]> source.dussan.org Git - vaadin-framework.git/commitdiff
combobox select: adding new items
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 31 Oct 2007 14:54:32 +0000 (14:54 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 31 Oct 2007 14:54:32 +0000 (14:54 +0000)
svn changeset:2639/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java
src/com/itmill/toolkit/ui/AbstractSelect.java
src/com/itmill/toolkit/ui/CustomLayout.java

index a0dae7b31f79967a441ae0aa8a6f2d501d03ead1..d2cf5995e30dd307e8fba3364f44ce4e6c7dfe22 100644 (file)
@@ -143,8 +143,9 @@ public class IFilterSelect extends Composite implements Paintable,
                private void setPrevButtonActive(boolean b) {
                        if (b) {
                                DOM.sinkEvents(up, Event.ONCLICK);
-                               DOM.setElementProperty(up, "className", CLASSNAME
-                                               + "-prevpage");
+                               DOM
+                                               .setElementProperty(up, "className", CLASSNAME
+                                                               + "-prevpage");
                        } else {
                                DOM.sinkEvents(up, 0);
                                DOM.setElementProperty(up, "className", CLASSNAME
@@ -178,9 +179,11 @@ public class IFilterSelect extends Composite implements Paintable,
 
                public void onBrowserEvent(Event event) {
                        Element target = DOM.eventGetTarget(event);
-                       if (DOM.compare(target, up) || DOM.compare(target, DOM.getChild(up, 0))) {
+                       if (DOM.compare(target, up)
+                                       || DOM.compare(target, DOM.getChild(up, 0))) {
                                filterOptions(currentPage - 1, lastFilter);
-                       } else if (DOM.compare(target, down) || DOM.compare(target, DOM.getChild(down, 0))) {
+                       } else if (DOM.compare(target, down)
+                                       || DOM.compare(target, DOM.getChild(down, 0))) {
                                filterOptions(currentPage + 1, lastFilter);
                        }
                        tb.setFocus(true);
@@ -225,7 +228,8 @@ public class IFilterSelect extends Composite implements Paintable,
                                                                + "px");
                        }
                        if (offsetHeight + getPopupTop() > Window.getClientHeight()) {
-                               int top = Window.getClientHeight() - offsetHeight - EXTRASPACE/2;
+                               int top = Window.getClientHeight() - offsetHeight - EXTRASPACE
+                                               / 2;
                                setPopupPosition(getPopupLeft(), top);
                        }
                }
@@ -254,6 +258,11 @@ public class IFilterSelect extends Composite implements Paintable,
                        MenuItem item = this.getSelectedItem();
                        if (item != null) {
                                doItemAction(item, true);
+                       } else if (allowNewItem) {
+                               String newItemValue = tb.getText();
+                               if(!newItemValue.equals("")) {
+                                       client.updateVariable(paintableId, "newitem", newItemValue, true);
+                               }
                        }
                        suggestionPopup.hide();
                }
@@ -263,7 +272,6 @@ public class IFilterSelect extends Composite implements Paintable,
        public static final int FILTERINGMODE_STARTSWITH = 1;
        public static final int FILTERINGMODE_CONTAINS = 2;
 
-       
        private static final String CLASSNAME = "i-filterselect";
 
        public static final int PAGELENTH = 15;
@@ -302,6 +310,7 @@ public class IFilterSelect extends Composite implements Paintable,
 
        private ArrayList allSuggestions;
        private int totalMatches;
+       private boolean allowNewItem;
 
        public IFilterSelect() {
                selectedItemIcon.setVisible(false);
@@ -331,7 +340,7 @@ public class IFilterSelect extends Composite implements Paintable,
                if (filter.equals(lastFilter) && currentPage == page) {
                        if (!suggestionPopup.isAttached())
                                suggestionPopup.showSuggestions(currentSuggestions,
-                                               currentPage, totalSuggestions);
+                                               currentPage, totalMatches);
                        return;
                }
                if (!filter.equals(lastFilter)) {
@@ -380,11 +389,13 @@ public class IFilterSelect extends Composite implements Paintable,
                        clientSideFiltering = true;
                }
 
+               allowNewItem = uidl.hasAttribute("allownewitem");
+
                currentSuggestions.clear();
                UIDL options = uidl.getChildUIDL(0);
                totalSuggestions = uidl.getIntAttribute("totalitems");
                totalMatches = uidl.getIntAttribute("totalMatches");
-               
+
                String captions = "";
                if (clientSideFiltering) {
                        allSuggestions = new ArrayList();
@@ -410,7 +421,7 @@ public class IFilterSelect extends Composite implements Paintable,
 
                if (filtering && lastFilter.equals(uidl.getStringVariable("filter"))) {
                        suggestionPopup.showSuggestions(currentSuggestions, currentPage,
-                                       totalSuggestions);
+                                       totalMatches);
                        filtering = false;
                }
 
index 0d0fa88a4aab36742996898f52f27d7d5f56304b..156ebc4df61ee20eda53cba910bf2bdb4b7a9235 100644 (file)
@@ -278,8 +278,8 @@ public abstract class AbstractSelect extends AbstractField implements
                if (isNewItemsAllowed()) {
                        target.addAttribute("allownewitem", true);
                }
-               if (!isNullSelectionAllowed()) {
-                       target.addAttribute("nullselect", false);
+               if (isNullSelectionAllowed()) {
+                       target.addAttribute("nullselect", true);
                }
 
                // Constructs selected keys array
index d4c39fc08d469ac5f43b1c13d027e3bb3375d20b..79b5d89c5be025622c7fef660354a36d14dfe120 100644 (file)
@@ -177,16 +177,16 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
                target.addAttribute("template", templateName);
                // Adds all items in all the locations
                for (Iterator i = slots.keySet().iterator(); i.hasNext();) {
-
                        // Gets the (location,component)
                        String location = (String) i.next();
                        Component c = (Component) slots.get(location);
-
-                       // Writes the item
-                       target.startTag("location");
-                       target.addAttribute("name", location);
-                       c.paint(target);
-                       target.endTag("location");
+                       if (c != null) {
+                               // Writes the item
+                               target.startTag("location");
+                               target.addAttribute("name", location);
+                               c.paint(target);
+                               target.endTag("location");
+                       }
                }
        }
 
@@ -221,24 +221,24 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
         * CustomLayout's template selecting was previously implemented with
         * setStyle. Overriding to improve backwards compatibility.
         * 
-        * @param name template name
+        * @param name
+        *            template name
         */
        public void setStyle(String name) {
                setTemplateName(name);
        }
 
-       
        /** Get the name of the template */
        public String getTemplateName() {
                return templateName;
        }
 
-       /** Set the name of the template used to draw custom layout.
+       /**
+        * Set the name of the template used to draw custom layout.
         * 
-        * With GWT-adapter, the template with name 'templatename' is 
-        * loaded from ITMILL/themes/themename/layouts/templatename.html.
-        * If the theme has not been set (with Application.setTheme()), 
-        * themename is 'default'.
+        * With GWT-adapter, the template with name 'templatename' is loaded from
+        * ITMILL/themes/themename/layouts/templatename.html. If the theme has not
+        * been set (with Application.setTheme()), themename is 'default'.
         * 
         * @param templateName
         */