Lior Vernia has uploaded a new change for review.

Change subject: webadmin: Changed bond name widget to ValueSuggestBox
......................................................................

webadmin: Changed bond name widget to ValueSuggestBox

When creating a new bond or editing an existing one, the widget for
picking a bond name is now a ValueSuggestBox rather than a
ValueListBox. This enables the user to input a new bond name, as well as
choose between suggested bond names that already exist on the host and
are free (as was customary historically).

Change-Id: I130586dc4787abecf81566a8d3b723d093f6fca2
Signed-off-by: Lior Vernia <[email protected]>
---
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.ui.xml
4 files changed, 147 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/31/12531/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java
new file mode 100644
index 0000000..37fa704
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBox.java
@@ -0,0 +1,97 @@
+package org.ovirt.engine.ui.common.widget.editor;
+
+import org.ovirt.engine.ui.common.utils.ObjectForStringFactory;
+import org.ovirt.engine.ui.common.widget.ValueSuggestBox;
+
+import com.google.gwt.editor.client.adapters.TakesValueEditor;
+import com.google.gwt.event.dom.client.KeyDownHandler;
+import com.google.gwt.event.dom.client.KeyPressHandler;
+import com.google.gwt.event.dom.client.KeyUpHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.text.shared.Renderer;
+import com.google.gwt.user.client.ui.SuggestBox;
+import com.google.gwt.user.client.ui.TextBoxBase;
+
+/**
+ * SuggestBox widget that adapts to UiCommon list model items.
+ *
+ * @param <T>
+ *            SuggestBox item type.
+ */
+public class ListModelSuggestBox<T> extends ValueSuggestBox<T> implements 
EditorWidget<T, TakesValueEditor<T>> {
+
+    private TakesConstrainedValueEditor<T> editor;
+
+    /**
+     * Creates a SuggestBox that renders its items using the specified {@link 
Renderer}.
+     *
+     * @param renderer
+     *            Renderer for SuggestBox items.
+     */
+    public ListModelSuggestBox(Renderer<T> renderer, ObjectForStringFactory<T> 
factory) {
+        super(renderer, factory, true);
+        setStyleName(null);
+    }
+
+    @Override
+    public TakesConstrainedValueEditor<T> asEditor() {
+        if (editor == null) {
+            editor = TakesConstrainedValueEditor.of(this, this, this);
+        }
+        return editor;
+    }
+
+    public SuggestBox asSuggestBox() {
+        return (SuggestBox) getWidget();
+    }
+
+    public TextBoxBase asTextBox() {
+        return asSuggestBox().getTextBox();
+    }
+
+    @Override
+    public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
+        return asSuggestBox().addKeyUpHandler(handler);
+    }
+
+    @Override
+    public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
+        return asSuggestBox().addKeyDownHandler(handler);
+    }
+
+    @Override
+    public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
+        return asSuggestBox().addKeyPressHandler(handler);
+    }
+
+    @Override
+    public int getTabIndex() {
+        return asSuggestBox().getTabIndex();
+    }
+
+    @Override
+    public void setAccessKey(char key) {
+        asSuggestBox().setAccessKey(key);
+    }
+
+    @Override
+    public void setFocus(boolean focused) {
+        asSuggestBox().setFocus(focused);
+    }
+
+    @Override
+    public void setTabIndex(int index) {
+        asSuggestBox().setTabIndex(index);
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return asTextBox().isEnabled();
+    }
+
+    @Override
+    public void setEnabled(boolean enabled) {
+        asTextBox().setEnabled(enabled);
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java
new file mode 100644
index 0000000..cb81d9c
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelSuggestBoxEditor.java
@@ -0,0 +1,30 @@
+package org.ovirt.engine.ui.common.widget.editor;
+
+import org.ovirt.engine.ui.common.utils.ObjectForStringFactory;
+import org.ovirt.engine.ui.common.widget.AbstractValidatedWidgetWithLabel;
+
+import com.google.gwt.editor.client.IsEditor;
+import com.google.gwt.text.shared.Renderer;
+
+/**
+ * Composite Editor that uses {@link ListModelSuggestBox}.
+ *
+ * @param <T>
+ *            SuggestBox item type.
+ */
+public class ListModelSuggestBoxEditor<T> extends 
AbstractValidatedWidgetWithLabel<T, ListModelSuggestBox<T>>
+        implements IsEditor<WidgetWithLabelEditor<T, 
ListModelSuggestBoxEditor<T>>> {
+
+    private final WidgetWithLabelEditor<T, ListModelSuggestBoxEditor<T>> 
editor;
+
+    public ListModelSuggestBoxEditor(Renderer<T> renderer, 
ObjectForStringFactory<T> factory) {
+        super(new ListModelSuggestBox<T>(renderer, factory));
+        this.editor = WidgetWithLabelEditor.of(getContentWidget().asEditor(), 
this);
+    }
+
+    @Override
+    public WidgetWithLabelEditor<T, ListModelSuggestBoxEditor<T>> asEditor() {
+        return editor;
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.java
index dfd2b4e..c84f4c5 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.java
@@ -1,9 +1,10 @@
 package org.ovirt.engine.ui.webadmin.section.main.view.popup.host;
 
+import org.ovirt.engine.core.common.businessentities.network.Bond;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import 
org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol;
-import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.core.compat.KeyValuePairCompat;
+import org.ovirt.engine.ui.common.utils.ObjectForStringFactory;
 import org.ovirt.engine.ui.common.view.popup.AbstractModelBoundPopupView;
 import org.ovirt.engine.ui.common.widget.Align;
 import org.ovirt.engine.ui.common.widget.dialog.SimpleDialogPanel;
@@ -11,6 +12,7 @@
 import org.ovirt.engine.ui.common.widget.editor.EntityModelLabelEditor;
 import org.ovirt.engine.ui.common.widget.editor.EntityModelTextBoxEditor;
 import org.ovirt.engine.ui.common.widget.editor.ListModelListBoxEditor;
+import org.ovirt.engine.ui.common.widget.editor.ListModelSuggestBoxEditor;
 import org.ovirt.engine.ui.common.widget.renderer.NullSafeRenderer;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
@@ -50,7 +52,7 @@
 
     @UiField(provided = true)
     @Path(value = "bond.selectedItem")
-    ListModelListBoxEditor<Object> bondEditor;
+    ListModelSuggestBoxEditor<Object> bondEditor;
 
     @UiField(provided = true)
     @Path(value = "network.selectedItem")
@@ -118,13 +120,22 @@
     public HostBondPopupView(EventBus eventBus, ApplicationResources 
resources, final ApplicationConstants constants) {
         super(eventBus, resources);
 
-        bondEditor = new ListModelListBoxEditor<Object>(new 
NullSafeRenderer<Object>() {
-            @Override
-            protected String renderNullSafe(Object object) {
-                return ((VdsNetworkInterface) object).getName();
-            }
+        bondEditor = new ListModelSuggestBoxEditor<Object>(
+                new NullSafeRenderer<Object>() {
+                    @Override
+                    protected String renderNullSafe(Object bond) {
+                        return ((Bond) bond).getName();
+                    }
 
-        });
+                },
+                new ObjectForStringFactory<Object>() {
+                    @Override
+                    public Bond getObjectForString(String bondName) {
+                        Bond bond = new Bond();
+                        bond.setName(bondName);
+                        return bond;
+                    }
+                });
         networkEditor = new ListModelListBoxEditor<Object>(new 
NullSafeRenderer<Object>() {
             @Override
             protected String renderNullSafe(Object object) {
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.ui.xml
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.ui.xml
index c42d3b1..921fdd1 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.ui.xml
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostBondPopupView.ui.xml
@@ -19,7 +19,7 @@
                        <g:DockLayoutPanel ui:field="layoutPanel">
                                <g:north size="330">
                                        <g:VerticalPanel ui:field="mainPanel">
-                                               <e:ListModelListBoxEditor 
ui:field="bondEditor" />
+                                               <e:ListModelSuggestBoxEditor 
ui:field="bondEditor" />
                                                <e:ListModelListBoxEditor 
ui:field="networkEditor" />
                                                <e:ListModelListBoxEditor 
ui:field="bondingModeEditor" />
                                                <e:EntityModelTextBoxEditor 
ui:field="customEditor" visible="false" />


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I130586dc4787abecf81566a8d3b723d093f6fca2
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Lior Vernia <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to