Vojtech Szocs has uploaded a new change for review.

Change subject: webadmin: Provide entity specific properties to UI plugins
......................................................................

webadmin: Provide entity specific properties to UI plugins

Before this patch, UI plugins would receive following base
entity object representation (same for all entity types):

  { 'entityId': '[BusinessEntityGuidAsString]' }

After this patch, UI plugins will receive the same as above
('entityId' renamed to 'id'), plus some additional entity
specific properties:

  'name' for Cluster, DataCenter, Host, Storage, Template,
  VirtualMachine

More properties can be added later on, as necessary. Note
that this is just a temporary solution, as we plan to use
generated Engine REST API types on the frontend side.

Change-Id: I937640bdddc8b888f517323d0be6b18796e81a05
Signed-off-by: Vojtech Szocs <vsz...@redhat.com>
---
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/PluginEventHandler.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/api/PluginUiFunctions.java
D 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/BaseEntity.java
A 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/EntityObject.java
4 files changed, 104 insertions(+), 54 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/58/10158/1

diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/PluginEventHandler.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/PluginEventHandler.java
index d6f5755..06301d3 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/PluginEventHandler.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/PluginEventHandler.java
@@ -3,7 +3,7 @@
 import org.ovirt.engine.ui.common.auth.CurrentUser;
 import org.ovirt.engine.ui.common.auth.UserLoginChangeEvent;
 import 
org.ovirt.engine.ui.common.auth.UserLoginChangeEvent.UserLoginChangeHandler;
-import org.ovirt.engine.ui.webadmin.plugin.entity.BaseEntity;
+import org.ovirt.engine.ui.webadmin.plugin.entity.EntityObject;
 import org.ovirt.engine.ui.webadmin.plugin.jsni.JsArrayHelper;
 import org.ovirt.engine.ui.webadmin.plugin.restapi.RestApiSessionAcquiredEvent;
 import 
org.ovirt.engine.ui.webadmin.plugin.restapi.RestApiSessionAcquiredEvent.RestApiSessionAcquiredHandler;
@@ -62,43 +62,43 @@
         eventBus.addHandler(ClusterSelectionChangeEvent.getType(), new 
ClusterSelectionChangeHandler() {
             @Override
             public void onClusterSelectionChange(ClusterSelectionChangeEvent 
event) {
-                manager.invokePluginsNow("ClusterSelectionChange", 
BaseEntity.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
+                manager.invokePluginsNow("ClusterSelectionChange", 
EntityObject.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
             }
         });
         eventBus.addHandler(DataCenterSelectionChangeEvent.getType(), new 
DataCenterSelectionChangeHandler() {
             @Override
             public void 
onDataCenterSelectionChange(DataCenterSelectionChangeEvent event) {
-                manager.invokePluginsNow("DataCenterSelectionChange", 
BaseEntity.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
+                manager.invokePluginsNow("DataCenterSelectionChange", 
EntityObject.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
             }
         });
         eventBus.addHandler(DiskSelectionChangeEvent.getType(), new 
DiskSelectionChangeHandler() {
             @Override
             public void onDiskSelectionChange(DiskSelectionChangeEvent event) {
-                manager.invokePluginsNow("DiskSelectionChange", 
BaseEntity.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
+                manager.invokePluginsNow("DiskSelectionChange", 
EntityObject.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
             }
         });
         eventBus.addHandler(HostSelectionChangeEvent.getType(), new 
HostSelectionChangeHandler() {
             @Override
             public void onHostSelectionChange(HostSelectionChangeEvent event) {
-                manager.invokePluginsNow("HostSelectionChange", 
BaseEntity.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
+                manager.invokePluginsNow("HostSelectionChange", 
EntityObject.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
             }
         });
         eventBus.addHandler(StorageSelectionChangeEvent.getType(), new 
StorageSelectionChangeHandler() {
             @Override
             public void onStorageSelectionChange(StorageSelectionChangeEvent 
event) {
-                manager.invokePluginsNow("StorageSelectionChange", 
BaseEntity.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
+                manager.invokePluginsNow("StorageSelectionChange", 
EntityObject.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
             }
         });
         eventBus.addHandler(TemplateSelectionChangeEvent.getType(), new 
TemplateSelectionChangeHandler() {
             @Override
             public void onTemplateSelectionChange(TemplateSelectionChangeEvent 
event) {
-                manager.invokePluginsNow("TemplateSelectionChange", 
BaseEntity.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
+                manager.invokePluginsNow("TemplateSelectionChange", 
EntityObject.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
             }
         });
         eventBus.addHandler(VirtualMachineSelectionChangeEvent.getType(), new 
VirtualMachineSelectionChangeHandler() {
             @Override
             public void 
onVirtualMachineSelectionChange(VirtualMachineSelectionChangeEvent event) {
-                manager.invokePluginsNow("VirtualMachineSelectionChange", 
BaseEntity.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
+                manager.invokePluginsNow("VirtualMachineSelectionChange", 
EntityObject.arrayFrom(event.getSelectedItems())); //$NON-NLS-1$
             }
         });
     }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/api/PluginUiFunctions.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/api/PluginUiFunctions.java
index d42c5bf..8ceb183 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/api/PluginUiFunctions.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/api/PluginUiFunctions.java
@@ -10,7 +10,7 @@
 import org.ovirt.engine.ui.common.widget.table.HasActionTable;
 import org.ovirt.engine.ui.uicommonweb.BaseCommandTarget;
 import org.ovirt.engine.ui.uicommonweb.UICommand;
-import org.ovirt.engine.ui.webadmin.plugin.entity.BaseEntity;
+import org.ovirt.engine.ui.webadmin.plugin.entity.EntityObject;
 import org.ovirt.engine.ui.webadmin.plugin.entity.EntityType;
 import org.ovirt.engine.ui.webadmin.plugin.jsni.JsFunctionResultHelper;
 import 
org.ovirt.engine.ui.webadmin.section.main.presenter.DynamicUrlContentTabProxyFactory;
@@ -217,7 +217,7 @@
         final UICommand command = new UICommand(label, new BaseCommandTarget() 
{
             @Override
             public void ExecuteCommand(UICommand uiCommand) {
-                
actionButtonInterface.onClick().invoke(BaseEntity.arrayFrom(table.getSelectedItems()),
 null);
+                
actionButtonInterface.onClick().invoke(EntityObject.arrayFrom(table.getSelectedItems()),
 null);
             }
         });
 
@@ -242,13 +242,13 @@
         // Update 'IsExecutionAllowed' property
         boolean isEnabled = true;
         isEnabled = 
JsFunctionResultHelper.invokeAndGetResultAsBoolean(actionButtonInterface.isEnabled(),
-                BaseEntity.arrayFrom(selectedItems), null, isEnabled);
+                EntityObject.arrayFrom(selectedItems), null, isEnabled);
         command.setIsExecutionAllowed(isEnabled);
 
         // Update 'IsAvailable' property
         boolean isAccessible = true;
         isAccessible = 
JsFunctionResultHelper.invokeAndGetResultAsBoolean(actionButtonInterface.isAccessible(),
-                BaseEntity.arrayFrom(selectedItems), null, isAccessible);
+                EntityObject.arrayFrom(selectedItems), null, isAccessible);
         command.setIsAvailable(isAccessible);
     }
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/BaseEntity.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/BaseEntity.java
deleted file mode 100644
index 788a19a..0000000
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/BaseEntity.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.ovirt.engine.ui.webadmin.plugin.entity;
-
-import java.util.List;
-
-import org.ovirt.engine.core.common.businessentities.BusinessEntity;
-import org.ovirt.engine.core.compat.NGuid;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.core.client.JsArray;
-
-/**
- * Overlay type representing an entity passed through the plugin API as native 
JS object.
- */
-// TODO(vszocs) use restapi-types to map backend business entity types
-// into restapi-definition types, and export these types for use with
-// JavaScript (plugin API)
-public class BaseEntity extends JavaScriptObject {
-
-    protected BaseEntity() {
-    }
-
-    /**
-     * Returns JSON-like representation of the given business entity:
-     * <pre>
-     * { entityId: "[BusinessEntityGuidAsString]" }
-     * </pre>
-     */
-    public static native BaseEntity from(BusinessEntity<? extends NGuid> 
businessEntity) /*-{
-        var guid = 
businessenti...@org.ovirt.engine.core.common.businessentities.BusinessEntity::getId()();
-        var guidAsString = 
gu...@org.ovirt.engine.core.compat.NGuid::toString()();
-        return { entityId: guidAsString };
-    }-*/;
-
-    public static <T extends BusinessEntity<? extends NGuid>> 
JsArray<BaseEntity> arrayFrom(List<T> businessEntityList) {
-        JsArray<BaseEntity> result = JavaScriptObject.createArray().cast();
-        for (T businessEntity : businessEntityList) {
-            result.push(BaseEntity.from(businessEntity));
-        }
-        return result;
-    }
-
-}
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/EntityObject.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/EntityObject.java
new file mode 100644
index 0000000..df12a5b
--- /dev/null
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/EntityObject.java
@@ -0,0 +1,92 @@
+package org.ovirt.engine.ui.webadmin.plugin.entity;
+
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.BusinessEntity;
+import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSGroup;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
+import org.ovirt.engine.core.common.businessentities.storage_domains;
+import org.ovirt.engine.core.common.businessentities.storage_pool;
+import org.ovirt.engine.core.compat.NGuid;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+/**
+ * Overlay type representing an entity passed through the plugin API as native 
JS object.
+ */
+public class EntityObject extends JavaScriptObject {
+
+    protected EntityObject() {
+    }
+
+    /**
+     * Creates new entity object using following representation:
+     * <pre>
+     * { id: "[BusinessEntityGuidAsString]" }
+     * </pre>
+     * Note that additional properties can be {@linkplain #setProperty set} 
for specific entity types.
+     */
+    protected static native EntityObject create(BusinessEntity<? extends 
NGuid> businessEntity) /*-{
+        var guid = 
businessenti...@org.ovirt.engine.core.common.businessentities.BusinessEntity::getId()();
+        var guidAsString = 
gu...@org.ovirt.engine.core.compat.NGuid::toString()();
+        return { id: guidAsString };
+    }-*/;
+
+    protected native void setProperty(String name, String value) /*-{
+        this[name] = value;
+    }-*/;
+
+    public static EntityObject from(BusinessEntity<? extends NGuid> 
businessEntity) {
+        EntityObject obj = create(businessEntity);
+
+        // Cluster
+        if (businessEntity instanceof VDSGroup) {
+            obj.setProperty("name", ((VDSGroup) businessEntity).getname()); 
//$NON-NLS-1$
+        }
+
+        // DataCenter
+        else if (businessEntity instanceof storage_pool) {
+            obj.setProperty("name", ((storage_pool) 
businessEntity).getname()); //$NON-NLS-1$
+        }
+
+        // Disk
+        else if (businessEntity instanceof Disk) {
+            // No custom properties for now
+        }
+
+        // Host
+        else if (businessEntity instanceof VDS) {
+            obj.setProperty("name", ((VDS) businessEntity).gethost_name()); 
//$NON-NLS-1$
+        }
+
+        // Storage
+        else if (businessEntity instanceof storage_domains) {
+            obj.setProperty("name", ((storage_domains) 
businessEntity).getstorage_name()); //$NON-NLS-1$
+        }
+
+        // Template
+        else if (businessEntity instanceof VmTemplate) {
+            obj.setProperty("name", ((VmTemplate) businessEntity).getname()); 
//$NON-NLS-1$
+        }
+
+        // VirtualMachine
+        else if (businessEntity instanceof VM) {
+            obj.setProperty("name", ((VM) businessEntity).getVmName()); 
//$NON-NLS-1$
+        }
+
+        return obj;
+    }
+
+    public static <T extends BusinessEntity<? extends NGuid>> 
JsArray<EntityObject> arrayFrom(List<T> businessEntityList) {
+        JsArray<EntityObject> result = JavaScriptObject.createArray().cast();
+        for (T businessEntity : businessEntityList) {
+            result.push(EntityObject.from(businessEntity));
+        }
+        return result;
+    }
+
+}


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

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

Reply via email to