Lior Vernia has uploaded a new change for review.

Change subject: webadmin: Replaced null profile with empty profile
......................................................................

webadmin: Replaced null profile with empty profile

Added a special value to represent an empty profile, and changed empty
profile instances to that instead of null. This is needed by a
soon-to-be-implemented Add/Remove VNIC widget in the Add/Edit VM
dialog, in order to discriminate between the case where a profile
hasn't yet been assigned (null) and the case where the empty profile
has been assigned (VnicProfileView.EMPTY).

Change-Id: I06962e43084ff4fd469e0025527cdd85a47f5ea7
Signed-off-by: Lior Vernia <lver...@redhat.com>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationMessages.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileEditor.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/EditProfileBehavior.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ProfileBehavior.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceModel.java
7 files changed, 31 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/19528/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
index 270edc9..1c49df9 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
@@ -10,6 +10,8 @@
     private String dataCenterName;
     private Version compatibilityVersion;
 
+    public static final VnicProfileView EMPTY = new VnicProfileView();
+
     public String getNetworkName() {
         return networkName;
     }
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationMessages.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationMessages.java
index b74e1d8..14a41f0 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationMessages.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationMessages.java
@@ -105,15 +105,21 @@
     @DefaultMessage("default: {0}")
     String defaultTimeZoneCaption(String currentDefault);
 
-    @DefaultMessage("VM has {0} Nics. Assign them to Profiles.")
+    @DefaultMessage("VM has {0} network interfaces. Assign profiles to them.")
     String assignNicsToProfilesPlural(int numOfNics);
 
-    @DefaultMessage("VM has 1 Nic. Assign it to a Profile.")
+    @DefaultMessage("VM has 1 network interface. Assign a profile to it.")
     String assignNicsToProfilesSingular();
 
     @DefaultMessage("VM has no network interfaces and there are no available 
profiles to choose from.")
     String assignNicsNothingToAssign();
 
+    @DefaultMessage("<Empty>")
+    SafeHtml emptyProfile();
+
+    @DefaultMessage("Do not assign any profile to this virtual network 
interface")
+    SafeHtml emptyProfileDescription();
+
     @DefaultMessage("{0} ({1})")
     SafeHtml profileAndNetwork(String profileName, String networkName);
 
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 a452cab..cc61ad6 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
@@ -18,17 +18,23 @@
 
                     @Override
                     public String getReplacementStringNullSafe(Object data) {
-                        return 
messages.profileAndNetworkSelected(((VnicProfileView) data).getName(),
-                                ((VnicProfileView) 
data).getNetworkName()).asString();
+                        VnicProfileView profile = (VnicProfileView) data;
+                        return (profile == VnicProfileView.EMPTY) ? 
messages.emptyProfile().asString()
+                                : 
messages.profileAndNetworkSelected(profile.getName(), profile.getNetworkName())
+                                        .asString();
                     }
 
                     @Override
                     public String getDisplayStringNullSafe(Object data) {
-                        String profileDescription =
-                                ((VnicProfileView) data).getDescription();
+                        VnicProfileView profile = (VnicProfileView) data;
+                        if (profile == VnicProfileView.EMPTY) {
+                            return 
templates.typeAheadNameDescription(messages.emptyProfile().asString(),
+                                    
messages.emptyProfileDescription().asString()).asString();
+                        }
+
+                        String profileDescription = profile.getDescription();
                         String profileAndNetwork =
-                                messages.profileAndNetwork(((VnicProfileView) 
data).getName(),
-                                        ((VnicProfileView) 
data).getNetworkName()).asString();
+                                messages.profileAndNetwork(profile.getName(), 
profile.getNetworkName()).asString();
 
                         return 
templates.typeAheadNameDescription(profileAndNetwork,
                                 profileDescription != null ? 
profileDescription : "").asString(); //$NON-NLS-1$
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
index c37f671..f6dd11d 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
@@ -1142,9 +1142,9 @@
 
         @Override
         public int compare(VnicProfileView vnicProfile1, VnicProfileView 
vnicProfile2) {
-            if (vnicProfile1 == null) {
-                return vnicProfile2 == null ? 0 : 1;
-            } else if (vnicProfile2 == null) {
+            if (vnicProfile1 == VnicProfileView.EMPTY) {
+                return vnicProfile2 == VnicProfileView.EMPTY ? 0 : 1;
+            } else if (vnicProfile2 == VnicProfileView.EMPTY) {
                 return -1;
             }
 
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/EditProfileBehavior.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/EditProfileBehavior.java
index 4c02335..472b918 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/EditProfileBehavior.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/EditProfileBehavior.java
@@ -16,7 +16,7 @@
         profiles = profiles == null ? new ArrayList<VnicProfileView>() : 
profiles;
 
         if (networkInterface.getVnicProfileId() == null) {
-            profileList.setSelectedItem(null);
+            profileList.setSelectedItem(VnicProfileView.EMPTY);
             return;
         }
 
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ProfileBehavior.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ProfileBehavior.java
index f7500dd..bb49739 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ProfileBehavior.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ProfileBehavior.java
@@ -33,6 +33,9 @@
                 ProfileBehavior.this.clusterNetworks = clusterNetworks;
 
                 List<VnicProfileView> vnicProfiles = new 
ArrayList<VnicProfileView>();
+                if (hotUpdateSupported) {
+                    vnicProfiles.add(VnicProfileView.EMPTY);
+                }
 
                 if (returnValue == null) {
                     return vnicProfiles;
@@ -44,10 +47,6 @@
                         vnicProfiles.add(vnicProfile);
                     }
 
-                }
-
-                if (hotUpdateSupported) {
-                    vnicProfiles.add(null);
                 }
 
                 Collections.sort(vnicProfiles, new 
Linq.VnicProfileViewComparator());
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceModel.java
index b8c0c12..48f45d4 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmInterfaceModel.java
@@ -383,8 +383,8 @@
         // Save changes.
         nic.setName((String) getName().getEntity());
         VnicProfileView profile = (VnicProfileView) 
getProfile().getSelectedItem();
-        nic.setVnicProfileId(profile != null ? profile.getId() : null);
-        nic.setNetworkName(profile != null ? profile.getNetworkName() : null);
+        nic.setVnicProfileId(profile.getId());
+        nic.setNetworkName(profile.getNetworkName());
         nic.setLinked((Boolean) getLinked().getEntity());
         if (getNicType().getSelectedItem() == null)
         {


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I06962e43084ff4fd469e0025527cdd85a47f5ea7
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