Vojtech Szocs has uploaded a new change for review.

Change subject: webadmin: WiP UI plugins SystemTreeSelectionChange
......................................................................

webadmin: WiP UI plugins SystemTreeSelectionChange

Work in progress, needs more testing.

Example usage:

api.register({
  SystemTreeSelectionChange: function(selectedItem) {

    // Currently using SystemTreeItemType enum name
    // e.g. 'System', 'DataCenters', 'DataCenter', etc.
    alert(selectedItem.type);

    // Defined if there is business entity associated
    // e.g. for 'DataCenter' -> { id: '..', name:'..' }
    // See EntityObject#from for details on mapping
    alert(selectedItem.entity);

  }
});

Change-Id: Ib01721c309912526f8d7f8252e94b44e0dbfd423
Bug-Url: https://bugzilla.redhat.com/1066425
Signed-off-by: Vojtech Szocs <vsz...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
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/entity/EntityObject.java
A 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/SystemTreeItemObject.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsArrayHelper.java
A 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsMutableObjectWithProperties.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/uicommon/model/SystemTreeModelProvider.java
7 files changed, 131 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/25186/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
index 5986dda..b84391d 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.ui.common.uicommon.model;
 
+import com.google.gwt.event.shared.GwtEvent;
+import com.google.gwt.event.shared.HasHandlers;
 import 
org.ovirt.engine.ui.common.presenter.AbstractModelBoundPopupPresenterWidget;
 import org.ovirt.engine.ui.common.presenter.ModelBoundPresenterWidget;
 import 
org.ovirt.engine.ui.common.presenter.popup.DefaultConfirmationPopupPresenterWidget;
@@ -24,7 +26,7 @@
  * @param <M>
  *            Model type.
  */
-public abstract class TabModelProvider<M extends EntityModel> implements 
ModelProvider<M>, ModelBoundPopupResolver<M> {
+public abstract class TabModelProvider<M extends EntityModel> implements 
ModelProvider<M>, ModelBoundPopupResolver<M>, HasHandlers {
 
     private final EventBus eventBus;
     private final ModelBoundPopupHandler<M> popupHandler;
@@ -161,4 +163,9 @@
         return null;
     }
 
+    @Override
+    public void fireEvent(GwtEvent<?> event) {
+        getEventBus().fireEvent(event);
+    }
+
 }
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 ef7a80c..c46e924 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
@@ -7,6 +7,7 @@
 import 
org.ovirt.engine.ui.common.auth.UserLoginChangeEvent.UserLoginChangeHandler;
 import 
org.ovirt.engine.ui.webadmin.plugin.PluginManager.PluginInvocationCondition;
 import org.ovirt.engine.ui.webadmin.plugin.entity.EntityObject;
+import org.ovirt.engine.ui.webadmin.plugin.entity.SystemTreeItemObject;
 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;
@@ -41,6 +42,8 @@
 import org.ovirt.engine.ui.webadmin.system.MessageEventData;
 import org.ovirt.engine.ui.webadmin.system.MessageReceivedEvent;
 import 
org.ovirt.engine.ui.webadmin.system.MessageReceivedEvent.MessageReceivedHandler;
+import 
org.ovirt.engine.ui.webadmin.uicommon.model.SystemTreeSelectionChangeEvent;
+import 
org.ovirt.engine.ui.webadmin.uicommon.model.SystemTreeSelectionChangeEvent.SystemTreeSelectionChangeHandler;
 
 import com.google.gwt.event.shared.EventBus;
 import com.google.inject.Inject;
@@ -178,6 +181,16 @@
             }
         });
 
+        // System tree item selection change
+        eventBus.addHandler(SystemTreeSelectionChangeEvent.getType(), new 
SystemTreeSelectionChangeHandler() {
+            @Override
+            public void 
onSystemTreeSelectionChange(SystemTreeSelectionChangeEvent event) {
+                manager.invokePluginsNow("SystemTreeSelectionChange", 
//$NON-NLS-1$
+                        JsArrayHelper.createMixedArray(
+                                
SystemTreeItemObject.from(event.getSelectedItem())));
+            }
+        });
+
         // Cross-window messaging
         eventBus.addHandler(MessageReceivedEvent.getType(), new 
MessageReceivedHandler() {
             @Override
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
index 237ab6c..fd18fbe 100644
--- 
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
@@ -21,18 +21,15 @@
 
 import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.core.client.JsArray;
+import org.ovirt.engine.ui.webadmin.plugin.jsni.JsMutableObjectWithProperties;
 
 /**
  * Overlay type representing a business entity passed through plugin API as 
native JS object.
  */
-public final class EntityObject extends JavaScriptObject {
+public final class EntityObject extends JsMutableObjectWithProperties {
 
     protected EntityObject() {
     }
-
-    protected native void setProperty(String name, String value) /*-{
-        this[name] = value;
-    }-*/;
 
     protected static <T> EntityObject create(T businessEntity) {
         EntityObject obj = JavaScriptObject.createObject().cast();
@@ -43,7 +40,7 @@
         } else if (businessEntity instanceof IVdcQueryable) {
             entityId = ((IVdcQueryable) 
businessEntity).getQueryableId().toString();
         }
-        obj.setProperty("id", entityId); //$NON-NLS-1$
+        obj.setValueAsString("id", entityId); //$NON-NLS-1$
 
         return obj;
     }
@@ -55,28 +52,28 @@
 
         // DataCenter
         if (businessEntity instanceof StoragePool) {
-            obj.setProperty("name", ((StoragePool) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((StoragePool) 
businessEntity).getName()); //$NON-NLS-1$
         }
 
         // Cluster
         else if (businessEntity instanceof VDSGroup) {
-            obj.setProperty("name", ((VDSGroup) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((VDSGroup) 
businessEntity).getName()); //$NON-NLS-1$
         }
 
         // Host
         else if (businessEntity instanceof VDS) {
-            obj.setProperty("name", ((VDS) businessEntity).getName()); 
//$NON-NLS-1$
-            obj.setProperty("hostname", ((VDS) businessEntity).getHostName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((VDS) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("hostname", ((VDS) 
businessEntity).getHostName()); //$NON-NLS-1$
         }
 
         // Network
         else if (businessEntity instanceof Network) {
-            obj.setProperty("name", ((Network) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((Network) 
businessEntity).getName()); //$NON-NLS-1$
         }
 
         // Storage
         else if (businessEntity instanceof StorageDomain) {
-            obj.setProperty("name", ((StorageDomain) 
businessEntity).getStorageName()); //$NON-NLS-1$
+            obj.setValueAsString("name", ((StorageDomain) 
businessEntity).getStorageName()); //$NON-NLS-1$
         }
 
         // Disk
@@ -86,48 +83,48 @@
 
         // VirtualMachine
         else if (businessEntity instanceof VM) {
-            obj.setProperty("name", ((VM) businessEntity).getName()); 
//$NON-NLS-1$
-            obj.setProperty("ipaddress", ((VM) businessEntity).getVmIp()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((VM) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("ipaddress", ((VM) 
businessEntity).getVmIp()); //$NON-NLS-1$
         }
 
         // Pool
         else if (businessEntity instanceof VmPool) {
-            obj.setProperty("name", ((VmPool) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((VmPool) businessEntity).getName()); 
//$NON-NLS-1$
         }
 
         // Template
         else if (businessEntity instanceof VmTemplate) {
-            obj.setProperty("name", ((VmTemplate) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((VmTemplate) 
businessEntity).getName()); //$NON-NLS-1$
         }
 
         // GlusterVolume
         else if (businessEntity instanceof GlusterVolumeEntity) {
-            obj.setProperty("name", ((GlusterVolumeEntity) 
businessEntity).getName()); //$NON-NLS-1$
+            obj.setValueAsString("name", ((GlusterVolumeEntity) 
businessEntity).getName()); //$NON-NLS-1$
         }
 
         // Provider
         else if (businessEntity instanceof Provider) {
-            obj.setProperty("name", ((Provider) businessEntity).getName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((Provider) 
businessEntity).getName()); //$NON-NLS-1$
         }
 
         // User
         else if (businessEntity instanceof DbUser) {
-            obj.setProperty("username", ((DbUser) 
businessEntity).getLoginName()); //$NON-NLS-1$
-            obj.setProperty("domain", ((DbUser) businessEntity).getDomain()); 
//$NON-NLS-1$
+            obj.setValueAsString("username", ((DbUser) 
businessEntity).getLoginName()); //$NON-NLS-1$
+            obj.setValueAsString("domain", ((DbUser) 
businessEntity).getDomain()); //$NON-NLS-1$
         }
 
         // Quota
         else if (businessEntity instanceof Quota) {
-            obj.setProperty("name", ((Quota) businessEntity).getQuotaName()); 
//$NON-NLS-1$
+            obj.setValueAsString("name", ((Quota) 
businessEntity).getQuotaName()); //$NON-NLS-1$
         }
 
         // Event
         else if (businessEntity instanceof AuditLog) {
-            obj.setProperty("correlationId", ((AuditLog) 
businessEntity).getCorrelationId()); //$NON-NLS-1$
-            obj.setProperty("message", ((AuditLog) 
businessEntity).getmessage()); //$NON-NLS-1$
-            obj.setProperty("callStack", ((AuditLog) 
businessEntity).getCallStack()); //$NON-NLS-1$
-            obj.setProperty("customEventId", String.valueOf(((AuditLog) 
businessEntity).getCustomEventId())); //$NON-NLS-1$
-            obj.setProperty("toString", ((AuditLog) 
businessEntity).toStringForLogging()); //$NON-NLS-1$
+            obj.setValueAsString("correlationId", ((AuditLog) 
businessEntity).getCorrelationId()); //$NON-NLS-1$
+            obj.setValueAsString("message", ((AuditLog) 
businessEntity).getmessage()); //$NON-NLS-1$
+            obj.setValueAsString("callStack", ((AuditLog) 
businessEntity).getCallStack()); //$NON-NLS-1$
+            obj.setValueAsString("customEventId", String.valueOf(((AuditLog) 
businessEntity).getCustomEventId())); //$NON-NLS-1$
+            obj.setValueAsString("toString", ((AuditLog) 
businessEntity).toStringForLogging()); //$NON-NLS-1$
         }
 
         return obj;
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/SystemTreeItemObject.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/SystemTreeItemObject.java
new file mode 100644
index 0000000..9b42855
--- /dev/null
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/entity/SystemTreeItemObject.java
@@ -0,0 +1,29 @@
+package org.ovirt.engine.ui.webadmin.plugin.entity;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import org.ovirt.engine.ui.uicommonweb.models.SystemTreeItemModel;
+import org.ovirt.engine.ui.webadmin.plugin.jsni.JsMutableObjectWithProperties;
+
+/**
+ * Overlay type representing a system tree item passed through plugin API as 
native JS object.
+ */
+public final class SystemTreeItemObject extends JsMutableObjectWithProperties {
+
+    protected SystemTreeItemObject() {
+    }
+
+    public static SystemTreeItemObject from(SystemTreeItemModel model) {
+        SystemTreeItemObject obj = JavaScriptObject.createObject().cast();
+
+        // TODO(vszocs) currently using SystemTreeItemType enum name
+        obj.setValueAsString("type", model.getType().name()); //$NON-NLS-1$
+
+        Object entity = model.getEntity();
+        if (entity != null) {
+            obj.setValueAsJavaScriptObject("entity", 
EntityObject.from(entity)); //$NON-NLS-1$
+        }
+
+        return obj;
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsArrayHelper.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsArrayHelper.java
index a3d45d6..1f028c0 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsArrayHelper.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsArrayHelper.java
@@ -28,9 +28,9 @@
      * Supported value types:
      * <ul>
      * <li>{@link JavaScriptObject}, maps to native JS object
-     * <li>String, maps to {@code string}
-     * <li>Double, maps to {@code number}
-     * <li>Boolean, maps to {@code boolean}
+     * <li>String, maps to JS {@code string}
+     * <li>Double, maps to JS {@code number}
+     * <li>Boolean, maps to JS {@code boolean}
      * </ul>
      */
     public static JsArray<JavaScriptObject> createMixedArray(Object... values) 
{
@@ -57,11 +57,11 @@
     }-*/;
 
     private static native void pushNumber(JavaScriptObject arrayObj, Double 
value) /*-{
-        arrayObj[arrayObj.length] = value;
+        arrayObj[arrayObj.length] = val...@java.lang.Double::doubleValue()();
     }-*/;
 
     private static native void pushBoolean(JavaScriptObject arrayObj, Boolean 
value) /*-{
-        arrayObj[arrayObj.length] = value;
+        arrayObj[arrayObj.length] = val...@java.lang.Boolean::booleanValue()();
     }-*/;
 
     /**
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsMutableObjectWithProperties.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsMutableObjectWithProperties.java
new file mode 100644
index 0000000..e356139
--- /dev/null
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/plugin/jsni/JsMutableObjectWithProperties.java
@@ -0,0 +1,41 @@
+package org.ovirt.engine.ui.webadmin.plugin.jsni;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * Extension of {@link JsObjectWithProperties} that allows setting typed 
properties.
+ */
+public abstract class JsMutableObjectWithProperties extends 
JsObjectWithProperties {
+
+    protected JsMutableObjectWithProperties() {
+    }
+
+    /**
+     * Sets the value for the given key as native JS object.
+     */
+    protected final native void setValueAsJavaScriptObject(String key, 
JavaScriptObject value) /*-{
+        this[key] = value;
+    }-*/;
+
+    /**
+     * Sets the value for the given key as String (maps to JS {@code string}).
+     */
+    protected final native void setValueAsString(String key, String value) /*-{
+        this[key] = value;
+    }-*/;
+
+    /**
+     * Sets the value for the given key as Double (maps to JS {@code number}).
+     */
+    protected final native void setValueAsDouble(String key, Double value) /*-{
+        this[key] = val...@java.lang.Double::doubleValue()();
+    }-*/;
+
+    /**
+     * Sets the value for the given key as Boolean (maps to JS {@code 
boolean}).
+     */
+    protected final native void setValueAsBoolean(String key, Boolean value) 
/*-{
+        this[key] = val...@java.lang.Boolean::booleanValue()();
+    }-*/;
+
+}
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/uicommon/model/SystemTreeModelProvider.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/uicommon/model/SystemTreeModelProvider.java
index b69f6dd..4a6e6f9 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/uicommon/model/SystemTreeModelProvider.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/uicommon/model/SystemTreeModelProvider.java
@@ -4,6 +4,7 @@
 import java.util.Arrays;
 import java.util.List;
 
+import com.gwtplatform.dispatch.annotation.GenEvent;
 import org.ovirt.engine.core.compat.Guid;
 import 
org.ovirt.engine.ui.common.presenter.popup.DefaultConfirmationPopupPresenterWidget;
 import org.ovirt.engine.ui.common.uicommon.model.DataBoundTabModelProvider;
@@ -32,6 +33,13 @@
 
 public class SystemTreeModelProvider extends 
DataBoundTabModelProvider<SystemTreeItemModel, SystemTreeModel>
         implements SearchableTreeModelProvider<SystemTreeItemModel, 
SystemTreeModel>, TreeModelWithElementId {
+
+    @GenEvent
+    public class SystemTreeSelectionChange {
+
+        SystemTreeItemModel selectedItem;
+
+    }
 
     private final DefaultSelectionEventManager<SystemTreeItemModel> 
selectionManager =
             DefaultSelectionEventManager.createDefaultManager();
@@ -108,6 +116,10 @@
     @Override
     public void setSelectedItems(List<SystemTreeItemModel> items) {
         getModel().setSelectedItem(items.size() > 0 ? items.get(0) : null);
+
+        if (items.size() > 0) {
+            SystemTreeSelectionChangeEvent.fire(this, items.get(0));
+        }
     }
 
     @Override


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

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