new extension point: custom image providers for network maps
authorVictor Kirhenshtein <victor@netxms.org>
Sun, 17 Mar 2013 20:06:01 +0000 (20:06 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Sun, 17 Mar 2013 20:06:01 +0000 (20:06 +0000)
.gitattributes
src/java/netxms-eclipse/NetworkMaps/META-INF/MANIFEST.MF
src/java/netxms-eclipse/NetworkMaps/plugin.xml
src/java/netxms-eclipse/NetworkMaps/schema/org.netxms.ui.eclipse.networkmaps.imageproviders.exsd [new file with mode: 0644]
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/Activator.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/MapImageProvidersManager.java [new file with mode: 0644]
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/api/NetworkMapImageProvider.java [new file with mode: 0644]
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/MapLabelProvider.java

index 83cf390..6ed822f 100644 (file)
@@ -1479,6 +1479,7 @@ src/java/netxms-eclipse/NetworkMaps/icons/service_components.gif -text
 src/java/netxms-eclipse/NetworkMaps/icons/service_deps.gif -text
 src/java/netxms-eclipse/NetworkMaps/icons/snap_to_grid.png -text
 src/java/netxms-eclipse/NetworkMaps/plugin.xml -text
+src/java/netxms-eclipse/NetworkMaps/schema/org.netxms.ui.eclipse.networkmaps.imageproviders.exsd -text
 src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/Activator.java -text
 src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/NetworkMapOpenHandler.java -text
 src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/actions/CreateMapGroup.java -text
index 0aadb6f..55b22b7 100644 (file)
@@ -19,4 +19,5 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Export-Package: org.netxms.ui.eclipse.networkmaps.algorithms,
+ org.netxms.ui.eclipse.networkmaps.api,
  org.netxms.ui.eclipse.networkmaps.widgets
index 652309f..ed5c5ab 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <?eclipse version="3.2"?>\r
 <plugin>\r
+   <extension-point id="org.netxms.ui.eclipse.networkmaps.imageproviders" name="Network Map Image Providers" schema="schema/org.netxms.ui.eclipse.networkmaps.imageproviders.exsd"/>\r
 \r
    <extension\r
          point="org.eclipse.ui.views">\r
diff --git a/src/java/netxms-eclipse/NetworkMaps/schema/org.netxms.ui.eclipse.networkmaps.imageproviders.exsd b/src/java/netxms-eclipse/NetworkMaps/schema/org.netxms.ui.eclipse.networkmaps.imageproviders.exsd
new file mode 100644 (file)
index 0000000..004aeb4
--- /dev/null
@@ -0,0 +1,117 @@
+<?xml version='1.0' encoding='UTF-8'?>\r
+<!-- Schema file written by PDE -->\r
+<schema targetNamespace="org.netxms.ui.eclipse.networkmaps" xmlns="http://www.w3.org/2001/XMLSchema">\r
+<annotation>\r
+      <appInfo>\r
+         <meta.schema plugin="org.netxms.ui.eclipse.networkmaps" id="org.netxms.ui.eclipse.networkmaps.imageproviders" name="Network Map Image Providers"/>\r
+      </appInfo>\r
+      <documentation>\r
+         Extension point for registering custom network map image providers.\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <element name="extension">\r
+      <annotation>\r
+         <appInfo>\r
+            <meta.element />\r
+         </appInfo>\r
+      </annotation>\r
+      <complexType>\r
+         <sequence minOccurs="1" maxOccurs="unbounded">\r
+            <element ref="provider"/>\r
+         </sequence>\r
+         <attribute name="point" type="string" use="required">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+            </annotation>\r
+         </attribute>\r
+         <attribute name="id" type="string">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+            </annotation>\r
+         </attribute>\r
+         <attribute name="name" type="string">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+               <appInfo>\r
+                  <meta.attribute translatable="true"/>\r
+               </appInfo>\r
+            </annotation>\r
+         </attribute>\r
+      </complexType>\r
+   </element>\r
+\r
+   <element name="provider">\r
+      <complexType>\r
+         <attribute name="class" type="string" use="required">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+               <appInfo>\r
+                  <meta.attribute kind="java" basedOn=":org.netxms.ui.eclipse.networkmaps.api.NetworkMapImageProvider"/>\r
+               </appInfo>\r
+            </annotation>\r
+         </attribute>\r
+         <attribute name="priority" type="string">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+            </annotation>\r
+         </attribute>\r
+      </complexType>\r
+   </element>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="since"/>\r
+      </appInfo>\r
+      <documentation>\r
+         1.2.7\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="examples"/>\r
+      </appInfo>\r
+      <documentation>\r
+         [Enter extension point usage example here.]\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="apiinfo"/>\r
+      </appInfo>\r
+      <documentation>\r
+         [Enter API information here.]\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="implementation"/>\r
+      </appInfo>\r
+      <documentation>\r
+         [Enter information about supplied implementation of this extension point.]\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="copyright"/>\r
+      </appInfo>\r
+      <documentation>\r
+         Copyright (c) 2003-2013 Raden Solutions\r
+      </documentation>\r
+   </annotation>\r
+\r
+</schema>\r
index 052cefb..6908e90 100644 (file)
@@ -33,6 +33,8 @@ public class Activator extends AbstractUIPlugin
           ps.setDefault("NetMap.ShowStatusIcon", true);\r
           ps.setDefault("NetMap.ShowStatusFrame", false);\r
           ps.setDefault("NetMap.ShowStatusBackground", false);\r
+          \r
+          MapImageProvidersManager.create();\r
        }\r
 \r
        /*\r
diff --git a/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/MapImageProvidersManager.java b/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/MapImageProvidersManager.java
new file mode 100644 (file)
index 0000000..6a105a4
--- /dev/null
@@ -0,0 +1,112 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2013 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.ui.eclipse.networkmaps;
+
+import java.util.Map;
+import java.util.TreeMap;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.graphics.Image;
+import org.netxms.client.objects.GenericObject;
+import org.netxms.ui.eclipse.networkmaps.api.NetworkMapImageProvider;
+
+/**
+ * Manager of network map image providers. There should be only one instance of it,
+ * created early during console startup.
+ */
+public class MapImageProvidersManager
+{
+       private static MapImageProvidersManager instance = null;
+       
+       /**
+        * Get color manager instance.
+        * 
+        * @return
+        */
+       public static MapImageProvidersManager getInstance()
+       {
+               return instance;
+       }
+       
+       /**
+        * Create color manager instance
+        */
+       protected static void create()
+       {
+               if (instance == null)
+                       instance = new MapImageProvidersManager();
+       }
+       
+       private Map<Integer, NetworkMapImageProvider> providers = new TreeMap<Integer, NetworkMapImageProvider>();
+       
+       /**
+        * Constructor
+        */
+       private MapImageProvidersManager()
+       {
+               // Read all registered extensions and create image providers
+               final IExtensionRegistry reg = Platform.getExtensionRegistry();
+               IConfigurationElement[] elements = reg.getConfigurationElementsFor("org.netxms.ui.eclipse.networkmaps.imageproviders"); //$NON-NLS-1$
+               for(int i = 0; i < elements.length; i++)
+               {
+                       try
+                       {
+                               final NetworkMapImageProvider p = (NetworkMapImageProvider)elements[i].createExecutableExtension("class"); //$NON-NLS-1$
+                               int priority = 65535;
+                               String value = elements[i].getAttribute("priority"); //$NON-NLS-1$
+                               if (value != null)
+                               {
+                                       try
+                                       {
+                                               priority = Integer.parseInt(value);
+                                               if (priority < 0)
+                                                       priority = 65535;
+                                       }
+                                       catch(NumberFormatException e)
+                                       {
+                                       }
+                               }
+                               providers.put(priority, p);
+                       }
+                       catch(CoreException e)
+                       {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+               }
+       }
+       
+       /**
+        * Get image for object.
+        * 
+        * @return image for given object or null.
+        */
+       public Image getMapImage(GenericObject object)
+       {
+               for(NetworkMapImageProvider p : providers.values())
+               {
+                       Image i = p.getMapImage(object);
+                       if (i != null)
+                               return i;
+               }
+               return null;
+       }
+}
diff --git a/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/api/NetworkMapImageProvider.java b/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/api/NetworkMapImageProvider.java
new file mode 100644 (file)
index 0000000..1facd91
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2013 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.ui.eclipse.networkmaps.api;
+
+import org.eclipse.swt.graphics.Image;
+import org.netxms.client.objects.GenericObject;
+
+/**
+ * Interface for network map custom image providers
+ */
+public interface NetworkMapImageProvider
+{
+       /**
+        * Get map image for given NetXMS object.
+        *  
+        * @param object NetXMS object
+        * @return image for given object or null to continue search
+        */
+       public Image getMapImage(GenericObject object);
+}
index 5701c66..6b3abdd 100644 (file)
@@ -1,6 +1,6 @@
 /**\r
  * NetXMS - open source network management system\r
- * Copyright (C) 2003-2010 Victor Kirhenshtein\r
+ * Copyright (C) 2003-2013 Victor Kirhenshtein\r
  *\r
  * This program is free software; you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
@@ -60,6 +60,7 @@ import org.netxms.client.objects.UnknownObject;
 import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;\r
 import org.netxms.ui.eclipse.imagelibrary.shared.ImageProvider;\r
 import org.netxms.ui.eclipse.networkmaps.Activator;\r
+import org.netxms.ui.eclipse.networkmaps.MapImageProvidersManager;\r
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;\r
 import org.netxms.ui.eclipse.tools.ColorCache;\r
 import org.netxms.ui.eclipse.tools.ColorConverter;\r
@@ -171,12 +172,19 @@ public class MapLabelProvider extends LabelProvider implements IFigureProvider,
                        GenericObject object = session.findObjectById(((NetworkMapObject)element).getObjectId());\r
                        if (object != null)\r
                        {\r
+                               // First, check if object has custom map image set\r
                                final UUID objectImageGuid = object.getImage();\r
                                if (objectImageGuid != null && !objectImageGuid.equals(NXCommon.EMPTY_GUID))\r
                                {\r
                                        return ImageProvider.getInstance().getImage(objectImageGuid);\r
                                }\r
+                               \r
+                               // Try registered network map image providers\r
+                               Image img = MapImageProvidersManager.getInstance().getMapImage(object);\r
+                               if (img != null)\r
+                                       return img;\r
 \r
+                               // Use built-in image as last resort\r
                                switch(object.getObjectClass())\r
                                {\r
                                        case GenericObject.OBJECT_NODE:\r
@@ -212,7 +220,7 @@ public class MapLabelProvider extends LabelProvider implements IFigureProvider,
                {\r
                        return imgResCluster;\r
                }\r
-               return imgUnknown;\r
+               return null;\r
        }\r
 \r
        /*\r