]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed one ("filtering") regression.
authorMarc Englund <marc.englund@itmill.com>
Mon, 3 Mar 2008 09:20:01 +0000 (09:20 +0000)
committerMarc Englund <marc.englund@itmill.com>
Mon, 3 Mar 2008 09:20:01 +0000 (09:20 +0000)
Implemeted "emptyText" functionality (weekend coding), but the code is disabled (commented out) serverside - #1455 will enable it.

svn changeset:3956/svn branch:trunk

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

index c36249537084ebd6a045f515b6d2ca1eec1e7394..9bcd66c3d27d5d7e35f459378161bd616f46252c 100644 (file)
@@ -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
+        }
     }
 }
index 0125af1d0fc3beac1c5c533ef4fc97630a5162d1..915ad94827b3f088c10067d997031f92ecddf04f 100644 (file)
@@ -17,6 +17,9 @@ import com.itmill.toolkit.data.Container;
  * \r
  */\r
 public class ComboBox extends Select {\r
+\r
+    private String emptyText = null;\r
+\r
     public ComboBox() {\r
         setMultiSelect(false);\r
         setNewItemsAllowed(false);\r
@@ -47,4 +50,21 @@ public class ComboBox extends Select {
         super.setMultiSelect(multiSelect);\r
     }\r
 \r
+    /*- TODO enable and test this - client impl exists\r
+    public String getEmptyText() {\r
+        return emptyText;\r
+    }\r
+\r
+    public void setEmptyText(String emptyText) {\r
+        this.emptyText = emptyText;\r
+    }\r
+\r
+    public void paintContent(PaintTarget target) throws PaintException {\r
+        if (emptyText != null) {\r
+            target.addAttribute("emptytext", emptyText);\r
+        }\r
+        super.paintContent(target);\r
+    }\r
+    -*/\r
+\r
 }\r