Lior Vernia has uploaded a new change for review.

Change subject: webadmin: TypeAheadListBox to display default text
......................................................................

webadmin: TypeAheadListBox to display default text

Adjusted the widget to display default grayed-out text when it has no
content.

Change-Id: I18d43efadde607867be440af73a9d67a14c293e0
Bug-Url: https://bugzilla.redhat.com/1086259
Signed-off-by: Lior Vernia <lver...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java
2 files changed, 18 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/79/31879/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
index 0231137..b2f90e4 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
@@ -7,6 +7,9 @@
     @DefaultStringValue("")
     String empty();
 
+    @DefaultStringValue("Please select an item...")
+    String emptyListBoxText();
+
     @DefaultStringValue("http://www.ovirt.org";)
     String vendorUrl();
 
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java
index 0ca6db9..9a00d66 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java
@@ -4,7 +4,9 @@
 import java.util.Collection;
 import java.util.List;
 
+import org.ovirt.engine.ui.common.CommonApplicationConstants;
 import 
org.ovirt.engine.ui.common.widget.editor.ListModelTypeAheadListBoxEditor.SuggestBoxRenderer;
+import org.ovirt.engine.ui.uicompat.external.StringUtils;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.Scheduler;
@@ -58,6 +60,7 @@
     @UiField
     Style style;
 
+    private static final CommonApplicationConstants constants = 
GWT.create(CommonApplicationConstants.class);
     private final SuggestBoxRenderer<T> renderer;
 
     /**
@@ -236,23 +239,15 @@
             return;
         }
 
-        // empty suggest box
         String providedText = asSuggestBox().getText();
-        if (providedText == null || "".equals(providedText)) {
-            if (getValue() != null) {
-                // something has been there, deleted on click inside and than 
hidden the box - restoring
-                
asSuggestBox().setText(renderer.getReplacementString(getValue()));
-            }
-        } else {
-            // something has been typed inside - validate
-            try {
-                T newData = asEntity(providedText);
-                // correct provided - use it
-                setValue(newData);
-            } catch (IllegalArgumentException e) {
-                // incorrect - return to previous one
-                
asSuggestBox().setText(renderer.getReplacementString(getValue()));
-            }
+        // validate input text
+        try {
+            T newData = asEntity(providedText);
+            // correct provided - use it
+            setValue(newData);
+        } catch (IllegalArgumentException e) {
+            // incorrect - return to previous one
+            render(getValue(), false);
         }
     }
 
@@ -319,7 +314,10 @@
 
     @Override
     protected void render(T value, boolean fireEvents) {
-        asSuggestBox().setValue(renderer.getReplacementString(value), 
fireEvents);
+        String replacementString = renderer.getReplacementString(value);
+        boolean empty = StringUtils.isEmpty(replacementString);
+        asSuggestBox().setValue(empty ? constants.emptyListBoxText() : 
replacementString, fireEvents);
+        asSuggestBox().getElement().getStyle().setColor(empty ? "gray" : 
"black"); //$NON-NLS-1$ $NON-NLS-2$
     }
 
     @Override


-- 
To view, visit http://gerrit.ovirt.org/31879
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I18d43efadde607867be440af73a9d67a14c293e0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Lior Vernia <lver...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to