Преглед на файлове

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
tags/6.7.0.beta1
Marc Englund преди 16 години
родител
ревизия
d545e9a267
променени са 2 файла, в които са добавени 57 реда и са изтрити 14 реда
  1. 37
    14
      src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java
  2. 20
    0
      src/com/itmill/toolkit/ui/ComboBox.java

+ 37
- 14
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
}
}
}

+ 20
- 0
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);
}
-*/
}

Loading…
Отказ
Запис