Added functionality to open network map link dcis on double click. Fixes #NX-1166
authorEriks Jenkevics <eriks@netxms.org>
Fri, 9 Jun 2017 07:44:09 +0000 (10:44 +0300)
committerEriks Jenkevics <eriks@netxms.org>
Fri, 9 Jun 2017 12:12:58 +0000 (15:12 +0300)
12 files changed:
include/netxms-version.h
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/client/netxms-client/src/main/java/org/netxms/client/ProtocolVersion.java
src/java/client/netxms-client/src/main/java/org/netxms/client/datacollection/DciValue.java
src/java/client/netxms-client/src/main/java/org/netxms/client/datacollection/SimpleDciValue.java
src/java/client/netxms-client/src/main/java/org/netxms/client/maps/configs/SingleDciConfig.java
src/java/netxms-eclipse/NetworkMaps/META-INF/MANIFEST.MF
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/AbstractNetworkMapView.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/LinkDciValueProvider.java
src/server/core/session.cpp
webui/webapp/NetworkMaps/META-INF/MANIFEST.MF
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/AbstractNetworkMapView.java

index cf42304..fded15b 100644 (file)
@@ -48,7 +48,7 @@
 #define CLIENT_PROTOCOL_VERSION_PUSH      1     /* Data push API */
 #define CLIENT_PROTOCOL_VERSION_TRAP      1     /* Event (trap) sending API */
 #define CLIENT_PROTOCOL_VERSION_MOBILE    1     /* All functionality relevant for mobile client */
-#define CLIENT_PROTOCOL_VERSION_FULL      10     /* All functionality */
+#define CLIENT_PROTOCOL_VERSION_FULL      11     /* All functionality */
 
 /**
  * Protocol version positions
index 59b9b46..c468c35 100644 (file)
@@ -107,6 +107,7 @@ import org.netxms.client.log.Log;
 import org.netxms.client.maps.MapDCIInstance;
 import org.netxms.client.maps.NetworkMapLink;
 import org.netxms.client.maps.NetworkMapPage;
+import org.netxms.client.maps.configs.SingleDciConfig;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
 import org.netxms.client.market.Repository;
@@ -3842,34 +3843,68 @@ public class NXCSession
    }
    
    /**
-    * Get last DCI values for given DCI id list(list can contain simple DCIss and table DCIs) 
+    * Get last DCI values for given Map DCI Instance list
     *
-    * @param dciIDList            List with all required data to get last DCI id
+    * @param dciIDList List with Map DCI Instances
     * @return List of DCI values
     * @throws IOException  if socket I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public DciValue[] getLastValues(Set<MapDCIInstance> dciIDList) throws IOException, NXCException
+   public DciValue[] getLastValues(Set<MapDCIInstance> mapDcis) throws IOException, NXCException
    {
       final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_DCI_VALUES);
-      msg.setFieldInt32(NXCPCodes.VID_NUM_ITEMS, dciIDList.size());
-      long base = NXCPCodes.VID_DCI_ID_LIST_BASE;
-      for(MapDCIInstance item : dciIDList)
+      long base = NXCPCodes.VID_DCI_VALUES_BASE;
+      msg.setFieldInt32(NXCPCodes.VID_NUM_ITEMS, mapDcis.size());
+      for(MapDCIInstance item : mapDcis)
       {
          item.fillMessage(msg, base);
-         base +=10;
+         base += 10;
       }
 
-      sendMessage(msg);
+      return sendLastValuesMsg(msg);
+   }
+   
+   /**
+    * Get last DCI values for given Single Dci Config list
+    *
+    * @param dciIDList List with Single Dci Configs
+    * @return List of DCI values
+    * @throws IOException  if socket I/O error occurs
+    * @throws NXCException if NetXMS server returns an error or operation was timed out
+    */
+   public DciValue[] getLastValues(List<SingleDciConfig> dciConfig) throws IOException, NXCException
+   {
+      final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_DCI_VALUES);
+      long base = NXCPCodes.VID_DCI_VALUES_BASE;
+      msg.setFieldInt32(NXCPCodes.VID_NUM_ITEMS, dciConfig.size());
+      for(SingleDciConfig c : dciConfig)
+      {
+         c.fillMessage(msg, base);
+         base += 10;
+      }
 
+      return sendLastValuesMsg(msg);
+   }
+   
+   /**
+    * Send msg containing list of dci configurations
+    * 
+    * @param msg
+    * @return
+    * @throws NXCException 
+    * @throws IOException 
+    */
+   public DciValue[] sendLastValuesMsg(NXCPMessage msg) throws IOException, NXCException
+   {
+      sendMessage(msg);
       final NXCPMessage response = waitForRCC(msg.getMessageId());
 
       int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ITEMS);
       DciValue[] list = new DciValue[count];
-      base = NXCPCodes.VID_DCI_ID_LIST_BASE;
+      long base = NXCPCodes.VID_DCI_VALUES_BASE;
       for(int i = 0; i < count; i++, base += 10)
       {
-         list[i] = (DciValue)new SimpleDciValue(response.getFieldAsInt64(base), response.getFieldAsString(base+1), response.getFieldAsInt32(base+2), response.getFieldAsInt32(base+3));
+         list[i] = (DciValue)new SimpleDciValue(response, base);
       }
 
       return list;
index ca24210..16a188f 100644 (file)
@@ -33,7 +33,7 @@ public final class ProtocolVersion
    public static final int PUSH = 1;
    public static final int TRAP = 1;
    public static final int MOBILE = 1;
-   public static final int FULL = 10;
+   public static final int FULL = 11;
    
    // Indexes
    public static final int INDEX_BASE = 0;
index 2279498..7b6d8bc 100644 (file)
@@ -27,15 +27,15 @@ import org.netxms.client.constants.Severity;
  */
 public abstract class DciValue
 {
-       private long id;                                        // DCI id
-       private long nodeId;                            // related node object id
+       protected long id;                                      // DCI id
+       protected long nodeId;                          // related node object id
        private long templateDciId;     // related template DCI ID
-       private String name;                            // name
-       private String description;     // description
-       private String value;                   // value
-       private int source;                             // data source (agent, SNMP, etc.)
-       private int dataType;
-       private int status;                             // status (active, disabled, etc.)
+       protected String name;                          // name
+       protected String description;   // description
+       protected String value;                 // value
+       protected int source;                           // data source (agent, SNMP, etc.)
+       protected int dataType;
+       protected int status;                           // status (active, disabled, etc.)
        private int errorCount;
        private int dcObjectType;               // Data collection object type (item, table, etc.)
        private Date timestamp;
@@ -64,6 +64,13 @@ public abstract class DciValue
        }
        
        /**
+        * Simple constructor for DciValue
+        */
+       protected DciValue()
+   {
+   }
+       
+       /**
         * Constructor for creating DciValue from NXCP message
         * 
         * @param nodeId owning node ID
@@ -92,22 +99,6 @@ public abstract class DciValue
                        activeThreshold = null;
        }
        
-       /**
-        * Constructor for creating DCIValue from last values message
-        * 
-        * @param id
-        * @param value
-        * @param dataType
-        * @param status
-        */
-       public DciValue(long id, String value, int dataType, int status)
-       {
-          this.id = id;
-          this.value = value;
-          this.dataType = dataType;
-          this.status = status;
-       }
-       
    /**
         * Returns formated DCI value or string with format error and correct type of DCI value;
         * 
index bbcfcb0..de42d6c 100644 (file)
@@ -41,8 +41,16 @@ public class SimpleDciValue extends DciValue
     * @param dataType type
     * @param status DCI status
     */
-   public SimpleDciValue(long id, String value, int dataType, int status)
+   public SimpleDciValue(NXCPMessage msg, long base)
    {
-      super(id, value, dataType, status);
+      super();
+      this.id = msg.getFieldAsInt64(base + 1);
+      this.value = msg.getFieldAsString(base + 2);
+      this.dataType = msg.getFieldAsInt32(base + 3);
+      this.status = msg.getFieldAsInt32(base + 4);
+      this.nodeId = msg.getFieldAsInt64(base + 5);
+      this.source = msg.getFieldAsInt32(base + 6);
+      this.name = msg.getFieldAsString(base + 7);
+      this.description = msg.getFieldAsString(base + 8);
    }
 }
index 12374a6..295f920 100644 (file)
@@ -18,6 +18,8 @@
  */
 package org.netxms.client.maps.configs;
 
+import org.netxms.base.NXCPMessage;
+import org.netxms.client.datacollection.DataCollectionItem;
 import org.netxms.client.datacollection.DataCollectionObject;
 import org.netxms.client.datacollection.DciValue;
 import org.simpleframework.xml.Attribute;
@@ -102,6 +104,27 @@ public class SingleDciConfig
        }
        
        /**
+        * Fill NXCPMessage with object data
+        * 
+        * @param msg
+        * @param base
+        */
+       public void fillMessage(NXCPMessage msg, long base)
+       {
+          if (type == DataCollectionItem.DCO_TYPE_TABLE && (column.isEmpty() || instance.isEmpty()))
+          {
+             return;
+          }
+          msg.setFieldInt32(base++, (int)nodeId);
+          msg.setFieldInt32(base++, (int)dciId);
+          if (type == DataCollectionItem.DCO_TYPE_TABLE)
+          {
+             msg.setField(base++, column);
+             msg.setField(base++, instance);
+          }
+       }
+       
+       /**
         * Get DCI name. Always returns non-empty string.
         * @return
         */
index f7cfed4..e7392fc 100644 (file)
@@ -25,3 +25,4 @@ Bundle-ActivationPolicy: lazy
 Export-Package: org.netxms.ui.eclipse.networkmaps.algorithms,
  org.netxms.ui.eclipse.networkmaps.api,
  org.netxms.ui.eclipse.networkmaps.widgets
+Import-Package: org.netxms.ui.eclipse.perfview.views
index 4173b92..84d3b0f 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.netxms.ui.eclipse.networkmaps.views;
 
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -29,6 +30,7 @@ import java.util.Set;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.draw2d.ManhattanConnectionRouter;
 import org.eclipse.draw2d.geometry.Dimension;
@@ -86,6 +88,7 @@ import org.eclipse.ui.part.ViewPart;
 import org.netxms.client.NXCSession;
 import org.netxms.client.SessionListener;
 import org.netxms.client.SessionNotification;
+import org.netxms.client.datacollection.DciValue;
 import org.netxms.client.maps.MapLayoutAlgorithm;
 import org.netxms.client.maps.MapObjectDisplayMode;
 import org.netxms.client.maps.NetworkMapLink;
@@ -102,6 +105,7 @@ import org.netxms.client.objects.NetworkMap;
 import org.netxms.ui.eclipse.actions.RefreshAction;
 import org.netxms.ui.eclipse.console.resources.GroupMarkers;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.networkmaps.Activator;
 import org.netxms.ui.eclipse.networkmaps.Messages;
 import org.netxms.ui.eclipse.networkmaps.algorithms.ExpansionAlgorithm;
@@ -117,6 +121,7 @@ import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.CommandBridge;
 import org.netxms.ui.eclipse.tools.FilteringMenuManager;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.perfview.views.HistoricalGraphView;
 
 /**
  * Base class for network map views
@@ -349,6 +354,10 @@ public abstract class AbstractNetworkMapView extends ViewPart implements ISelect
                                                }
                                        }
                                }
+                               else if (selectionType == SELECTION_LINKS)
+                               {
+                                  openLinkDci();
+                               }
 
                                // Default behavior
                                actionOpenDrillDownObject.run();
@@ -1373,6 +1382,68 @@ public abstract class AbstractNetworkMapView extends ViewPart implements ISelect
                        }
                }
        }
+       
+       /**
+        * Handler for opening network map dci on double click
+        */
+       private void openLinkDci()
+       {
+          final NetworkMapLink link = (NetworkMapLink)currentSelection.getFirstElement();         
+          if (!link.hasDciData())
+             return;
+          new ConsoleJob("Open link dci job", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {         
+         /* (non-Javadoc)
+          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
+          */
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            DciValue[] values = session.getLastValues(link.getDciAsList());
+            final StringBuilder sb = new StringBuilder();
+            for(DciValue v : values)
+            {
+               sb.append("&");
+               sb.append(Long.toString(v.getNodeId()));
+               sb.append("@");
+               sb.append(Long.toString(v.getId()));
+               sb.append("@");
+               sb.append(Integer.toString(v.getSource()));
+               sb.append("@");
+               sb.append(Integer.toString(v.getDataType()));
+               sb.append("@");
+               sb.append(URLEncoder.encode(v.getName(), "UTF-8"));
+               sb.append("@");
+               sb.append(URLEncoder.encode(v.getDescription(), "UTF-8"));
+            }
+            
+            runInUIThread(new Runnable() {               
+               /* (non-Javadoc)
+                * @see java.lang.Runnable#run()
+                */
+               @Override
+               public void run()
+               {
+                  try
+                  {
+                     getSite().getPage().showView(HistoricalGraphView.ID, sb.toString(), IWorkbenchPage.VIEW_ACTIVATE);
+                  }
+                  catch(PartInitException e)
+                  {
+                     MessageDialogHelper.openError(getSite().getShell(), "Error", String.format("Error opening view: %s", e.getLocalizedMessage()));
+                  }
+               }
+            });
+         }         
+         /* (non-Javadoc)
+          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
+          */
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot open dci link historical graph view";
+         }
+      }.start();
+       }
 
        /**
         * Set map default connection routing algorithm
index dbbf777..62c0c9a 100644 (file)
@@ -240,7 +240,7 @@ public class LinkDciValueProvider
       SingleDciConfig[] dciList =  link.getDciList();
       for(int i = 0; i < dciList.length;)
       {
-         DciValue v = getDciLastValue(dciList[i].dciId); 
+         DciValue v = getDciLastValue(dciList[i].dciId);
          if (v != null)
          {
             String formatString = dciList[i].getFormatString();
index 7680190..30fbe5c 100644 (file)
@@ -4545,12 +4545,16 @@ void ClientSession::getLastValuesByDciId(NXCPMessage *pRequest)
 
                status = dcoObj->getStatus();
 
-               msg.setField(outgoingIndex++, dciID);
-               msg.setField(outgoingIndex++, CHECK_NULL_EX(value));
-               msg.setField(outgoingIndex++, type);
-               msg.setField(outgoingIndex++, status);
+               msg.setField(outgoingIndex + 1, dciID);
+               msg.setField(outgoingIndex + 2, CHECK_NULL_EX(value));
+               msg.setField(outgoingIndex + 3, type);
+               msg.setField(outgoingIndex + 4, status);
+               msg.setField(outgoingIndex + 5, object->getId());
+               msg.setField(outgoingIndex + 6, dcoObj->getDataSource());
+               msg.setField(outgoingIndex + 7, dcoObj->getName());
+               msg.setField(outgoingIndex + 8, dcoObj->getDescription());
                safe_free(value);
-               outgoingIndex += 6;
+               outgoingIndex += 10;
             }
          }
       }
index 2597c6c..4178b30 100644 (file)
@@ -25,3 +25,4 @@ Bundle-ActivationPolicy: lazy
 Export-Package: org.netxms.ui.eclipse.networkmaps.algorithms,
  org.netxms.ui.eclipse.networkmaps.api,
  org.netxms.ui.eclipse.networkmaps.widgets
+Import-Package: org.netxms.ui.eclipse.perfview.views
index a50786c..122c580 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.netxms.ui.eclipse.networkmaps.views;
 
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -29,6 +30,7 @@ import java.util.Set;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.draw2d.ManhattanConnectionRouter;
 import org.eclipse.draw2d.geometry.Dimension;
@@ -82,6 +84,7 @@ import org.eclipse.ui.part.ViewPart;
 import org.netxms.client.NXCSession;
 import org.netxms.client.SessionListener;
 import org.netxms.client.SessionNotification;
+import org.netxms.client.datacollection.DciValue;
 import org.netxms.client.maps.MapLayoutAlgorithm;
 import org.netxms.client.maps.MapObjectDisplayMode;
 import org.netxms.client.maps.NetworkMapLink;
@@ -98,6 +101,7 @@ import org.netxms.client.objects.NetworkMap;
 import org.netxms.ui.eclipse.actions.RefreshAction;
 import org.netxms.ui.eclipse.console.resources.GroupMarkers;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.networkmaps.Activator;
 import org.netxms.ui.eclipse.networkmaps.Messages;
 import org.netxms.ui.eclipse.networkmaps.algorithms.ExpansionAlgorithm;
@@ -109,6 +113,7 @@ import org.netxms.ui.eclipse.networkmaps.views.helpers.LinkDciValueProvider;
 import org.netxms.ui.eclipse.networkmaps.views.helpers.MapContentProvider;
 import org.netxms.ui.eclipse.networkmaps.views.helpers.MapLabelProvider;
 import org.netxms.ui.eclipse.objectbrowser.api.ObjectContextMenu;
+import org.netxms.ui.eclipse.perfview.views.HistoricalGraphView;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.CommandBridge;
 import org.netxms.ui.eclipse.tools.FilteringMenuManager;
@@ -345,6 +350,10 @@ public abstract class AbstractNetworkMapView extends ViewPart implements ISelect
                                                }
                                        }
                                }
+            else if (selectionType == SELECTION_LINKS)
+            {
+               openLinkDci();
+            }
 
                                // Default behavior
                                actionOpenDrillDownObject.run();
@@ -1354,6 +1363,68 @@ public abstract class AbstractNetworkMapView extends ViewPart implements ISelect
                        }
                }
        }
+       
+       /**
+    * Handler for opening network map dci on double click
+    */
+   private void openLinkDci()
+   {
+      final NetworkMapLink link = (NetworkMapLink)currentSelection.getFirstElement();     
+      if (!link.hasDciData())
+         return;
+      new ConsoleJob("Open link dci job", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {         
+         /* (non-Javadoc)
+          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
+          */
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            DciValue[] values = session.getLastValues(link.getDciAsList());
+            final StringBuilder sb = new StringBuilder();
+            for(DciValue v : values)
+            {
+               sb.append("&");
+               sb.append(Long.toString(v.getNodeId()));
+               sb.append("@");
+               sb.append(Long.toString(v.getId()));
+               sb.append("@");
+               sb.append(Integer.toString(v.getSource()));
+               sb.append("@");
+               sb.append(Integer.toString(v.getDataType()));
+               sb.append("@");
+               sb.append(URLEncoder.encode(v.getName(), "UTF-8"));
+               sb.append("@");
+               sb.append(URLEncoder.encode(v.getDescription(), "UTF-8"));
+            }
+            
+            runInUIThread(new Runnable() {               
+               /* (non-Javadoc)
+                * @see java.lang.Runnable#run()
+                */
+               @Override
+               public void run()
+               {
+                  try
+                  {
+                     getSite().getPage().showView(HistoricalGraphView.ID, sb.toString(), IWorkbenchPage.VIEW_ACTIVATE);
+                  }
+                  catch(PartInitException e)
+                  {
+                     MessageDialogHelper.openError(getSite().getShell(), "Error", String.format("Error opening view: %s", e.getLocalizedMessage()));
+                  }
+               }
+            });
+         }         
+         /* (non-Javadoc)
+          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
+          */
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot open dci link historical graph view";
+         }
+      }.start();
+   }
 
        /**
         * Set map default connection routing algorithm