Lior Vernia has uploaded a new change for review.

Change subject: webadmin: ListModelTypeAheadListBox to not always add to valid 
values
......................................................................

webadmin: ListModelTypeAheadListBox to not always add to valid values

Added a parameter that determines whether the widget should
automatically add values to the list of "valid" values (those
suggested). This is particularly useful when the selected value is
initialized to some value, that shouldn't be chosen again once it's
been changed (which is the case for the vNIC widget).

Change-Id: Ic35073123696fe7e727464079c31794935a7ad70
Bug-Url: https://bugzilla.redhat.com/1020861
Signed-off-by: Lior Vernia <lver...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBoxEditor.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileEditor.java
3 files changed, 26 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/53/26753/1

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 77efcd2..0e0311b 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
@@ -57,6 +57,13 @@
 
     private final SuggestBoxRenderer<T> renderer;
 
+    /**
+     * This is used to decide whether, when setting the value of the widget to 
one that doesn't exist among the list of
+     * suggested items {@link #acceptableValues}, the new value should be 
added to it; see usage in
+     * {@link #addToValidValuesIfNeeded(Object)}.
+     */
+    private final boolean autoAddToValidValues;
+
     private Collection<T> acceptableValues = new ArrayList<T>();
 
     private HandlerRegistration eventHandler;
@@ -73,8 +80,13 @@
     }
 
     public ListModelTypeAheadListBox(SuggestBoxRenderer<T> renderer) {
+        this(renderer, true);
+    }
+
+    public ListModelTypeAheadListBox(SuggestBoxRenderer<T> renderer, boolean 
autoAddToValidValues) {
         super(new RenderableSuggestOracle<T>(renderer));
         this.renderer = renderer;
+        this.autoAddToValidValues = autoAddToValidValues;
 
         suggestBox = asSuggestBox();
 
@@ -266,7 +278,7 @@
     }
 
     private void addToValidValuesIfNeeded(T value) {
-        if (!acceptableValues.contains(value)) {
+        if (!acceptableValues.contains(value) && autoAddToValidValues) {
             acceptableValues.add(value);
         }
 
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBoxEditor.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBoxEditor.java
index 2254a8a..fac9943 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBoxEditor.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBoxEditor.java
@@ -18,11 +18,21 @@
     private final WidgetWithLabelEditor<T, ListModelTypeAheadListBoxEditor<T>> 
editor;
 
     public ListModelTypeAheadListBoxEditor(SuggestBoxRenderer<T> renderer) {
-        this(renderer, new VisibilityRenderer.SimpleVisibilityRenderer());
+        this(renderer, true);
+    }
+
+    public ListModelTypeAheadListBoxEditor(SuggestBoxRenderer<T> renderer, 
boolean autoAddToValidValues) {
+        this(renderer, autoAddToValidValues, new 
VisibilityRenderer.SimpleVisibilityRenderer());
     }
 
     public ListModelTypeAheadListBoxEditor(SuggestBoxRenderer<T> renderer, 
VisibilityRenderer visibilityRenderer) {
-        super(new ListModelTypeAheadListBox<T>(renderer), visibilityRenderer);
+        this(renderer, true, visibilityRenderer);
+    }
+
+    public ListModelTypeAheadListBoxEditor(SuggestBoxRenderer<T> renderer,
+            boolean autoAddToValidValues,
+            VisibilityRenderer visibilityRenderer) {
+        super(new ListModelTypeAheadListBox<T>(renderer, 
autoAddToValidValues), visibilityRenderer);
         this.editor = WidgetWithLabelEditor.of(getContentWidget().asEditor(), 
this);
     }
 
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileEditor.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileEditor.java
index cc61ad6..3f4f1df 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileEditor.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileEditor.java
@@ -40,7 +40,7 @@
                                 profileDescription != null ? 
profileDescription : "").asString(); //$NON-NLS-1$
                     }
 
-                });
+                }, false);
     }
 
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic35073123696fe7e727464079c31794935a7ad70
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
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