]> source.dussan.org Git - vaadin-framework.git/commitdiff
setColumns() and setRows() added to selects as appropriate, made to match width of...
authorMarc Englund <marc.englund@itmill.com>
Fri, 23 Nov 2007 07:45:03 +0000 (07:45 +0000)
committerMarc Englund <marc.englund@itmill.com>
Fri, 23 Nov 2007 07:45:03 +0000 (07:45 +0000)
Fixes #898

svn changeset:2893/svn branch:trunk

13 files changed:
src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java
src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IOptionGroupBase.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITwinColSelect.java
src/com/itmill/toolkit/terminal/gwt/public/default/button/button.css
src/com/itmill/toolkit/terminal/gwt/public/default/select/select.css
src/com/itmill/toolkit/terminal/gwt/public/default/textfield/textfield.css
src/com/itmill/toolkit/ui/ComboBox.java [new file with mode: 0644]
src/com/itmill/toolkit/ui/ListSelect.java
src/com/itmill/toolkit/ui/NativeSelect.java
src/com/itmill/toolkit/ui/Select.java
src/com/itmill/toolkit/ui/TwinColSelect.java

index 3b65a6aa9ea7ad8851e64f1ae78e7fbe13a9b441..43dfb3fa21f7d8348072e3e06a7abeaa798e8e26 100644 (file)
@@ -43,6 +43,9 @@ public class IListSelect extends IOptionGroupBase {
                 select.setItemSelected(select.getItemCount() - 1, true);
             }
         }
+        if (getRows() > 0) {
+            select.setVisibleItemCount(getRows());
+        }
     }
 
     protected Object[] getSelectedItems() {
index efd18d13cc24ffa3235966e30b7f566b55b2ad0d..95c954a4c0fda27ac88b772616d15d3fcedc7525 100644 (file)
@@ -58,4 +58,5 @@ public class INativeSelect extends IOptionGroupBase {
                     + getSelectedItem() }, isImmediate());
         }
     }
+
 }
index 5a1d624eefab37ad2d1dc4909857c5fe7affdedb..baedab7f1ae986acd10676bea910be7acaac2e0c 100644 (file)
@@ -32,6 +32,10 @@ abstract class IOptionGroupBase extends Composite implements Paintable,
 \r
     private boolean readonly;\r
 \r
+    private int cols = 0;\r
+\r
+    private int rows = 0;\r
+\r
     private boolean nullSelectionAllowed = true;\r
 \r
     private boolean nullSelectionItemAvailable = false;\r
@@ -94,6 +98,21 @@ abstract class IOptionGroupBase extends Composite implements Paintable,
         return nullSelectionItemAvailable;\r
     }\r
 \r
+    /**\r
+     * @return "cols" specified in uidl, 0 if not specified\r
+     */\r
+    protected int getColumns() {\r
+        return cols;\r
+    }\r
+\r
+    /**\r
+     * @return "rows" specified in uidl, 0 if not specified\r
+     */\r
+\r
+    protected int getRows() {\r
+        return rows;\r
+    }\r
+\r
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
         this.client = client;\r
         id = uidl.getId();\r
@@ -111,27 +130,40 @@ abstract class IOptionGroupBase extends Composite implements Paintable,
         nullSelectionAllowed = uidl.getBooleanAttribute("nullselect");\r
         nullSelectionItemAvailable = uidl.getBooleanAttribute("nullselectitem");\r
 \r
+        cols = uidl.getIntAttribute("cols");\r
+        rows = uidl.getIntAttribute("rows");\r
+\r
         UIDL ops = uidl.getChildUIDL(0);\r
 \r
+        if (getColumns() > 0) {\r
+            container.setWidth(getColumns() + "em");\r
+            if (container != optionsContainer) {\r
+                optionsContainer.setWidth("100%");\r
+            }\r
+        }\r
+\r
         buildOptions(ops);\r
 \r
         if (uidl.getBooleanAttribute("allownewitem")) {\r
             if (newItemField == null) {\r
                 newItemButton = new IButton();\r
                 newItemButton.setText("+");\r
+                newItemButton.setWidth("1.5em");\r
                 newItemButton.addClickListener(this);\r
                 newItemField = new ITextField();\r
                 newItemField.addKeyboardListener(this);\r
-                newItemField.setColumns(16);\r
+                // newItemField.setColumns(16);\r
+                if (getColumns() > 0) {\r
+                    newItemField.setWidth((getColumns() - 2) + "em");\r
+                }\r
             }\r
             newItemField.setEnabled(!disabled && !readonly);\r
             newItemButton.setEnabled(!disabled && !readonly);\r
 \r
-            if (newItemField != null && newItemField.getParent() == container) {\r
-                return;\r
+            if (newItemField == null || newItemField.getParent() != container) {\r
+                container.add(newItemField);\r
+                container.add(newItemButton);\r
             }\r
-            container.add(newItemField);\r
-            container.add(newItemButton);\r
         } else if (newItemField != null) {\r
             container.remove(newItemField);\r
             container.remove(newItemButton);\r
index 7b1ed75f27cec25165501877f802e41c7197f86b..6b77aefebdc45856b8eeabf1554cf1dea15ac814 100644 (file)
@@ -87,23 +87,25 @@ public class ITextField extends TextBoxBase implements Paintable,
     }
 
     private native void setColumns(Element e, int c) /*-{
-                   try {
-                       switch(e.tagName.toLowerCase()) {
-                               case "input":
-                                       e.size = c;
-                                       break;
-                               case "textarea":
-                                       e.cols = c;
-                                       break;
-                               default:;
-                       }
-                   } catch (e) {}
-                   }-*/;
+                      try {
+                       switch(e.tagName.toLowerCase()) {
+                               case "input":
+                                       //e.size = c;
+                                       e.style.width = c+"em";
+                                       break;
+                               case "textarea":
+                                       //e.cols = c;
+                                       e.style.width = c+"em";
+                                       break;
+                               default:;
+                       }
+                      } catch (e) {}
+                      }-*/;
 
     private native void setRows(Element e, int r) /*-{
-                   try {
-                       if(e.tagName.toLowerCase() == "textarea")
-                               e.rows = r;
-                   } catch (e) {}
-                   }-*/;
+                      try {
+                       if(e.tagName.toLowerCase() == "textarea")
+                               e.rows = r;
+                      } catch (e) {}
+                      }-*/;
 }
index 5ed9cea2e927098f2f34ccfcecf2ec44de8f48fb..614120db51b9ca5a6bb560aec8dcc0c0a5664e9c 100644 (file)
@@ -27,7 +27,9 @@ public class ITwinColSelect extends IOptionGroupBase {
     public ITwinColSelect() {\r
         super(CLASSNAME);\r
         options = new ListBox();\r
+        options.addClickListener(this);\r
         selections = new ListBox();\r
+        selections.addClickListener(this);\r
         options.setVisibleItemCount(VISIBLE_COUNT);\r
         selections.setVisibleItemCount(VISIBLE_COUNT);\r
         options.setStyleName(CLASSNAME + "-options");\r
@@ -35,15 +37,15 @@ public class ITwinColSelect extends IOptionGroupBase {
         Panel buttons = new FlowPanel();\r
         buttons.setStyleName(CLASSNAME + "-buttons");\r
         add = new IButton();\r
-        remove = new IButton();\r
         add.setText(">>");\r
-        remove.setText("<<");\r
         add.addClickListener(this);\r
+        remove = new IButton();\r
+        remove.setText("<<");\r
         remove.addClickListener(this);\r
         Panel p = ((Panel) optionsContainer);\r
         p.add(options);\r
         buttons.add(add);\r
-        HTML br = new HTML("&nbsp;");\r
+        HTML br = new HTML("<span/>");\r
         br.setStyleName(CLASSNAME + "-deco");\r
         buttons.add(br);\r
         buttons.add(remove);\r
@@ -71,6 +73,15 @@ public class ITwinColSelect extends IOptionGroupBase {
                         optionUidl.getStringAttribute("key"));\r
             }\r
         }\r
+        optionsContainer.setWidth(null);\r
+        if (getColumns() > 0) {\r
+            options.setWidth(getColumns() + "em");\r
+            selections.setWidth(getColumns() + "em");\r
+        }\r
+        if (getRows() > 0) {\r
+            options.setVisibleItemCount(getRows());\r
+            selections.setVisibleItemCount(getRows());\r
+        }\r
     }\r
 \r
     protected Object[] getSelectedItems() {\r
@@ -118,6 +129,8 @@ public class ITwinColSelect extends IOptionGroupBase {
                     String text = options.getItemText(optionIndex);\r
                     String value = options.getValue(optionIndex);\r
                     selections.addItem(text, value);\r
+                    selections.setItemSelected(selections.getItemCount() - 1,\r
+                            true);\r
                     options.removeItem(optionIndex);\r
                 }\r
             }\r
@@ -136,11 +149,24 @@ public class ITwinColSelect extends IOptionGroupBase {
                     String text = selections.getItemText(selectionIndex);\r
                     String value = selections.getValue(selectionIndex);\r
                     options.addItem(text, value);\r
+                    options.setItemSelected(options.getItemCount() - 1, true);\r
                     selections.removeItem(selectionIndex);\r
                 }\r
             }\r
             client.updateVariable(id, "selected", selectedKeys.toArray(),\r
                     isImmediate());\r
+        } else if (sender == options) {\r
+            // unselect all in other list, to avoid mistakes (i.e wrong button)\r
+            int c = selections.getItemCount();\r
+            for (int i = 0; i < c; i++) {\r
+                selections.setItemSelected(i, false);\r
+            }\r
+        } else if (sender == selections) {\r
+            // unselect all in other list, to avoid mistakes (i.e wrong button)\r
+            int c = options.getItemCount();\r
+            for (int i = 0; i < c; i++) {\r
+                options.setItemSelected(i, false);\r
+            }\r
         }\r
     }\r
 \r
index bb3ad4773f788eb3ff4a81f2fff70d74c19ecba0..2e5f3c8b4ee4b1c9e0749dee7ac45bc1b9671c70 100644 (file)
@@ -1,5 +1,6 @@
 .i-button {\r
        cursor: pointer;\r
+       font-size: 13px;\r
 }\r
 .i-button.link {\r
        border: 0px;\r
index 9ea1c263fa93e8b5c97d259f7a708797205b185c..5998c55f8579c7f8b2f6437b09a9a41003c2f5b4 100644 (file)
@@ -1,7 +1,6 @@
 .i-select {\r
 \r
 }\r
-\r
 .i-select-option {\r
 \r
 }\r
        border-left-color: #d6d6d6;\r
        */\r
        display: block;\r
+       font-size: 13px;\r
 }\r
 \r
 /* Twincol style */\r
+.i-select-twincol {\r
+       white-space: nowrap;\r
+}\r
 .i-select-twincol-options {\r
        float: left;\r
+       font-size: 13px;\r
+}\r
+.i-select-twincol-selections {\r
+       font-size: 13px;\r
+       font-weight: bold;\r
 }\r
 \r
 .i-select-twincol-buttons {\r
        float: left;\r
-       width: 40px;\r
+       padding: 2px; /* does not work in first render in FF ? */\r
        text-align: center;\r
 }\r
 \r
 .i-select-twincol-buttons .i-select-twincol-deco {\r
-       display: inline; /* Needed to push the two buttons in stack */\r
+       clear:both;\r
 }\r
 \r
 .i-select-twincol .i-textfield {\r
index bf5d50219c56ae0264025cc9e37d324290cb7392..b8d4003e6533a7b220ec4e8b3c7be78fdb6f8818 100644 (file)
        border: none;\r
 }\r
 \r
+/* TODO impl all textarea styles */\r
+.i-textarea {\r
+       background: #fff url(img/bg.png) repeat-x;\r
+       padding: 2px;\r
+       border: 1px solid #b6b6b6;\r
+       border-top-color: #9d9d9d;\r
+       border-bottom-color: #d6d6d6;\r
+       border-right-color: #d6d6d6;\r
+       margin: 0;\r
+       font-size: 13px;\r
+}\r
+\r
+\r
 .i-richtextarea {\r
        border: 1px solid #b6b6b6;\r
        overflow: hidden;\r
diff --git a/src/com/itmill/toolkit/ui/ComboBox.java b/src/com/itmill/toolkit/ui/ComboBox.java
new file mode 100644 (file)
index 0000000..55f2c31
--- /dev/null
@@ -0,0 +1,48 @@
+/**\r
+ * \r
+ */\r
+package com.itmill.toolkit.ui;\r
+\r
+import java.util.Collection;\r
+\r
+import com.itmill.toolkit.data.Container;\r
+\r
+/**\r
+ * A filtering dropdown single-select with newItemsAllowed. Items are filtered\r
+ * based on user input, and loaded dynamically ("lazy-loading") from the server.\r
+ * You can turn off newItemsAllowed and change filtering mode (and also turn it\r
+ * off), but you can not turn on multi-select mode.\r
+ * \r
+ */\r
+public class ComboBox extends Select {\r
+    public ComboBox() {\r
+        setMultiSelect(false);\r
+        setNewItemsAllowed(true);\r
+    }\r
+\r
+    public ComboBox(String caption, Collection options) {\r
+        super(caption, options);\r
+        setMultiSelect(false);\r
+        setNewItemsAllowed(true);\r
+    }\r
+\r
+    public ComboBox(String caption, Container dataSource) {\r
+        super(caption, dataSource);\r
+        setMultiSelect(false);\r
+        setNewItemsAllowed(true);\r
+    }\r
+\r
+    public ComboBox(String caption) {\r
+        super(caption);\r
+        setMultiSelect(false);\r
+        setNewItemsAllowed(true);\r
+    }\r
+\r
+    public void setMultiSelect(boolean multiSelect) {\r
+        if (multiSelect && !isMultiSelect()) {\r
+            throw new UnsupportedOperationException("Multiselect not supported");\r
+        }\r
+        super.setMultiSelect(multiSelect);\r
+    }\r
+\r
+}\r
index 25f6f011108bc2f7e988ae87bc6c10c2cf1e6d9e..235524a64954597c6d282d83c729c906ad752317 100644 (file)
@@ -12,6 +12,9 @@ import com.itmill.toolkit.terminal.PaintTarget;
  */
 public class ListSelect extends AbstractSelect {
 
+    private int columns = 0;
+    private int rows = 0;
+
     public ListSelect() {
         super();
     }
@@ -28,8 +31,60 @@ public class ListSelect extends AbstractSelect {
         super(caption);
     }
 
+    /**
+     * Sets the number of columns in the editor. If the number of columns is set
+     * 0, the actual number of displayed columns is determined implicitly by the
+     * adapter.
+     * 
+     * @param columns
+     *                the number of columns to set.
+     */
+    public void setColumns(int columns) {
+        if (columns < 0) {
+            columns = 0;
+        }
+        if (this.columns != columns) {
+            this.columns = columns;
+            requestRepaint();
+        }
+    }
+
+    public int getColumns() {
+        return columns;
+    }
+
+    public int getRows() {
+        return rows;
+    }
+
+    /**
+     * Sets the number of rows in the editor. If the number of rows is set 0,
+     * the actual number of displayed rows is determined implicitly by the
+     * adapter.
+     * 
+     * @param rows
+     *                the number of rows to set.
+     */
+    public void setRows(int rows) {
+        if (rows < 0) {
+            rows = 0;
+        }
+        if (this.rows != rows) {
+            this.rows = rows;
+            requestRepaint();
+        }
+    }
+
     public void paintContent(PaintTarget target) throws PaintException {
         target.addAttribute("type", "list");
+        // Adds the number of columns
+        if (columns != 0) {
+            target.addAttribute("cols", columns);
+        }
+        // Adds the number of rows
+        if (rows != 0) {
+            target.addAttribute("rows", rows);
+        }
         super.paintContent(target);
     }
 }
index 353ca9c8d8e6355612df66c41769a7c1f8b4ccc4..9c5859095e6003e8259f0013cfeabedaa19c02d0 100644 (file)
@@ -14,6 +14,9 @@ import com.itmill.toolkit.terminal.PaintTarget;
  */
 public class NativeSelect extends AbstractSelect {
 
+    // width in characters, mimics TextField
+    private int columns = 0;
+
     public NativeSelect() {
         super();
     }
@@ -30,8 +33,35 @@ public class NativeSelect extends AbstractSelect {
         super(caption);
     }
 
+    /**
+     * Sets the number of columns in the editor. If the number of columns is set
+     * 0, the actual number of displayed columns is determined implicitly by the
+     * adapter.
+     * 
+     * @param columns
+     *                the number of columns to set.
+     */
+    public void setColumns(int columns) {
+        if (columns < 0) {
+            columns = 0;
+        }
+        if (this.columns != columns) {
+            this.columns = columns;
+            requestRepaint();
+        }
+    }
+
+    public int getColumns() {
+        return columns;
+    }
+
     public void paintContent(PaintTarget target) throws PaintException {
         target.addAttribute("type", "native");
+        // Adds the number of columns
+        if (columns != 0) {
+            target.addAttribute("cols", columns);
+        }
+
         super.paintContent(target);
     }
 
index 12f875709630660fbd1b368afb819fc32df50508..a5a199f8da11d44fdd95ef8d3a50526dde4291e5 100644 (file)
@@ -67,6 +67,8 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
      */
     protected int pageLength = 10;
 
+    private int columns = 0;
+
     // current page when the user is 'paging' trough options
     private int currentPage;
 
@@ -142,6 +144,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
             }
         }
 
+        // Adds the number of columns
+        if (columns != 0) {
+            target.addAttribute("cols", columns);
+        }
+
         // Constructs selected keys array
         String[] selectedKeys;
         if (isMultiSelect()) {
@@ -421,4 +428,27 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
     public int getFilteringMode() {
         return filteringMode;
     }
+
+    /**
+     * Sets the number of columns in the editor. If the number of columns is set
+     * 0, the actual number of displayed columns is determined implicitly by the
+     * adapter.
+     * 
+     * @param columns
+     *                the number of columns to set.
+     */
+    public void setColumns(int columns) {
+        if (columns < 0) {
+            columns = 0;
+        }
+        if (this.columns != columns) {
+            this.columns = columns;
+            requestRepaint();
+        }
+    }
+
+    public int getColumns() {
+        return columns;
+    }
+
 }
index aab5bf62c10ad0a4731b49a579c5955a88595c73..3a77d868f4277de3a82f6e54b60dcf636dbd1b7c 100644 (file)
@@ -15,6 +15,9 @@ import com.itmill.toolkit.terminal.PaintTarget;
  */
 public class TwinColSelect extends AbstractSelect {
 
+    private int columns = 0;
+    private int rows = 0;
+
     /**
      * 
      */
@@ -40,6 +43,50 @@ public class TwinColSelect extends AbstractSelect {
         setMultiSelect(true);
     }
 
+    /**
+     * Sets the number of columns in the editor. If the number of columns is set
+     * 0, the actual number of displayed columns is determined implicitly by the
+     * adapter.
+     * 
+     * @param columns
+     *                the number of columns to set.
+     */
+    public void setColumns(int columns) {
+        if (columns < 0) {
+            columns = 0;
+        }
+        if (this.columns != columns) {
+            this.columns = columns;
+            requestRepaint();
+        }
+    }
+
+    public int getColumns() {
+        return columns;
+    }
+
+    public int getRows() {
+        return rows;
+    }
+
+    /**
+     * Sets the number of rows in the editor. If the number of rows is set 0,
+     * the actual number of displayed rows is determined implicitly by the
+     * adapter.
+     * 
+     * @param rows
+     *                the number of rows to set.
+     */
+    public void setRows(int rows) {
+        if (rows < 0) {
+            rows = 0;
+        }
+        if (this.rows != rows) {
+            this.rows = rows;
+            requestRepaint();
+        }
+    }
+
     /**
      * @param caption
      * @param options
@@ -51,6 +98,14 @@ public class TwinColSelect extends AbstractSelect {
 
     public void paintContent(PaintTarget target) throws PaintException {
         target.addAttribute("type", "twincol");
+        // Adds the number of columns
+        if (columns != 0) {
+            target.addAttribute("cols", columns);
+        }
+        // Adds the number of rows
+        if (rows != 0) {
+            target.addAttribute("rows", rows);
+        }
         super.paintContent(target);
     }