}
if (allowNewItem) {
- if (!enteredItemValue.equals("")) {
+ if (!enteredItemValue.equals(emptyText)) {
client.updateVariable(paintableId, "newitem",
enteredItemValue, immediate);
}
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;
}
}
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);
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;
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(
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"))) {
// 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;
case KeyboardListener.KEY_ENTER:
case KeyboardListener.KEY_TAB:
suggestionPopup.menu.doSelectedItemAction();
+ tb.setFocus(false);
break;
}
}
filterOptions(0, "");
}
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
- tb.selectAll();
tb.setFocus(true);
+ tb.selectAll();
}
}
}-*/;
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
+ }
}
}
* \r
*/\r
public class ComboBox extends Select {\r
+\r
+ private String emptyText = null;\r
+\r
public ComboBox() {\r
setMultiSelect(false);\r
setNewItemsAllowed(false);\r
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