Frank Kobzik has uploaded a new change for review.

Change subject: userportal: clarify setting style for vm item
......................................................................

userportal: clarify setting style for vm item

Basic user portal: This patch makes it clear what style the vm item
container has set based on state of the VM. instead of setting and
resetting styles from various part of the presenter, the patch
introduces single method that does this work so that it's easier to
determine the vm style.

Change-Id: I5f5de37b387c9e03c2a66843ceb82649c353ee96
Signed-off-by: Frantisek Kobzik <fkob...@redhat.com>
---
M 
frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/presenter/tab/basic/MainTabBasicListItemPresenterWidget.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.ui.xml
3 files changed, 76 insertions(+), 58 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/36942/1

diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/presenter/tab/basic/MainTabBasicListItemPresenterWidget.java
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/presenter/tab/basic/MainTabBasicListItemPresenterWidget.java
index edd8162..55c2774 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/presenter/tab/basic/MainTabBasicListItemPresenterWidget.java
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/presenter/tab/basic/MainTabBasicListItemPresenterWidget.java
@@ -32,6 +32,7 @@
 import com.gwtplatform.mvp.client.PresenterWidget;
 import com.gwtplatform.mvp.client.View;
 
+
 public class MainTabBasicListItemPresenterWidget extends 
PresenterWidget<MainTabBasicListItemPresenterWidget.ViewDef> implements 
MouseOutHandler, MouseOverHandler, ClickHandler, DoubleClickHandler {
 
     public interface ViewDef extends View, 
HasEditorDriver<UserPortalItemModel>, HasMouseOutHandlers, 
HasMouseOverHandlers, HasClickHandlers, HasDoubleClickHandlers, HasElementId {
@@ -39,16 +40,6 @@
         void showDoubleClickBanner();
 
         void hideDoubleClickBanner();
-
-        void setVmUpStyle();
-
-        void setVmDownStyle();
-
-        void setMouseOverStyle();
-
-        void setSelected();
-
-        void setNotSelected(boolean vmIsUp, boolean consoleInUse);
 
         void showErrorDialog(String message);
 
@@ -68,6 +59,15 @@
 
         void updateRebootButton(UICommand command);
 
+        void setItemSelectedStyle();
+
+        void setVmStatusUnselectedStyle();
+
+        void setItemMouseOverStyle();
+
+        void setItemRunningStyle();
+
+        void setItemNotRunningOrConsoleTakenStyle();
     }
 
     private final UserPortalBasicListProvider listModelProvider;
@@ -97,11 +97,7 @@
         selectedItemChangeListener = new IEventListener<EventArgs>() {
             @Override
             public void eventRaised(Event<? extends EventArgs> ev, Object 
sender, EventArgs args) {
-                if (!sameEntity(listModel.getSelectedItem(), model)) {
-                    getView().setNotSelected(model.isVmUp(), consoleInUse());
-                } else {
-                    getView().setSelected();
-                }
+                setVmStyle();
             }
         };
         
listModel.getSelectedItemChangedEvent().addListener(selectedItemChangeListener);
@@ -194,7 +190,7 @@
     public void setModel(UserPortalItemModel model) {
         this.model = model;
 
-        setupDefaultVmStyles();
+        setVmStyle();
 
         getView().updateRunButton(getRunCommand(), model.isPool());
         getView().updateShutdownButton(getShutdownCommand());
@@ -217,25 +213,13 @@
 
     @Override
     public void onMouseOut(MouseOutEvent event) {
+        setVmStyle();
         getView().hideDoubleClickBanner();
-        setupDefaultVmStyles();
-    }
-
-    void setupDefaultVmStyles() {
-        if (!isSelected()) {
-            if (model.isVmUp() && !consoleInUse()) {
-                getView().setVmUpStyle();
-            } else {
-                getView().setVmDownStyle();
-            }
-        }
     }
 
     @Override
     public void onMouseOver(MouseOverEvent event) {
-        if (!isSelected()) {
-            getView().setMouseOverStyle();
-        }
+        setVmStyleMouseOver();
         if (!model.isPool() && model.getVmConsoles().canConnectToConsole()) {
             getView().showDoubleClickBanner();
         }
@@ -262,7 +246,46 @@
     void setSelectedItem() {
         listModel.setSelectedItem(model);
         listModelProvider.setSelectedItems(Arrays.asList(model));
-        getView().setSelected();
+        setVmStyle();
+    }
+
+    /**
+     * Helper function for setting vm item style based on state of the vm.
+     */
+    private void setVmStyle() {
+        setVmStyleByStatus(false);
+    }
+
+    /**
+     * Helper function for setting vm item style based on state of the vm when 
mouse is over the item.
+     */
+    private void setVmStyleMouseOver() {
+        setVmStyleByStatus(true);
+    }
+
+    /**
+     * Method for setting style of a VM item container and VM text status 
based on state of the VM.
+     * Settings of VM item container style should happen in this method only.
+     * The purpose of this method is to have the decision logic in one place 
so that it's easy to
+     * determine resulting style of the item.
+     *
+     * @param mouseOver - mouse is over the item
+     */
+    private void setVmStyleByStatus(boolean mouseOver) {
+        if (isSelected()) {
+            getView().setItemSelectedStyle();
+        } else {
+            getView().setVmStatusUnselectedStyle();
+            if (mouseOver) {
+                getView().setItemMouseOverStyle();
+            } else {
+                if (model.isVmUp() && !consoleInUse()) {
+                    getView().setItemRunningStyle();
+                } else {
+                    getView().setItemNotRunningOrConsoleTakenStyle();
+                }
+            }
+        }
     }
 
     boolean isSelected() {
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.java
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.java
index 52e6917..cf1240c 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.java
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.java
@@ -265,34 +265,29 @@
     }
 
     @Override
-    public void setVmUpStyle() {
-        mainContainer.setStyleName(style.itemRunningStyle());
-    }
-
-    @Override
-    public void setVmDownStyle() {
-        mainContainer.setStyleName(style.itemNotRunningOrConsoleTakenStyle());
-    }
-
-    @Override
-    public void setMouseOverStyle() {
-        mainContainer.setStyleName(style.itemOverStyle());
-    }
-
-    @Override
-    public void setSelected() {
+    public void setItemSelectedStyle() {
         vmStatus.setStyleName(style.machineStatusSelectedStyle());
         mainContainer.setStyleName(style.itemSelectedStyle());
     }
 
     @Override
-    public void setNotSelected(boolean vmIsUp, boolean consoleInUse) {
+    public void setVmStatusUnselectedStyle() {
         vmStatus.setStyleName(style.machineStatusStyle());
-        if (vmIsUp && !consoleInUse) {
-            setVmUpStyle();
-        } else {
-            setVmDownStyle();
-        }
+    }
+
+    @Override
+    public void setItemMouseOverStyle() {
+        mainContainer.setStyleName(style.itemOverStyle());
+    }
+
+    @Override
+    public void setItemRunningStyle() {
+        mainContainer.setStyleName(style.itemRunningStyle());
+    }
+
+    @Override
+    public void setItemNotRunningOrConsoleTakenStyle() {
+        mainContainer.setStyleName(style.itemNotRunningOrConsoleTakenStyle());
     }
 
     @Override
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.ui.xml
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.ui.xml
index f613054..b3bbc2c 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.ui.xml
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/main/view/tab/basic/MainTabBasicListItemView.ui.xml
@@ -96,11 +96,11 @@
         }
 
         .itemOverStyle {
-              background-color: #B5C5D7;
+            background-color: #B5C5D7;
         }
 
         .itemNotRunningOrConsoleTakenStyle {
-             background-color: #E1E1E1;
+            background-color: #E1E1E1;
         }
 
         .itemRunningStyle {
@@ -126,9 +126,9 @@
             float: right;
         }
 
-    .rebootButtonAdditionalStyle {
-      float: right;
-    }
+        .rebootButtonAdditionalStyle {
+          float: right;
+        }
 
     </ui:style>
 


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

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

Reply via email to