Tomas Jelinek has uploaded a new change for review.

Change subject: frontend: Select an empty profile does not work
......................................................................

frontend: Select an empty profile does not work

There were the following issuse:
- the empty profile is represented by null but the ListModelTypeAheadListBox
  did not supported it. Fixed by adding the null as a supported value
- the null has been rendered by NullSafeSuggestBoxRenderer as an empty String
  but it was  nearly invisable in the editor. Fixed by adding a specific
  template for this case into the CommonApplicationTemplates
- the network name was not set (only the profile id). While the network
  name is depricated, it is still used by
  VmInterfaceManager.updateNicForBackwardCompatibility and expected to
  be set

Change-Id: I199d4ce14b55b3f552cf6138b7c3c5d21d620ccc
Signed-off-by: Tomas Jelinek <tjeli...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationTemplates.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java
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/ProfileInstanceTypeEditor.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java
6 files changed, 30 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/91/18791/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationTemplates.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationTemplates.java
index 37b0a71..19a52aa 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationTemplates.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationTemplates.java
@@ -68,12 +68,17 @@
     SafeHtml italicText(String text);
 
     @Template("<table style='min-width: 200px; width: 100%; border-bottom: 1px 
solid #acacac;'><tr>" +
-            "<td style='width: 49%;'>{0}</td>" +
+            "<td style='width: 49%;'>{0}&nbsp;</td>" +
             "<td style='width: 2%; border-left: 1px solid #acacac;'></td>" +
             "<td style='white-space: normal; width: 49%; color: 
#acacac;'>{1}</td>" +
             "</tr></table>")
     SafeHtml typeAheadNameDescription(String name, String description);
 
+    @Template("<table style='min-width: 200px; width: 100%; border-bottom: 1px 
solid #acacac;'><tr>" +
+            "<td>&nbsp</td>" +
+            "</tr></table>")
+    SafeHtml typeAheadEmptyContent();
+
     @Template("<div style='width: {0}; font-style: italic;'>{1}</div>")
     SafeHtml italicFixedWidth(String pxWidth, String text);
 
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java
index f7fd9c6..c7d82fd 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java
@@ -145,7 +145,8 @@
     /**
      * Returns the entity representation of the given String which was passed 
to the suggest box.
      * @param value String from the suggest box
-     * @return the entity representation, or null if incorrect value passed
+     * @throws IllegalArgumentException if incorrect value has been passed
+     * @return the entity representation
      */
     protected abstract T asEntity(String value);
 
@@ -159,10 +160,11 @@
         return asSuggestBox().addValueChangeHandler(new 
ValueChangeHandler<String>() {
             @Override
             public void onValueChange(ValueChangeEvent<String> event) {
-                T value = asEntity(event.getValue());
-                if (value != null) {
-                    handler.onValueChange(new ValueChangeEvent<T>(value) {
-                    });
+                try {
+                    T value = asEntity(event.getValue());
+                    handler.onValueChange(new ValueChangeEvent<T>(value) {});
+                } catch (IllegalArgumentException e) {
+                    // ignore - the user entered an incorrect string. Just do 
not notify the listeners
                 }
             }
         });
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 b18a2e6..51ec5b8 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
@@ -211,11 +211,11 @@
             }
         } else {
             // something has been typed inside - validate
-            T newData = asEntity(providedText);
-            if (newData != null) {
+            try {
+                T newData = asEntity(providedText);
                 // correct provided - use it
                 setValue(newData);
-            } else {
+            } catch (IllegalArgumentException e) {
                 // incorrect - return to previous one
                 
asSuggestBox().setText(renderer.getReplacementString(getValue()));
             }
@@ -225,14 +225,10 @@
     @Override
     protected T asEntity(String provided) {
         if (provided == null) {
-            return null;
+            throw new IllegalArgumentException("Only non-null arguments are 
accepted"); //$NON-NLS-1$
         }
 
         for (T data : acceptableValues) {
-            if (data == null) {
-                continue;
-            }
-
             String expected = renderer.getReplacementString(data);
             if (expected == null) {
                 continue;
@@ -243,7 +239,7 @@
             }
         }
 
-        return null;
+        throw new IllegalArgumentException("The provided value is not 
acceptable: '" + provided + "'"); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     public void setValue(T value) {
@@ -427,7 +423,11 @@
             Suggestion currentSelection = 
listModelTypeAheadListBox.getCurrentSelection();
             if (currentSelection != null) {
                 String replacementString = 
currentSelection.getReplacementString();
-                
listModelTypeAheadListBox.setValue(listModelTypeAheadListBox.asEntity(replacementString),
 true);
+                try {
+                    
listModelTypeAheadListBox.setValue(listModelTypeAheadListBox.asEntity(replacementString),
 true);
+                } catch (IllegalArgumentException e) {
+                    // do not set the value if it is not a correct one
+                }
             }
 
             listModelTypeAheadListBox.hideSuggestions();
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 62c55f4..660f7fb 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
@@ -1,5 +1,7 @@
 package org.ovirt.engine.ui.common.widget.editor;
 
+import com.google.gwt.core.client.GWT;
+import org.ovirt.engine.ui.common.CommonApplicationTemplates;
 import org.ovirt.engine.ui.common.widget.AbstractValidatedWidgetWithLabel;
 import org.ovirt.engine.ui.common.widget.VisibilityRenderer;
 
@@ -51,6 +53,8 @@
 
     public static abstract class NullSafeSuggestBoxRenderer<T> implements 
SuggestBoxRenderer<T> {
 
+        private static final CommonApplicationTemplates templates = 
GWT.create(CommonApplicationTemplates.class);
+
         @Override
         public String getReplacementString(T data) {
             return emptyOr(data == null ? "" : 
getReplacementStringNullSafe(data));
@@ -58,7 +62,7 @@
 
         @Override
         public String getDisplayString(T data) {
-            return emptyOr(data == null ? "" : getDisplayStringNullSafe(data));
+            return emptyOr(data == null ? 
templates.typeAheadEmptyContent().asString() : getDisplayStringNullSafe(data));
         }
 
         private String emptyOr(String string) {
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.java
index 84a7a61..268607a 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.java
@@ -63,6 +63,7 @@
         // flush
         VnicProfileView profile = (VnicProfileView) 
profileEditor.asEditor().getSubEditor().getValue();
         vnicIntsanceType.getNetworkInterface().setVnicProfileId(profile != 
null ? profile.getId() : null);
+        vnicIntsanceType.getNetworkInterface().setNetworkName(profile != null 
? profile.getNetworkName() : null);
         return vnicIntsanceType;
     }
 
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java
index bb590f5..ba0ed05 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceCreatingManager.java
@@ -160,6 +160,7 @@
 
                                 if (sameNic && assignedProfileChanged) {
                                     
created.setVnicProfileId(edited.getNetworkInterface().getVnicProfileId());
+                                    
created.setNetworkName(edited.getNetworkInterface().getNetworkName());
                                     parameters.add(new 
AddVmInterfaceParameters(vmId, created));
                                     break;
                                 }


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

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

Reply via email to