From 44601df8829b7e1e12c78909fef14264d68fffd8 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 1 Nov 2007 12:18:25 +0000 Subject: [PATCH] Select: null selections without nullselectionItemId svn changeset:2655/svn branch:trunk --- .../terminal/gwt/client/ui/IFilterSelect.java | 20 +++++++----- src/com/itmill/toolkit/ui/Select.java | 31 ++++++++++++++++--- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java index d2cf5995e3..de78951986 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java @@ -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)) { diff --git a/src/com/itmill/toolkit/ui/Select.java b/src/com/itmill/toolkit/ui/Select.java index e480e26474..567aa16068 100644 --- a/src/com/itmill/toolkit/ui/Select.java +++ b/src/com/itmill/toolkit/ui/Select.java @@ -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 -- 2.39.5