From d545e9a267a7e82f498396357759973f6a1f47fd Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Mon, 3 Mar 2008 09:20:01 +0000 Subject: [PATCH] Fixed one ("filtering") regression. Implemeted "emptyText" functionality (weekend coding), but the code is disabled (commented out) serverside - #1455 will enable it. svn changeset:3956/svn branch:trunk --- .../terminal/gwt/client/ui/IFilterSelect.java | 51 ++++++++++++++----- src/com/itmill/toolkit/ui/ComboBox.java | 20 ++++++++ 2 files changed, 57 insertions(+), 14 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 c362495370..9bcd66c3d2 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java @@ -390,7 +390,7 @@ public class IFilterSelect extends Composite implements Paintable, } if (allowNewItem) { - if (!enteredItemValue.equals("")) { + if (!enteredItemValue.equals(emptyText)) { client.updateVariable(paintableId, "newitem", enteredItemValue, immediate); } @@ -400,10 +400,13 @@ public class IFilterSelect extends Composite implements Paintable, doItemAction(item, true); } else { if (currentSuggestion != null) { - tb.setText(currentSuggestion.getReplacementString()); + String text = currentSuggestion.getReplacementString(); + tb.setText((text.equals("") ? emptyText : text)); + // TODO add/remove class CLASSNAME_EMPTY selectedOptionKey = currentSuggestion.key; } else { - tb.setText(""); + tb.setText(emptyText); + // TODO add class CLASSNAME_EMPTY selectedOptionKey = null; } } @@ -455,6 +458,11 @@ public class IFilterSelect extends Composite implements Paintable, private boolean nullSelectionAllowed; private boolean enabled; + // shown in unfocused empty field, disappears on focus (e.g "Search here") + private String emptyText = ""; + private static final String CLASSNAME_EMPTY = "empty"; + private static final String ATTR_EMPTYTEXT = "emptytext"; + public IFilterSelect() { selectedItemIcon.setVisible(false); panel.add(selectedItemIcon); @@ -536,6 +544,11 @@ public class IFilterSelect extends Composite implements Paintable, nullSelectionAllowed = uidl.hasAttribute("nullselect"); + if (uidl.hasAttribute(ATTR_EMPTYTEXT)) { + // "emptytext" changed from server + emptyText = uidl.getStringAttribute(ATTR_EMPTYTEXT); + } + if (true) { suggestionPopup.setPagingEnabled(true); clientSideFiltering = false; @@ -550,17 +563,11 @@ public class IFilterSelect extends Composite implements Paintable, final UIDL options = uidl.getChildUIDL(0); totalMatches = uidl.getIntAttribute("totalMatches"); - String captions = ""; + String captions = emptyText; if (clientSideFiltering) { allSuggestions = new ArrayList(); } - if (uidl.hasVariable("selected") - && uidl.getStringArrayVariable("selected").length == 0) { - // select nulled - tb.setText(""); - } - for (final Iterator i = options.getChildIterator(); i.hasNext();) { final UIDL optionUidl = (UIDL) i.next(); final FilterSelectSuggestion suggestion = new FilterSelectSuggestion( @@ -581,6 +588,13 @@ public class IFilterSelect extends Composite implements Paintable, captions += suggestion.getReplacementString(); } + if (!filtering && uidl.hasVariable("selected") + && uidl.getStringArrayVariable("selected").length == 0) { + // select nulled + tb.setText(emptyText); + // TODO add class CLASSNAME_EMPTY + } + if (filtering && lastFilter.toLowerCase().equals( uidl.getStringVariable("filter"))) { @@ -616,7 +630,9 @@ public class IFilterSelect extends Composite implements Paintable, // normal selection newKey = String.valueOf(suggestion.getOptionKey()); } - tb.setText(suggestion.getReplacementString()); + String text = suggestion.getReplacementString(); + tb.setText(text.equals("") ? emptyText : text); + // TODO add/remove class CLASSNAME_EMPTY setSelectedItemIcon(suggestion.getIconUri()); if (!newKey.equals(selectedOptionKey)) { selectedOptionKey = newKey; @@ -660,6 +676,7 @@ public class IFilterSelect extends Composite implements Paintable, case KeyboardListener.KEY_ENTER: case KeyboardListener.KEY_TAB: suggestionPopup.menu.doSelectedItemAction(); + tb.setFocus(false); break; } } @@ -707,8 +724,8 @@ public class IFilterSelect extends Composite implements Paintable, filterOptions(0, ""); } DOM.eventPreventDefault(DOM.eventGetCurrentEvent()); - tb.selectAll(); tb.setFocus(true); + tb.selectAll(); } } @@ -739,13 +756,19 @@ public class IFilterSelect extends Composite implements Paintable, }-*/; public void onFocus(Widget sender) { - // NOP + if (emptyText.equals(tb.getText())) { + tb.setText(""); + // TODO remove class CLASSNAME_EMPTY + } } public void onLostFocus(Widget sender) { if (suggestionPopup.isJustClosed()) { suggestionPopup.menu.doSelectedItemAction(); } - + if ("".equals(tb.getText())) { + tb.setText(emptyText); + // TODO add CLASSNAME_EMPTY + } } } diff --git a/src/com/itmill/toolkit/ui/ComboBox.java b/src/com/itmill/toolkit/ui/ComboBox.java index 0125af1d0f..915ad94827 100644 --- a/src/com/itmill/toolkit/ui/ComboBox.java +++ b/src/com/itmill/toolkit/ui/ComboBox.java @@ -17,6 +17,9 @@ import com.itmill.toolkit.data.Container; * */ public class ComboBox extends Select { + + private String emptyText = null; + public ComboBox() { setMultiSelect(false); setNewItemsAllowed(false); @@ -47,4 +50,21 @@ public class ComboBox extends Select { super.setMultiSelect(multiSelect); } + /*- TODO enable and test this - client impl exists + public String getEmptyText() { + return emptyText; + } + + public void setEmptyText(String emptyText) { + this.emptyText = emptyText; + } + + public void paintContent(PaintTarget target) throws PaintException { + if (emptyText != null) { + target.addAttribute("emptytext", emptyText); + } + super.paintContent(target); + } + -*/ + } -- 2.39.5