Lior Vernia has uploaded a new change for review.

Change subject: webadmin: Refactored code concerning Neutron agent
......................................................................

webadmin: Refactored code concerning Neutron agent

This code would be common with the soon-to-be-added Network Provider
tab in HostModel. Refactored into NeutronAgentBehavior on the model
side and into NeutronAgentSection on the view side.

Change-Id: Ifbec5113f146e4955945d6913c5b11eb60ca2389
Signed-off-by: Lior Vernia <lver...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.java
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.ui.xml
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/AddProviderModel.java
A 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronAgentBehavior.java
A 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronPluginTranslator.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/provider/ProviderPopupPresenterWidget.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.ui.xml
11 files changed, 390 insertions(+), 194 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/93/16893/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
index 9e5de5b..0e0dcd3 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.ui.common;
 
 import com.google.gwt.i18n.client.Constants;
+import com.google.gwt.i18n.client.Constants.DefaultStringValue;
 
 public interface CommonApplicationConstants extends Constants {
 
@@ -208,6 +209,18 @@
     @DefaultStringValue("Force Remove")
     String forceRemove();
 
+    @DefaultStringValue("Host")
+    String hostQpid();
+
+    @DefaultStringValue("Port")
+    String portQpid();
+
+    @DefaultStringValue("Username")
+    String usernameQpid();
+
+    @DefaultStringValue("Password")
+    String passwordQpid();
+
     // General
     @DefaultStringValue("Yes")
     String yes();
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.java
new file mode 100644
index 0000000..01818a6
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.java
@@ -0,0 +1,116 @@
+package org.ovirt.engine.ui.common.widget.uicommon.popup.provider;
+
+import org.ovirt.engine.ui.common.CommonApplicationConstants;
+import org.ovirt.engine.ui.common.idhandler.ElementIdHandler;
+import org.ovirt.engine.ui.common.idhandler.WithElementId;
+import org.ovirt.engine.ui.common.widget.editor.EntityModelPasswordBoxEditor;
+import org.ovirt.engine.ui.common.widget.editor.EntityModelTextBoxEditor;
+import 
org.ovirt.engine.ui.common.widget.uicommon.popup.AbstractModelBoundPopupWidget;
+import org.ovirt.engine.ui.uicommonweb.models.providers.NeutronAgentBehavior;
+import org.ovirt.engine.ui.uicompat.Event;
+import org.ovirt.engine.ui.uicompat.EventArgs;
+import org.ovirt.engine.ui.uicompat.IEventListener;
+import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.editor.client.SimpleBeanEditorDriver;
+import com.google.gwt.resources.client.CssResource;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.Label;
+import com.google.inject.Inject;
+
+public class NeutronAgentSection extends 
AbstractModelBoundPopupWidget<NeutronAgentBehavior> {
+
+    interface Driver extends SimpleBeanEditorDriver<NeutronAgentBehavior, 
NeutronAgentSection> {
+    }
+
+    private final Driver driver = GWT.create(Driver.class);
+
+    interface ViewUiBinder extends UiBinder<FlowPanel, NeutronAgentSection> {
+        ViewUiBinder uiBinder = GWT.create(ViewUiBinder.class);
+    }
+
+    interface ViewIdHandler extends ElementIdHandler<NeutronAgentSection> {
+        ViewIdHandler idHandler = GWT.create(ViewIdHandler.class);
+    }
+
+    interface Style extends CssResource {
+    }
+
+    @UiField
+    @Path(value = "interfaceMappings.entity")
+    @WithElementId("interfaceMappings")
+    EntityModelTextBoxEditor interfaceMappings;
+
+    @UiField
+    @Ignore
+    Label qpidTitle;
+
+    @UiField
+    @Path(value = "qpidHost.entity")
+    @WithElementId("qpidHost")
+    EntityModelTextBoxEditor qpidHost;
+
+    @UiField
+    @Path(value = "qpidPort.entity")
+    @WithElementId("qpidPort")
+    EntityModelTextBoxEditor qpidPort;
+
+    @UiField
+    @Path(value = "qpidUsername.entity")
+    @WithElementId("qpidUsername")
+    EntityModelTextBoxEditor qpidUsername;
+
+    @UiField
+    @Path(value = "qpidPassword.entity")
+    @WithElementId("qpidPassword")
+    EntityModelPasswordBoxEditor qpidPassword;
+
+    @UiField
+    Style style;
+
+    @Inject
+    public NeutronAgentSection(CommonApplicationConstants constants) {
+        initWidget(ViewUiBinder.uiBinder.createAndBindUi(this));
+        ViewIdHandler.idHandler.generateAndSetIds(this);
+
+        qpidTitle.setText(constants.qpid());
+        qpidHost.setLabel(constants.hostQpid());
+        qpidPort.setLabel(constants.portQpid());
+        qpidUsername.setLabel(constants.usernameQpid());
+        qpidPassword.setLabel(constants.passwordQpid());
+
+        driver.initialize(this);
+    }
+
+    @Override
+    public void edit(final NeutronAgentBehavior behavior) {
+        qpidTitle.setVisible(behavior.getIsAvailable());
+        interfaceMappings.setLabel((String) 
behavior.getInterfaceMappingsLabel().getEntity());
+        behavior.getPropertyChangedEvent().addListener(new IEventListener() {
+
+            @Override
+            public void eventRaised(Event ev, Object sender, EventArgs args) {
+                if ("IsAvailable".equals(((PropertyChangedEventArgs) 
args).PropertyName)) { //$NON-NLS-1$
+                    qpidTitle.setVisible(behavior.getIsAvailable());
+                }
+            }
+        });
+        
behavior.getInterfaceMappingsLabel().getEntityChangedEvent().addListener(new 
IEventListener() {
+
+            @Override
+            public void eventRaised(Event ev, Object sender, EventArgs args) {
+                interfaceMappings.setLabel((String) 
behavior.getInterfaceMappingsLabel().getEntity());
+            }
+        });
+        driver.edit(behavior);
+    }
+
+    @Override
+    public NeutronAgentBehavior flush() {
+        return driver.flush();
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.ui.xml
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.ui.xml
new file mode 100644
index 0000000..0adc402
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/provider/NeutronAgentSection.ui.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent";>
+<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
+       xmlns:g="urn:import:com.google.gwt.user.client.ui" 
xmlns:e="urn:import:org.ovirt.engine.ui.common.widget.editor">
+
+       <ui:with field='constants' 
type='org.ovirt.engine.ui.common.CommonApplicationConstants'/>
+       <ui:style 
type="org.ovirt.engine.ui.common.widget.uicommon.popup.provider.NeutronAgentSection.Style">
+               .sectionStyle {
+                       margin-top: 20px;
+               }
+
+        .qpidInnerPanel {
+            padding-left: 20px;
+        }
+
+        .qpidHeader {
+                       font-weight: bold;
+            margin-top: 10px;
+            margin-bottom: 10px;
+            paading-right: 6px;
+               }
+       </ui:style>
+
+       <g:FlowPanel>
+               <g:FlowPanel>
+                       <e:EntityModelTextBoxEditor 
ui:field="interfaceMappings"/>
+               </g:FlowPanel>
+               <g:FlowPanel addStyleNames="{style.sectionStyle}">
+                       <g:Label ui:field="qpidTitle" 
addStyleNames="{style.qpidHeader}"/>
+                       <g:FlowPanel addStyleNames="{style.qpidInnerPanel}">
+                               <e:EntityModelTextBoxEditor 
ui:field="qpidHost"/>
+                               <e:EntityModelTextBoxEditor 
ui:field="qpidPort"/>
+                               <e:EntityModelTextBoxEditor 
ui:field="qpidUsername"/>
+                               <e:EntityModelPasswordBoxEditor 
ui:field="qpidPassword"/>
+                       </g:FlowPanel>
+               </g:FlowPanel>
+       </g:FlowPanel>
+
+</ui:UiBinder>
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/AddProviderModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/AddProviderModel.java
index 6cc55ba..d6f5c67 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/AddProviderModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/AddProviderModel.java
@@ -8,8 +8,6 @@
 
 public class AddProviderModel extends ProviderModel {
 
-    private static final String QPID_PORT_DEFAULT = "5672"; //$NON-NLS-1$
-
     @SuppressWarnings("unchecked")
     public AddProviderModel(ProviderListModel sourceListModel) {
         super(sourceListModel, VdcActionType.AddProvider, new Provider());
@@ -18,8 +16,6 @@
 
         getType().setSelectedItem(Linq.firstOrDefault((Iterable<ProviderType>) 
getType().getItems()));
         getRequiresAuthentication().setEntity(false);
-
-        getQpidPort().setEntity(QPID_PORT_DEFAULT);
     }
 
 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronAgentBehavior.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronAgentBehavior.java
new file mode 100644
index 0000000..4873558
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronAgentBehavior.java
@@ -0,0 +1,136 @@
+package org.ovirt.engine.ui.uicommonweb.models.providers;
+
+import 
org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions;
+import org.ovirt.engine.core.common.businessentities.ProviderType;
+import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
+import org.ovirt.engine.ui.uicommonweb.models.ListModel;
+import org.ovirt.engine.ui.uicommonweb.validation.HostAddressValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.InterfaceMappingsValidation;
+import org.ovirt.engine.ui.uicompat.ConstantsManager;
+import org.ovirt.engine.ui.uicompat.Event;
+import org.ovirt.engine.ui.uicompat.EventArgs;
+import org.ovirt.engine.ui.uicompat.IEventListener;
+import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;
+
+public class NeutronAgentBehavior extends EntityModel {
+
+    private static final String QPID_PORT_DEFAULT = "5672"; //$NON-NLS-1$
+
+    private final ListModel type;
+    private final ListModel pluginType;
+
+    private EntityModel interfaceMappingsLabel = new EntityModel();
+    private EntityModel interfaceMappings = new EntityModel();
+    private EntityModel qpidHost = new EntityModel();
+    private EntityModel qpidPort = new EntityModel();
+    private EntityModel qpidUsername = new EntityModel();
+    private EntityModel qpidPassword = new EntityModel();
+
+    public ListModel getType() {
+        return type;
+    }
+
+    public ListModel getPluginType() {
+        return pluginType;
+    }
+
+    public EntityModel getInterfaceMappings() {
+        return interfaceMappings;
+    }
+
+    public EntityModel getInterfaceMappingsLabel() {
+        return interfaceMappingsLabel;
+    }
+
+    public EntityModel getQpidHost() {
+        return qpidHost;
+    }
+
+    public EntityModel getQpidPort() {
+        return qpidPort;
+    }
+
+    public EntityModel getQpidUsername() {
+        return qpidUsername;
+    }
+
+    public EntityModel getQpidPassword() {
+        return qpidPassword;
+    }
+
+    public NeutronAgentBehavior(final ListModel type, final ListModel 
pluginType) {
+        this.type = type;
+        this.pluginType = pluginType;
+
+        getType().getSelectedItemChangedEvent().addListener(new 
IEventListener() {
+            @Override
+            public void eventRaised(Event ev, Object sender, EventArgs args) {
+                updateAvailability();
+            }
+        });
+        getPluginType().getSelectedItemChangedEvent().addListener(new 
IEventListener() {
+            @Override
+            public void eventRaised(Event ev, Object sender, EventArgs args) {
+                updateAvailability();
+                String displayString = getPluginDisplayString();
+                if 
(!NeutronPluginTranslator.isDisplayStringCustom(displayString)) {
+                    
switch(NeutronPluginTranslator.getPluginTypeForDisplayString(displayString)) {
+                        case OPEN_VSWITCH:
+                        
getInterfaceMappingsLabel().setEntity(ConstantsManager.getInstance()
+                                .getConstants()
+                                .bridgeMappings());
+                            break;
+                        case LINUX_BRIDGE:
+                        default:
+                        
getInterfaceMappingsLabel().setEntity(ConstantsManager.getInstance()
+                                .getConstants()
+                                .interfaceMappings());
+                    }
+                }
+            }
+        });
+        getPropertyChangedEvent().addListener(new IEventListener() {
+
+            @Override
+            public void eventRaised(Event ev, Object sender, EventArgs args) {
+                if ("IsAvailable".equals(((PropertyChangedEventArgs) 
args).PropertyName)) { //$NON-NLS-1$
+                    boolean available = getIsAvailable();
+                    getInterfaceMappings().setIsAvailable(available);
+                    getQpidHost().setIsAvailable(available);
+                    getQpidPort().setIsAvailable(available);
+                    getQpidUsername().setIsAvailable(available);
+                    getQpidPassword().setIsAvailable(available);
+                }
+            }
+        });
+
+        
getInterfaceMappingsLabel().setEntity(ConstantsManager.getInstance().getConstants().interfaceMappings());
+        getQpidPort().setEntity(QPID_PORT_DEFAULT);
+    }
+
+    private void updateAvailability() {
+        boolean providerNeutron = getType().getSelectedItem() == 
ProviderType.OPENSTACK_NETWORK;
+        getPluginType().setIsAvailable(providerNeutron);
+        setIsAvailable(providerNeutron
+                && 
!NeutronPluginTranslator.isDisplayStringCustom(getPluginDisplayString()));
+    }
+
+    private String getPluginDisplayString() {
+        String res = (String) getPluginType().getSelectedItem();
+        return (res == null) ? new String() : res;
+    }
+
+    public boolean validate() {
+        if (getIsAvailable()) {
+            getInterfaceMappings().validateEntity(new IValidation[] { new 
InterfaceMappingsValidation() });
+            getQpidHost().validateEntity(new IValidation[] { new 
HostAddressValidation(true) });
+            getQpidPort().validateEntity(new IValidation[] { new 
IntegerValidation(BusinessEntitiesDefinitions.NETWORK_MIN_LEGAL_PORT,
+                    BusinessEntitiesDefinitions.NETWORK_MAX_LEGAL_PORT) });
+            return getInterfaceMappings().getIsValid() && 
getQpidHost().getIsValid() && getQpidPort().getIsValid();
+        }
+        return true;
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronPluginTranslator.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronPluginTranslator.java
new file mode 100644
index 0000000..39eef57
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/NeutronPluginTranslator.java
@@ -0,0 +1,51 @@
+package org.ovirt.engine.ui.uicommonweb.models.providers;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import 
org.ovirt.engine.core.common.businessentities.OpenstackNetworkPluginType;
+import org.ovirt.engine.ui.uicompat.EnumTranslator;
+
+public class NeutronPluginTranslator {
+
+    private static final Map<String, OpenstackNetworkPluginType> 
pluginForDisplay;
+
+    static {
+        pluginForDisplay = new HashMap<String, OpenstackNetworkPluginType>();
+        for (OpenstackNetworkPluginType plugin : 
OpenstackNetworkPluginType.values()) {
+            pluginForDisplay.put(EnumTranslator.createAndTranslate(plugin), 
plugin);
+        }
+    }
+
+    public static Set<String> getPresetDisplayStrings() {
+        return pluginForDisplay.keySet();
+    }
+
+    public static boolean isDisplayStringCustom(String displayString) {
+        return !pluginForDisplay.containsKey(displayString);
+    }
+
+    public static OpenstackNetworkPluginType 
getPluginTypeForDisplayString(String displayString) {
+        return pluginForDisplay.get(displayString);
+    }
+
+    public static String getDisplayForPlugin(OpenstackNetworkPluginType 
pluginType) {
+        return EnumTranslator.createAndTranslate(pluginType);
+    }
+
+    public static String getDisplayStringForPluginName(String pluginName) {
+        try {
+            return 
EnumTranslator.createAndTranslate(OpenstackNetworkPluginType.valueOf(pluginName));
+        }
+        catch (IllegalArgumentException e) {
+            return pluginName;
+        }
+    }
+
+    public static String getPluginNameForDisplayString(String displayString) {
+        OpenstackNetworkPluginType pluginType = 
pluginForDisplay.get(displayString);
+        return (pluginType == null) ? displayString : pluginType.name();
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java
index 8bb2e15..a98c853 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java
@@ -1,14 +1,9 @@
 package org.ovirt.engine.ui.uicommonweb.models.providers;
 
 import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.ovirt.engine.core.common.action.ProviderParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
-import 
org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions;
-import 
org.ovirt.engine.core.common.businessentities.OpenstackNetworkPluginType;
 import 
org.ovirt.engine.core.common.businessentities.OpenstackNetworkProviderProperties;
 import org.ovirt.engine.core.common.businessentities.Provider;
 import org.ovirt.engine.core.common.businessentities.ProviderType;
@@ -26,14 +21,10 @@
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
 import org.ovirt.engine.ui.uicommonweb.models.SearchableListModel;
-import org.ovirt.engine.ui.uicommonweb.validation.HostAddressValidation;
 import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
-import org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation;
-import org.ovirt.engine.ui.uicommonweb.validation.InterfaceMappingsValidation;
 import org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation;
 import org.ovirt.engine.ui.uicommonweb.validation.UrlValidation;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
-import org.ovirt.engine.ui.uicompat.EnumTranslator;
 import org.ovirt.engine.ui.uicompat.Event;
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult;
@@ -53,7 +44,6 @@
     protected final SearchableListModel sourceListModel;
     private final VdcActionType action;
     protected final Provider provider;
-    private final Map<String, OpenstackNetworkPluginType> pluginForName;
 
     private EntityModel name = new EntityModel();
     private EntityModel description = new EntityModel();
@@ -68,13 +58,7 @@
     private UICommand testCommand;
     private EntityModel testResult = new EntityModel();
 
-    private EntityModel agentTabAvailable = new EntityModel();
-    private EntityModel interfaceMappingsLabel = new EntityModel();
-    private EntityModel interfaceMappings = new EntityModel();
-    private EntityModel host = new EntityModel();
-    private EntityModel qpidPort = new EntityModel();
-    private EntityModel userName = new EntityModel();
-    private EntityModel agentConfigPassword = new EntityModel();
+    private NeutronAgentBehavior neutronAgentTab;
 
     public EntityModel getName() {
         return name;
@@ -132,40 +116,12 @@
         return testResult;
     }
 
-    public EntityModel getAgentTabAvailable() {
-        return agentTabAvailable;
-    }
-
-    public EntityModel getInterfaceMappings() {
-        return interfaceMappings;
-    }
-
-    public EntityModel getInterfaceMappingsLabel() {
-        return interfaceMappingsLabel;
-    }
-
-    public EntityModel getHost() {
-        return host;
-    }
-
-    public EntityModel getQpidPort() {
-        return qpidPort;
-    }
-
-    public EntityModel getUserName() {
-        return userName;
-    }
-
-    public EntityModel getAgentConfigPassword() {
-        return agentConfigPassword;
+    public NeutronAgentBehavior getNeutronAgentTab() {
+        return neutronAgentTab;
     }
 
     public boolean isTypeOpenStackNetwork() {
         return (ProviderType) getType().getSelectedItem() == 
ProviderType.OPENSTACK_NETWORK;
-    }
-
-    public OpenstackNetworkPluginType getSelectedPlugin() {
-        return pluginForName.get(getPluginType().getSelectedItem());
     }
 
     private String getDefaultUrl(ProviderType type) {
@@ -212,54 +168,26 @@
         getType().getSelectedItemChangedEvent().addListener(new 
IEventListener() {
             @Override
             public void eventRaised(Event ev, Object sender, EventArgs args) {
-                boolean openStackNetProvider = isTypeOpenStackNetwork();
-                getPluginType().setIsAvailable(openStackNetProvider);
-                getApiVersion().setIsAvailable(openStackNetProvider);
-                getTenantName().setIsAvailable(openStackNetProvider);
-                if (!openStackNetProvider) {
-                    getAgentTabAvailable().setEntity(false);
-                } else {
+                boolean providerNeutron = isTypeOpenStackNetwork();
+                getApiVersion().setIsAvailable(providerNeutron);
+                getTenantName().setIsAvailable(providerNeutron);
+                if (providerNeutron) {
                     OpenstackNetworkProviderProperties properties =
                             (OpenstackNetworkProviderProperties) 
provider.getAdditionalProperties();
-                    String pluginString = (properties == null) ? new String() 
: properties.getPluginType();
-                    OpenstackNetworkPluginType plugin = 
pluginForName.get(pluginString);
-                    getPluginType().setSelectedItem(plugin == null ? 
pluginString
-                            : EnumTranslator.createAndTranslate(plugin));
+                    String pluginName = (properties == null) ? new String() : 
properties.getPluginType();
+                    
getPluginType().setSelectedItem(NeutronPluginTranslator.getDisplayStringForPluginName(pluginName));
                 }
             }
         });
-        getPluginType().getSelectedItemChangedEvent().addListener(new 
IEventListener() {
-            @Override
-            public void eventRaised(Event ev, Object sender, EventArgs args) {
-                OpenstackNetworkPluginType plugin = 
pluginForName.get(getPluginType().getSelectedItem());
-                getAgentTabAvailable().setEntity(plugin != null);
-                if (plugin != null) {
-                    switch(plugin) {
-                        case OPEN_VSWITCH:
-                        
getInterfaceMappingsLabel().setEntity(ConstantsManager.getInstance()
-                                .getConstants()
-                                .bridgeMappings());
-                            break;
-                        case LINUX_BRIDGE:
-                        default:
-                        
getInterfaceMappingsLabel().setEntity(ConstantsManager.getInstance()
-                                .getConstants()
-                                .interfaceMappings());
-                    }
-                }
-            }
-        });
+
+        neutronAgentTab = new NeutronAgentBehavior(getType(), getPluginType());
 
         getPluginType().setIsAvailable(false);
         getApiVersion().setIsAvailable(false);
         getTenantName().setIsAvailable(false);
 
-        pluginForName = new HashMap<String, OpenstackNetworkPluginType>();
-        for (OpenstackNetworkPluginType plugin : 
OpenstackNetworkPluginType.values()) {
-            pluginForName.put(EnumTranslator.createAndTranslate(plugin), 
plugin);
-        }
-        getPluginType().setItems(pluginForName.keySet());
         getType().setItems(Arrays.asList(ProviderType.values()));
+        
getPluginType().setItems(NeutronPluginTranslator.getPresetDisplayStrings());
         getApiVersion().setItems(Arrays.asList("v2.0")); //$NON-NLS-1$
 
         UICommand tempVar = new UICommand(CMD_SAVE, this);
@@ -282,22 +210,11 @@
         getTenantName().validateEntity(new IValidation[] { new 
NotEmptyValidation()} );
         getUrl().validateEntity(new IValidation[] { new NotEmptyValidation(),
                 new UrlValidation(Uri.SCHEME_HTTP, Uri.SCHEME_HTTPS) });
-        boolean agentTabValid = validateAgentTab();
+        getNeutronAgentTab().validate();
 
         return getName().getIsValid() && getType().getIsValid() && 
getPluginType().getIsValid()
                 && getUrl().getIsValid() && getUsername().getIsValid() && 
getPassword().getIsValid()
-                && getTenantName().getIsValid() && agentTabValid;
-    }
-
-    private boolean validateAgentTab() {
-        if ((Boolean) getAgentTabAvailable().getEntity()) {
-            getInterfaceMappings().validateEntity(new IValidation[] { new 
InterfaceMappingsValidation() });
-            getHost().validateEntity(new IValidation[] { new 
HostAddressValidation(true) });
-            getQpidPort().validateEntity(new IValidation[] { new 
IntegerValidation(BusinessEntitiesDefinitions.NETWORK_MIN_LEGAL_PORT,
-                    BusinessEntitiesDefinitions.NETWORK_MAX_LEGAL_PORT) });
-            return getInterfaceMappings().getIsValid() && 
getHost().getIsValid() && getQpidPort().getIsValid();
-        }
-        return true;
+                && getTenantName().getIsValid() && 
getNeutronAgentTab().getIsValid();
     }
 
     private void cancel() {
@@ -312,8 +229,8 @@
 
         if (isTypeOpenStackNetwork()) {
             OpenstackNetworkProviderProperties properties = new 
OpenstackNetworkProviderProperties();
-            OpenstackNetworkPluginType plugin = getSelectedPlugin();
-            properties.setPluginType(plugin == null ? (String) 
getPluginType().getEntity() : plugin.name());
+            properties.setPluginType(NeutronPluginTranslator.
+                    getPluginNameForDisplayString((String) 
getPluginType().getSelectedItem()));
             provider.setAdditionalProperties(properties);
         }
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
index 1d17328..1395779 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
@@ -186,18 +186,6 @@
     @DefaultStringValue("Network Label")
     String networkLabel();
 
-    @DefaultStringValue("Host")
-    String hostQpid();
-
-    @DefaultStringValue("Port")
-    String portQpid();
-
-    @DefaultStringValue("Username")
-    String usernameQpid();
-
-    @DefaultStringValue("Password")
-    String passwordQpid();
-
     @DefaultStringValue("Comment")
     String commentLabel();
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/provider/ProviderPopupPresenterWidget.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/provider/ProviderPopupPresenterWidget.java
index 6500e6a..a5ec9d7 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/provider/ProviderPopupPresenterWidget.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/provider/ProviderPopupPresenterWidget.java
@@ -6,6 +6,7 @@
 import org.ovirt.engine.ui.uicompat.Event;
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.IEventListener;
+import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;
 
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
@@ -17,7 +18,7 @@
     public interface ViewDef extends 
AbstractModelBoundPopupPresenterWidget.ViewDef<ProviderModel> {
         HasUiCommandClickHandlers getTestButton();
         void setTestResultImage(String errorMessage);
-        void customizeAgentTab(boolean tabAvailable, String ifMappingsLabel);
+        void setAgentTabVisibility(boolean visible);
     }
 
     @Inject
@@ -44,25 +45,15 @@
                 getView().setTestResultImage((String) 
model.getTestResult().getEntity());
             }
         });
-        model.getAgentTabAvailable().getEntityChangedEvent().addListener(new 
IEventListener() {
+        model.getNeutronAgentTab().getPropertyChangedEvent().addListener(new 
IEventListener() {
 
             @Override
             public void eventRaised(Event ev, Object sender, EventArgs args) {
-                customizeAgentTab(model);
+                if ("IsAvailable".equals(((PropertyChangedEventArgs) 
args).PropertyName)) { //$NON-NLS-1$
+                    
getView().setAgentTabVisibility(model.getNeutronAgentTab().getIsAvailable());
+                }
             }
         });
-        
model.getInterfaceMappingsLabel().getEntityChangedEvent().addListener(new 
IEventListener() {
-
-            @Override
-            public void eventRaised(Event ev, Object sender, EventArgs args) {
-                customizeAgentTab(model);
-            }
-        });
-    }
-
-    private void customizeAgentTab(ProviderModel model) {
-        getView().customizeAgentTab((Boolean) 
model.getAgentTabAvailable().getEntity(),
-                (String) model.getInterfaceMappingsLabel().getEntity());
     }
 
 }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.java
index 7147049..090014f 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.java
@@ -14,6 +14,7 @@
 import org.ovirt.engine.ui.common.widget.editor.ListModelListBoxEditor;
 import org.ovirt.engine.ui.common.widget.editor.ListModelSuggestBoxEditor;
 import org.ovirt.engine.ui.common.widget.renderer.EnumRenderer;
+import 
org.ovirt.engine.ui.common.widget.uicommon.popup.provider.NeutronAgentSection;
 import org.ovirt.engine.ui.uicommonweb.models.providers.ProviderModel;
 import org.ovirt.engine.ui.webadmin.ApplicationConstants;
 import org.ovirt.engine.ui.webadmin.ApplicationResources;
@@ -113,30 +114,9 @@
     @Ignore
     DialogTab agentConfigurationTab;
 
-    @UiField
-    @Path(value = "host.entity")
-    @WithElementId("host")
-    EntityModelTextBoxEditor host;
-
-    @UiField
-    @Path(value = "qpidPort.entity")
-    @WithElementId("qpidPort")
-    EntityModelTextBoxEditor qpidPort;
-
-    @UiField
-    @Path(value = "userName.entity")
-    @WithElementId("userName")
-    EntityModelTextBoxEditor userName;
-
-    @UiField
-    @Path(value = "agentConfigPassword.entity")
-    @WithElementId("agentConfigPassword")
-    EntityModelPasswordBoxEditor agentConfigPassword;
-
-    @UiField
-    @Path(value = "interfaceMappings.entity")
-    @WithElementId("interfaceMappings")
-    EntityModelTextBoxEditor interfaceMappings;
+    @UiField(provided = true)
+    @Ignore
+    NeutronAgentSection neutronAgentSection;
 
     @UiField
     Style style;
@@ -150,6 +130,7 @@
 
         typeEditor = new ListModelListBoxEditor<Object>(new EnumRenderer());
         requiresAuthenticationEditor = new 
EntityModelCheckBoxEditor(Align.RIGHT);
+        neutronAgentSection = new NeutronAgentSection(constants);
 
         this.resources = resources;
         this.constants = constants;
@@ -177,21 +158,18 @@
 
         // Agent configuration tab
         
agentConfigurationTab.setLabel(constants.providerPopupAgentConfigurationTabLabel());
-        host.setLabel(constants.hostQpid());
-        qpidPort.setLabel(constants.portQpid());
-        userName.setLabel(constants.usernameQpid());
-        agentConfigPassword.setLabel(constants.passwordQpid());
     }
 
     @Override
     public void edit(ProviderModel model) {
-        customizeAgentTab((Boolean) model.getAgentTabAvailable().getEntity(),
-                (String) model.getInterfaceMappingsLabel().getEntity());
+        setAgentTabVisibility(model.getNeutronAgentTab().getIsAvailable());
         driver.edit(model);
+        neutronAgentSection.edit(model.getNeutronAgentTab());
     }
 
     @Override
     public ProviderModel flush() {
+        neutronAgentSection.flush();
         return driver.flush();
     }
 
@@ -223,9 +201,8 @@
     }
 
     @Override
-    public void customizeAgentTab(boolean tabAvailable, String 
ifMappingsLabel) {
-        agentConfigurationTab.setVisible(tabAvailable);
-        interfaceMappings.setLabel(ifMappingsLabel);
+    public void setAgentTabVisibility(boolean visible) {
+        agentConfigurationTab.setVisible(visible);
     }
 
 }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.ui.xml
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.ui.xml
index cf2da90..a574255 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.ui.xml
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/provider/ProviderPopupView.ui.xml
@@ -3,7 +3,8 @@
 <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
        xmlns:g="urn:import:com.google.gwt.user.client.ui" 
xmlns:d="urn:import:org.ovirt.engine.ui.common.widget.dialog"
        xmlns:e="urn:import:org.ovirt.engine.ui.common.widget.editor" 
xmlns:w="urn:import:org.ovirt.engine.ui.common.widget"
-       xmlns:t="urn:import:org.ovirt.engine.ui.common.widget.dialog.tab">
+       xmlns:t="urn:import:org.ovirt.engine.ui.common.widget.dialog.tab"
+       
xmlns:p="urn:import:org.ovirt.engine.ui.common.widget.uicommon.popup.provider">
 
        <ui:with field='constants' 
type='org.ovirt.engine.ui.common.CommonApplicationConstants'/>
        <ui:style 
type="org.ovirt.engine.ui.webadmin.section.main.view.popup.provider.ProviderPopupView.Style">
@@ -50,22 +51,6 @@
                        vertical-align: middle;
                        margin-right: 10px;
                }
-
-        .qpidInnerPanel {
-            padding-left: 20px;
-        }
-
-        .qpidHeader {
-                       font-weight: bold;
-            margin-top: 10px;
-            margin-bottom: 10px;
-            paading-right: 6px;
-               }
-
-        .explanationLabel {
-            font-style: italic;
-            margin: 10px 5px;
-        }
        </ui:style>
 
        <d:SimpleDialogPanel width="600px" height="450px">
@@ -105,20 +90,7 @@
                 <t:tab>
                     <t:DialogTab ui:field="agentConfigurationTab">
                         <t:content>
-                                                       <g:FlowPanel>
-                                                               <g:FlowPanel>
-                                                                       
<e:EntityModelTextBoxEditor ui:field="interfaceMappings"/>
-                                                               </g:FlowPanel>
-                                                               <g:FlowPanel 
addStyleNames="{style.sectionStyle}">
-                                                                       
<g:Label text="{constants.qpid}" addStyleNames="{style.qpidHeader}"/>
-                                                                       
<g:FlowPanel addStyleNames="{style.qpidInnerPanel}">
-                                                                               
<e:EntityModelTextBoxEditor ui:field="host"/>
-                                                                               
<e:EntityModelTextBoxEditor ui:field="qpidPort"/>
-                                                                               
<e:EntityModelTextBoxEditor ui:field="userName"/>
-                                                                               
<e:EntityModelPasswordBoxEditor ui:field="agentConfigPassword"/>
-                                                                       
</g:FlowPanel>
-                                                               </g:FlowPanel>
-                            </g:FlowPanel>
+                                                       <p:NeutronAgentSection 
ui:field="neutronAgentSection" />
                         </t:content>
                     </t:DialogTab>
                 </t:tab>


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

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