Alona Kaplan has uploaded a new change for review.

Change subject: webadmin: add validation to edit vfsConfig dialog
......................................................................

webadmin: add validation to edit vfsConfig dialog

Change-Id: I6d96834d2e92ab28dc11237f40f6808ae909f7d1
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostNicModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/NicLabelModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/PfNicLabelModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/SetupNetworksBondModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/VfsConfigModel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/host/HostNicPopupPresenterWidget.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostNicPopupView.java
7 files changed, 67 insertions(+), 21 deletions(-)


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

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostNicModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostNicModel.java
index 319e669..aaf4d37 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostNicModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostNicModel.java
@@ -9,10 +9,13 @@
 import org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
+import org.ovirt.engine.ui.uicommonweb.models.HasValidatedTabs;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
+import org.ovirt.engine.ui.uicommonweb.models.TabName;
+import org.ovirt.engine.ui.uicommonweb.models.ValidationCompleteEvent;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
 
-public class HostNicModel extends Model {
+public class HostNicModel extends Model implements HasValidatedTabs {
 
     public static final VfsConfigModel EMPTY_VFS_CONFIG_MODEL = new 
VfsConfigModel();
     public static final PfNicLabelModel EMPTY_LABELS_MODEL = new 
PfNicLabelModel();
@@ -44,7 +47,22 @@
     }
 
     public boolean validate() {
-        return labelsModel == EMPTY_LABELS_MODEL ? true : 
labelsModel.validate();
+        if (vfsConfigModel == EMPTY_VFS_CONFIG_MODEL) {
+            vfsConfigModel.setIsValid(true);
+        } else {
+            vfsConfigModel.validate();
+        }
+
+        if (labelsModel == EMPTY_LABELS_MODEL) {
+            labelsModel.setIsValid(true);
+        } else {
+            labelsModel.validate();
+        }
+        setValidTab(TabName.PF_TAB, labelsModel.getIsValid());
+        setValidTab(TabName.VFS_CONFIG_TAB, vfsConfigModel.getIsValid());
+
+        ValidationCompleteEvent.fire(getEventBus(), this);
+        return allTabsValid();
     }
 
     public VfsConfigModel getVfsConfigModel() {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/NicLabelModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/NicLabelModel.java
index 16f1ee5..b618b79 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/NicLabelModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/NicLabelModel.java
@@ -9,6 +9,9 @@
 
 import 
org.ovirt.engine.core.common.businessentities.comparators.LexoNumericComparator;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
+import org.ovirt.engine.ui.uicommonweb.validation.AsciiNameValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
+import org.ovirt.engine.ui.uicompat.ConstantsManager;
 
 public abstract class NicLabelModel extends ListModel<ListModel<String>> {
     private List<String> originalLabels;
@@ -50,4 +53,23 @@
         }
         return selectedLabels;
     }
+
+    public void validate() {
+        boolean res = true;
+        Set<String> editedLabels = new HashSet<String>();
+        for (ListModel<String> labelModel : getItems()) {
+            labelModel.validateSelectedItem(new IValidation[] { new 
AsciiNameValidation() });
+
+            String label = labelModel.getSelectedItem();
+
+            if (editedLabels.contains(label)) {
+                
labelModel.getInvalidityReasons().add(ConstantsManager.getInstance().getConstants().duplicateLabel());
+                labelModel.setIsValid(false);
+            }
+            editedLabels.add(label);
+
+            res &= labelModel.getIsValid();
+        }
+        setIsValid(res);;
+    }
 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/PfNicLabelModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/PfNicLabelModel.java
index db70dd4..d4c6ae2 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/PfNicLabelModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/PfNicLabelModel.java
@@ -10,8 +10,6 @@
 
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
-import org.ovirt.engine.ui.uicommonweb.validation.AsciiNameValidation;
-import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
 
 public class PfNicLabelModel extends NicLabelModel {
@@ -55,12 +53,11 @@
         flushedLabels = new HashSet<String>();
     }
 
-    public boolean validate() {
-        Set<String> editedLabels = new HashSet<String>();
-        boolean res = true;
+    @Override
+    public void validate() {
+        super.validate();
+        boolean res = getIsValid();
         for (ListModel<String> labelModel : getItems()) {
-            labelModel.validateSelectedItem(new IValidation[] { new 
AsciiNameValidation() });
-
             String label = labelModel.getSelectedItem();
             String usingIface = labelToIface.get(label);
             if (usingIface != null && !containedIfaces.contains(usingIface)) {
@@ -70,15 +67,9 @@
                 labelModel.setIsValid(false);
             }
 
-            if (editedLabels.contains(label)) {
-                
labelModel.getInvalidityReasons().add(ConstantsManager.getInstance().getConstants().duplicateLabel());
-                labelModel.setIsValid(false);
-            }
-            editedLabels.add(label);
-
             res &= labelModel.getIsValid();
         }
-        return res;
+        setIsValid(res);;
     }
 
     /**
@@ -112,7 +103,7 @@
     /**
      * Clears the labels from the original interfaces composing this 
interface, and committing the actual labels (after
      * removal/addition by the user).
-     *
+     * 
      * @param the
      *            interface to which the actual labels will be committed.
      */
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/SetupNetworksBondModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/SetupNetworksBondModel.java
index 6bdca8f..02123b3 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/SetupNetworksBondModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/SetupNetworksBondModel.java
@@ -19,7 +19,8 @@
 
     @Override
     public boolean validate() {
-        return getLabelsModel().validate();
+        getLabelsModel().validate();
+        return getLabelsModel().getIsValid();
     }
 
 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/VfsConfigModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/VfsConfigModel.java
index 07502eb..87b4458 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/VfsConfigModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/VfsConfigModel.java
@@ -13,6 +13,9 @@
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
+import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
 
 public class VfsConfigModel extends EntityModel<HostNicVfsConfig> {
@@ -89,6 +92,15 @@
         networks.setItems(vfsConfigNetworks);
     }
 
+    public void validate() {
+        numOfVfs.validateEntity(new IValidation[] { new NotEmptyValidation(),
+                new IntegerValidation(0, getMaxNumOfVfs().getEntity()) });
+
+        labelsModel.validate();
+
+        setIsValid(labelsModel.getIsValid() && numOfVfs.getIsValid());
+    }
+
     public static enum AllNetworksSelector {
         
allNetworkAllowed(ConstantsManager.getInstance().getConstants().allNetworksAllowed()),
         
specificNetworks(ConstantsManager.getInstance().getConstants().specificNetworksAllowed());
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/host/HostNicPopupPresenterWidget.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/host/HostNicPopupPresenterWidget.java
index 2738380..0188de2 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/host/HostNicPopupPresenterWidget.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/host/HostNicPopupPresenterWidget.java
@@ -1,14 +1,14 @@
 package org.ovirt.engine.ui.webadmin.section.main.presenter.popup.host;
 
-import 
org.ovirt.engine.ui.common.presenter.AbstractModelBoundPopupPresenterWidget;
+import 
org.ovirt.engine.ui.common.presenter.AbstractTabbedModelBoundPopupPresenterWidget;
 import org.ovirt.engine.ui.uicommonweb.models.hosts.HostNicModel;
 
 import com.google.gwt.event.shared.EventBus;
 import com.google.inject.Inject;
 
-public class HostNicPopupPresenterWidget extends 
AbstractModelBoundPopupPresenterWidget<HostNicModel, 
HostNicPopupPresenterWidget.ViewDef> {
+public class HostNicPopupPresenterWidget extends 
AbstractTabbedModelBoundPopupPresenterWidget<HostNicModel, 
HostNicPopupPresenterWidget.ViewDef> {
 
-    public interface ViewDef extends 
AbstractModelBoundPopupPresenterWidget.ViewDef<HostNicModel> {
+    public interface ViewDef extends 
AbstractTabbedModelBoundPopupPresenterWidget.ViewDef<HostNicModel> {
         void showTabs();
 
         void showOnlyPf();
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostNicPopupView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostNicPopupView.java
index 534c695..a9bef89 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostNicPopupView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/HostNicPopupView.java
@@ -107,6 +107,7 @@
 
     @Override
     public void showOnlyPf() {
+        getTabPanel().switchTab(pfTab);
         tabPanel.setVisible(false);
         contentPanel.setWidget(pfTab.getContent());
         mainPanel.setWidth("400px"); //$NON-NLS-1$
@@ -115,6 +116,7 @@
 
     @Override
     public void showOnlyVfsConfig() {
+        getTabPanel().switchTab(vfsConfigTab);
         tabPanel.setVisible(false);
         contentPanel.setWidget(vfsConfigTab.getContent());
         mainPanel.setWidth("515px"); //$NON-NLS-1$


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

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

Reply via email to