]> source.dussan.org Git - vaadin-framework.git/commitdiff
Select: null selections without nullselectionItemId
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 1 Nov 2007 12:18:25 +0000 (12:18 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 1 Nov 2007 12:18:25 +0000 (12:18 +0000)
svn changeset:2655/svn branch:trunk

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

index d2cf5995e30dd307e8fba3364f44ce4e6c7dfe22..de78951986fbc48d0995bfe56c34e5d30ae40cc7 100644 (file)
@@ -125,7 +125,6 @@ public class IFilterSelect extends Composite implements Paintable,
                        setPrevButtonActive(first > 1);
                        setNextButtonActive(last < totalSuggestions);
                        setPopupPositionAndShow(this);
-
                }
 
                private void setNextButtonActive(boolean b) {
@@ -274,7 +273,7 @@ public class IFilterSelect extends Composite implements Paintable,
 
        private static final String CLASSNAME = "i-filterselect";
 
-       public static final int PAGELENTH = 15;
+       public static final int PAGELENTH = 10;
 
        private final FlowPanel panel = new FlowPanel();
 
@@ -311,6 +310,7 @@ public class IFilterSelect extends Composite implements Paintable,
        private ArrayList allSuggestions;
        private int totalMatches;
        private boolean allowNewItem;
+       private boolean nullSelectionAllowed;
 
        public IFilterSelect() {
                selectedItemIcon.setVisible(false);
@@ -376,10 +376,9 @@ public class IFilterSelect extends Composite implements Paintable,
                if (client.updateComponent(this, uidl, true))
                        return;
 
-               if (uidl.hasAttribute("immediate"))
-                       immediate = true;
-               else
-                       immediate = false;
+               immediate = uidl.hasAttribute("immediate");
+               
+               nullSelectionAllowed = uidl.hasAttribute("nullselect");
 
                if (true) {
                        this.suggestionPopup.setPagingEnabled(true);
@@ -447,7 +446,14 @@ public class IFilterSelect extends Composite implements Paintable,
 
        public void onSuggestionSelected(FilterSelectSuggestion suggestion) {
                currentSuggestion = suggestion;
-               String newKey = String.valueOf(suggestion.getOptionKey());
+               String newKey;
+               if(suggestion.key.equals("")) {
+                       // "nullselection"
+                       newKey = "";
+               } else {
+                       // normal selection
+                       newKey = String.valueOf(suggestion.getOptionKey());
+               }
                tb.setText(suggestion.getReplacementString());
                setSelectedItemIcon(suggestion.getIconUri());
                if (!newKey.equals(selectedOptionKey)) {
index e480e26474d37e121be00bfd8af3c30922ebe3b3..567aa160682220f7c6a2230408c897149d866ed6 100644 (file)
@@ -65,7 +65,7 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
        /**
         * Holds value of property pageLength. 0 disables paging.
         */
-       protected int pageLength = 15;
+       protected int pageLength = 10;
 
        // current page when the user is 'paging' trough options
        private int currentPage;
@@ -132,8 +132,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
                if (isNewItemsAllowed()) {
                        target.addAttribute("allownewitem", true);
                }
+
+               boolean needNullSelectOption = false;
                if (isNullSelectionAllowed()) {
                        target.addAttribute("nullselect", true);
+                       needNullSelectOption = getNullSelectionItemId() == null;
                }
 
                // Constructs selected keys array
@@ -173,10 +176,29 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
                 * target.addAttribute("totalMatches", this.optionFilter
                 * .getMatchCount()); } else { i = getItemIds().iterator(); }
                 */
+               target.startTag("options");
+
+               boolean paintNullSelection = needNullSelectOption
+                               && (currentPage == 0 && (filterstring == null
+                                               || filterstring.equals("") || filterstring.equals("-")));
+
+               if (paintNullSelection) {
+                       target.startTag("so");
+                       target.addAttribute("caption", "-");
+                       target.addAttribute("key", "");
+                       target.endTag("so");
+               }
+
                List options = getFilteredOptions();
                if (options.size() > this.pageLength) {
                        int first = this.currentPage * this.pageLength;
                        int last = first + this.pageLength;
+                       if(needNullSelectOption) {
+                               if(currentPage > 0) {
+                                       first--;
+                               }
+                               last--;
+                       }
                        if (options.size() < last) {
                                last = options.size();
                        }
@@ -185,7 +207,6 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
                Iterator i = options.iterator();
                // Paints the available selection options from data source
 
-               target.startTag("options");
                while (i.hasNext()) {
 
                        // Gets the option attribute values
@@ -212,9 +233,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
                }
                target.endTag("options");
 
-               target.addAttribute("totalitems", size());
+               target.addAttribute("totalitems", size()
+                               + (needNullSelectOption ? 1 : 0));
                if (this.filteredOptions != null) {
-                       target.addAttribute("totalMatches", this.filteredOptions.size());
+                       target.addAttribute("totalMatches", this.filteredOptions.size()
+                                       + (needNullSelectOption ? 1 : 0));
                }
 
                // Paint variables