Tomas Jelinek has uploaded a new change for review.

Change subject: userportal: windows 8/2012 default user portal console should 
be RDP
......................................................................

userportal: windows 8/2012 default user portal console should be RDP

Since windows 8/2012 don't have spice drivers yet, default in user portal
should be rdp.

Default in admin will stay spice.

This default is recalculated if the OS type or the default console changes

Change-Id: I019f3f80e020a85fb6b2ae8a855a0c3fe89ba1d6
Signed-off-by: Tomas Jelinek <[email protected]>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java
A 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleSelectionContext.java
4 files changed, 88 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/11/10211/1

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
index aa2bcfa..d0f40fa 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java
@@ -18,6 +18,7 @@
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.models.ListWithDetailsModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.ConsoleModel;
+import org.ovirt.engine.ui.uicommonweb.models.vms.ConsoleSelectionContext;
 import org.ovirt.engine.ui.uicommonweb.models.vms.RdpConsoleModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.SpiceConsoleModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.VncConsoleModel;
@@ -36,8 +37,9 @@
     private static final int VNC_INDEX = 1;
     private static final int RDP_INDEX = 2;
 
-    // TODO requires a different patch to be merged first
-    private static final List<VmOsType> vmOsTypeWithoutSpiceDriverSupport = 
Arrays.asList();
+    private static final List<VmOsType> vmOsTypeWithoutSpiceDriverSupport = 
Arrays.asList(VmOsType.Windows8,
+            VmOsType.Windows8x64,
+            VmOsType.Windows2012x64);
 
     public IUserPortalListModel() {
         cachedConsoleModels = new HashMap<Guid, ArrayList<ConsoleModel>>();
@@ -181,6 +183,10 @@
                                 spiceConsoleModel, vncConsoleModel, 
rdpConsoleModel })));
 
                 updateDefaultSelectedConsoleProtocol(vm);
+            } else if (selectionContextChanged(vm)) {
+                // if new data comes which has changed the selection context, 
(e.g. the OS type changed)
+                // recalculate the default selected protocol
+                updateDefaultSelectedConsoleProtocol(vm);
             }
 
             // Getting cached console model
@@ -208,8 +214,19 @@
         }
     }
 
+    private boolean selectionContextChanged(VM vm) {
+        ConsoleSelectionContext newContext = new 
ConsoleSelectionContext(vm.getVmOs(), vm.getDefaultDisplayType());
+        ConsoleModel selectedConsole = resolveSelectedConsoleModel(vm.getId());
+
+        if (selectedConsole == null) {
+            return true;
+        }
+
+        return !newContext.equals(selectedConsole.getSelectionContext());
+    }
+
     protected ConsoleModel determineConsoleModelFromVm(VM vm, 
ArrayList<ConsoleModel> cachedModels) {
-        return vm.getDisplayType() == DisplayType.vnc ? 
cachedModels.get(VNC_INDEX) : cachedModels.get(SPICE_INDEX);
+        return vm.getDefaultDisplayType() == DisplayType.vnc ? 
cachedModels.get(VNC_INDEX) : cachedModels.get(SPICE_INDEX);
     }
 
     protected void updateDefaultSelectedConsoleProtocol(VM vm) {
@@ -231,6 +248,14 @@
             cachedModels.get(RDP_INDEX).setUserSelected(true);
         } else {
             determineConsoleModelFromVm(vm, 
cachedModels).setUserSelected(true);
+        }
+
+        setupSelectionContext(vm);
+    }
+
+    private void setupSelectionContext(VM vm) {
+        for (ConsoleModel model : cachedConsoleModels.get(vm.getId())) {
+            model.setSelectionContext(new 
ConsoleSelectionContext(vm.getVmOs(), vm.getDefaultDisplayType()));
         }
     }
 
@@ -264,11 +289,16 @@
             return null;
         }
 
+        ConsoleModel selectedConsoleModel = resolveSelectedConsoleModel(vmId);
+        return selectedConsoleModel == null ? null
+                : 
ConsoleProtocol.getProtocolByModel(selectedConsoleModel.getClass());
+    }
+
+    private ConsoleModel resolveSelectedConsoleModel(Guid vmId) {
         for (ConsoleModel model : cachedConsoleModels.get(vmId)) {
             if (model.isUserSelected()) {
-                return ConsoleProtocol.getProtocolByModel(model.getClass());
+                return model;
             }
-
         }
 
         return null;
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
index bf02d4f..281b7d6 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
@@ -1334,8 +1334,6 @@
             
gettempVm().setMigrationSupport(MigrationSupport.IMPLICITLY_NON_MIGRATABLE);
         }
 
-        updateDefaultSelectedConsoleProtocol(gettempVm());
-
         if (model.getIsNew())
         {
             if (gettempVm().getVmtGuid().equals(NGuid.Empty))
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java
index a186af6..d4ae410 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java
@@ -24,6 +24,16 @@
         return userSelected;
     }
 
+    private ConsoleSelectionContext selectionContext;
+
+    public ConsoleSelectionContext getSelectionContext() {
+        return selectionContext;
+    }
+
+    public void setSelectionContext(ConsoleSelectionContext selectionContext) {
+        this.selectionContext = selectionContext;
+    }
+
     public void setUserSelected(boolean userSelected) {
         this.userSelected = userSelected;
     }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleSelectionContext.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleSelectionContext.java
new file mode 100644
index 0000000..5751639
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleSelectionContext.java
@@ -0,0 +1,43 @@
+package org.ovirt.engine.ui.uicommonweb.models.vms;
+
+import org.ovirt.engine.core.common.businessentities.DisplayType;
+import org.ovirt.engine.core.common.businessentities.VmOsType;
+
+public class ConsoleSelectionContext {
+
+    private VmOsType osType;
+
+    private DisplayType defaultDisplayType;
+
+    public ConsoleSelectionContext(VmOsType osType, DisplayType 
consoleProtocol) {
+        super();
+        this.osType = osType;
+        this.defaultDisplayType = consoleProtocol;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((defaultDisplayType == null) ? 0 : 
defaultDisplayType.hashCode());
+        result = prime * result + ((osType == null) ? 0 : osType.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ConsoleSelectionContext other = (ConsoleSelectionContext) obj;
+        if (defaultDisplayType != other.defaultDisplayType)
+            return false;
+        if (osType != other.osType)
+            return false;
+        return true;
+    }
+
+}


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

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

Reply via email to