"commands" box on overview page filled from object tools; object tools can have icons
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 20 May 2014 19:53:54 +0000 (22:53 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 20 May 2014 19:53:54 +0000 (22:53 +0300)
63 files changed:
android/src/agent/res/values/build_number.xml
android/src/console/res/values/build_number.xml
build/build_number
include/build.h
include/netxms-version.h
include/netxmsdb.h
include/nms_cscp.h
include/nms_util.h
include/nxcpapi.h
include/nxtools.h
sql/objtools.in
sql/schema.in
src/java/build/set_build_number.cmd
src/java/certificate-manager/pom.xml
src/java/mobile-agent/pom.xml
src/java/netxms-base/pom.xml
src/java/netxms-base/src/main/java/org/netxms/base/BuildNumber.java
src/java/netxms-base/src/main/java/org/netxms/base/NXCPCodes.java
src/java/netxms-base/src/main/java/org/netxms/base/NXCommon.java
src/java/netxms-client-api/pom.xml
src/java/netxms-client/pom.xml
src/java/netxms-client/src/main/java/org/netxms/client/objecttools/ObjectTool.java
src/java/netxms-client/src/main/java/org/netxms/client/objecttools/ObjectToolDetails.java
src/java/netxms-eclipse/Core/.classpath
src/java/netxms-eclipse/Core/META-INF/MANIFEST.MF
src/java/netxms-eclipse/Core/build.properties
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/widgets/CommandBox.java
src/java/netxms-eclipse/ObjectTools/META-INF/MANIFEST.MF
src/java/netxms-eclipse/ObjectTools/plugin.xml
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/Activator.java
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/LoginListener.java
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/ObjectToolsDynamicMenu.java
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/WakeupToolHandler.java [new file with mode: 0644]
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/NodeInfo.java [new file with mode: 0644]
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java [new file with mode: 0644]
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolsCache.java [moved from src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/ObjectToolsCache.java with 78% similarity]
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/views/LocalCommandResults.java
src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/views/TableToolResults.java
src/java/netxms-eclipse/ObjectView/META-INF/MANIFEST.MF
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/SourceProvider.java
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/Commands.java
src/java/pom.xml
src/libnetxms/message.cpp
src/libnetxms/tools.cpp
src/server/core/objtools.cpp
src/server/core/session.cpp
src/server/tools/nxdbmgr/upgrade.cpp
webui/webapp/Core/.classpath
webui/webapp/Core/META-INF/MANIFEST.MF
webui/webapp/Core/build.properties
webui/webapp/ObjectTools/META-INF/MANIFEST.MF
webui/webapp/ObjectTools/plugin.xml
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/Activator.java
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/LoginListener.java
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/ObjectToolsDynamicMenu.java
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/WakeupToolHandler.java [new file with mode: 0644]
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/NodeInfo.java [new file with mode: 0644]
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java [new file with mode: 0644]
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolsCache.java [moved from webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/ObjectToolsCache.java with 79% similarity]
webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/views/TableToolResults.java
webui/webapp/ObjectView/META-INF/MANIFEST.MF
webui/webapp/ObjectView/src/org/netxms/ui/eclipse/objectview/SourceProvider.java
webui/webapp/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/Commands.java

index 477a9b9..ede836a 100644 (file)
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-       <string name="build_number">7876</string>
+       <string name="build_number">7877</string>
 </resources>
index 477a9b9..ede836a 100644 (file)
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-       <string name="build_number">7876</string>
+       <string name="build_number">7877</string>
 </resources>
index 5436fdf..7a0e2f1 100644 (file)
@@ -1 +1 @@
-7876
+7877
index 75a42d3..bff4455 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef __build_h
 #define __build_h
-#define NETXMS_VERSION_BUILD 7876
-#define NETXMS_VERSION_BUILD_STRING _T("7876")
+#define NETXMS_VERSION_BUILD 7877
+#define NETXMS_VERSION_BUILD_STRING _T("7877")
 #endif
index 132d5d1..9cf812a 100644 (file)
@@ -30,9 +30,9 @@
  */
 #define NETXMS_VERSION_MAJOR        1
 #define NETXMS_VERSION_MINOR        2
-#define NETXMS_VERSION_RELEASE      14
-#define NETXMS_VERSION_STRING       _T("1.2.14")
-#define NETXMS_VERSION_STRING_A     "1.2.14"
+#define NETXMS_VERSION_RELEASE      15
+#define NETXMS_VERSION_STRING       _T("1.2.15")
+#define NETXMS_VERSION_STRING_A     "1.2.15"
 
 #ifdef UNICODE
 #define IS_UNICODE_BUILD_STRING     _T(" (UNICODE)")
index 98e7ed4..83768f4 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   318
+#define DB_FORMAT_VERSION   319
 
 #endif
index eee60e3..aeda023 100644 (file)
@@ -975,6 +975,7 @@ typedef struct
 #define VID_URL                     ((UINT32)471)
 #define VID_PEER_PROTOCOL           ((UINT32)472)
 #define VID_VIEW_REFRESH_INTERVAL   ((UINT32)473)
+#define VID_COMMAND_NAME            ((UINT32)474)
 
 // Base variabe for single threshold in message
 #define VID_THRESHOLD_BASE          ((UINT32)0x00800000)
index 8d67516..c7da72e 100644 (file)
@@ -1006,8 +1006,8 @@ extern "C"
 #define BinToStr BinToStrA
 #endif
 
-   UINT32 LIBNETXMS_EXPORTABLE StrToBinW(const WCHAR *pStr, BYTE *data, UINT32 size);
-   UINT32 LIBNETXMS_EXPORTABLE StrToBinA(const char *pStr, BYTE *data, UINT32 size);
+   size_t LIBNETXMS_EXPORTABLE StrToBinW(const WCHAR *pStr, BYTE *data, size_t size);
+   size_t LIBNETXMS_EXPORTABLE StrToBinA(const char *pStr, BYTE *data, size_t size);
 #ifdef UNICODE
 #define StrToBin StrToBinW
 #else
index b5db1e9..1f1ad3b 100644 (file)
@@ -112,6 +112,7 @@ public:
    bool getFieldAsBoolean(UINT32 fieldId);
    UINT32 getFieldAsInt32Array(UINT32 fieldId, UINT32 numElements, UINT32 *buffer);
    UINT32 getFieldAsInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data);
+   BYTE *getBinaryFieldPtr(UINT32 fieldId, size_t *size);
 
    UINT32 GetVariableLong(UINT32 dwVarId);
    UINT64 GetVariableInt64(UINT32 dwVarId);
index 1526c5f..dc52dbe 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2011 Victor Kirhenshtein
+** Copyright (C) 2003-2014 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
 // Object tool flags
 //
 
-#define TF_REQUIRES_SNMP            ((DWORD)0x00000001)
-#define TF_REQUIRES_AGENT           ((DWORD)0x00000002)
-#define TF_REQUIRES_OID_MATCH       ((DWORD)0x00000004)
-#define TF_ASK_CONFIRMATION         ((DWORD)0x00000008)
-#define TF_DISABLED                 ((DWORD)0x00000020)
-#define TF_SNMP_INDEXED_BY_VALUE    ((DWORD)0x00010000)
+#define TF_REQUIRES_SNMP            ((UINT32)0x00000001)
+#define TF_REQUIRES_AGENT           ((UINT32)0x00000002)
+#define TF_REQUIRES_OID_MATCH       ((UINT32)0x00000004)
+#define TF_ASK_CONFIRMATION         ((UINT32)0x00000008)
+#define TF_GENERATES_OUTPUT         ((UINT32)0x00000010)
+#define TF_DISABLED                 ((UINT32)0x00000020)
+#define TF_SHOW_IN_COMMANDS         ((UINT32)0x00000040)
+#define TF_SNMP_INDEXED_BY_VALUE    ((UINT32)0x00010000)
 
 
 //
index ab0d9d3..cea6d5e 100644 (file)
@@ -3,17 +3,23 @@
 ** ex: syntax=sql
 */
 
-INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
-       VALUES (1,'&Shutdown system',TOOL_TYPE_ACTION,'System.Shutdown',10,' ','Shutdown target node via NetXMS agent',
-   'Host %OBJECT_NAME% (%OBJECT_IP_ADDR%) will be shut down. Are you sure?');
-INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
-       VALUES (2,'&Restart system',TOOL_TYPE_ACTION,'System.Restart',10,' ','Restart target node via NetXMS agent',
-   'Host %OBJECT_NAME% (%OBJECT_IP_ADDR%) will be restarted. Are you sure?');
-INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
-       VALUES (3,'&Wakeup node',TOOL_TYPE_INTERNAL,'wakeup',0,' ','Wakeup node using Wake-On-LAN magic packet','');
+INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text,command_name,icon)
+       VALUES (1,'&Shutdown system',TOOL_TYPE_ACTION,'System.Shutdown',74,' ','Shutdown target node via NetXMS agent',
+           'Host %OBJECT_NAME% (%OBJECT_IP_ADDR%) will be shut down. Are you sure?', 'Shutdown system',
+           '89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000000473424954080808087c086488000002bf49444154388d95933f689c7518c73fbf3f7779efaede995c137369d54123ba4843070b1204c10ed24db182939b90c1c1e2eee05871e8d0d2b98a8ba0c52ee2d0cb622acd99222dd1084d9a18cd3597f7bd6bdebbdffbfbe7701d82e8e0071ebec303dfe7e1e1fb883fea7542aba54c080dac153c261ed1a30540b51a8f359bd9c9e565afedd4943ab6b4f4d56873f38d5014ff6af04f95950aaad5fa7e7d7dfdbcee1d1c3cd95d59395b5a5c7c82ffc1fd4ee7acc9f349fd683090b1db15499ae2013b3f8f1c0e296f6f539c380140796707333747a856296d6ca081d1e1a138cc73a95d8cc28f468834459f3ecd7367cee0b38ccd7bf7787e711180dfaf5ee599850544a3c1760898d5556c51e06314d2c5288be150186b995d58404bc9eef5ebb87e86140229257690b17be33b4a4a3173ea14236b71d60a17a3901684b59652b34952ab31dcda6470f76794c9b0b6c0160665320eefae317ab04552ad529e9ec6c78003292dc861bf2f4408e369fb7b948a8cb2cd7085c115868998936887eb75514a617a3db66eb68505211d30f86b97dde536420844a341b17e8bf8db0a21ed12d23ddcda0ff46f7e4dac24482939b8b386b3060f4207206a457afb16be9f519f7f91f22baf52f9e91bfca7ef00829a4fb1af9fa3fed2cbf8419f6c75054a0a0fc800a025f151cafdcb17514af3ecc79f939fbf40d69c259d9ca1ffd687cc7d7411a5145b573e230e52d0120f68ffd8400ad8b97685c9934f31f9ee07b4de5e227ff37d8c311c4f12aad50afb5f5c62e7da65a400519204408f37108408de471e5cfa04fbe3b74c9d7b8ff2d32f1042805f7e25bdf1257fdeee103c8408528d53afa356c85a42b107d6812920bdd3c16f7448cae3d81a0b837cdc2b1c380f724203445d8ff161767cb66df1afe5380a0d3d05ca8d0f148110c02bb035b013109b1a17747b06baa20d3c84897dc93420feeb0b8f22203603dd19307f037f0665861328b32e0000000049454e44ae426082'
+           );
+INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text,command_name,icon)
+       VALUES (2,'&Restart system',TOOL_TYPE_ACTION,'System.Restart',74,' ','Restart target node via NetXMS agent',
+           'Host %OBJECT_NAME% (%OBJECT_IP_ADDR%) will be restarted. Are you sure?', 'Restart system',
+           '89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000000473424954080808087c0864880000029849444154388d85934d8b1c5514869f73eeadaaae6ea77bda388999882241fc5c0e09ae4484c4857b4177fa0b5474256edcfa075cbacbc23f6074a12332a0a2200a2189e8c468a23d93e99e9eaeaaae7beb1e1733f9902c7ce06c0ebc2f2fe7f0ca5fe311fdd71e77d93332922e08b749dcc5fe3bc9f72d5d1fcf861f7dd6f9f295353778ebdd0b71ff977374ad60f7888e1003bbb3379ceb930f4e7fbe7be5a7573da7f65697db17cf2ff2e757fe6e06a00e1141040aab59ebb5dc47076efbdb739cacc63edc9aabee4f64796248efb10dbcf738e750556268e97eff14b937ce6d1607126e55eae33c4956d5f4f72f21ae40d6cfe0bc4755c9f39cd4ccc0d27d7a695ae23c896fe7a645d5482c26340f0d19e639beb9811463c85788610a29c1d11d4284cc416a82848589861a49754bab390fac3f4ba69174f963ba7040d745249f4136033f63efd859769f78933a792c244265ea436d9a9a99e86895bc28b0e90fc03632bd88e463acb787580696f3e0fa299ade09e275a5feed2b09b5898f4ba35bdc40bb6b0034f5357cda4277bec354400d0b0d5d75406a5e42caa751d90596c425e22d00aa48771933a3c99e6230a8d1b241dcd1eb03a4a2c4563600f07615bc622da80510149aefa1b982ef3dc24d7d071b7afc71f0c781d58c83d107e48347d1f62a1a7f44f4d0c0130c4c4196d89fefa1273f215f7d9d4b379fa4dfdf22cb32bc7f99b5f533c45893edbc4fe75a8c0116c05b008b408434fd9a327f031b7d08c73670ee2c65595296259afe20fbe76de2fc9ba39e1cd6c6a7e4b0ae87d5200a4cbea4acce3318bd8865cfe1a283dd9fe9a65f901615a982d400c96360be9eda4ebbfdf0a6ec752f741ac11f1a89db02d9ba5bc8d483ae877587e2f0abdfac2b26b209488fa218b07627d7ff636dc524d52cff0513e53f37235ac3190000000049454e44ae426082'
+           );
+INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text,command_name,icon)
+       VALUES (3,'&Wakeup node',TOOL_TYPE_INTERNAL,'wakeup',64,' ','Wakeup node using Wake-On-LAN magic packet','','Wakeup node using Wake-On-LAN',
+           '89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000000473424954080808087c086488000000097048597300000dd700000dd70142289b780000001974455874536f667477617265007777772e696e6b73636170652e6f72679bee3c1a0000023649444154388d8d924f48545114c67ff7bd37ff7cf9071bc70a4d47271ca15c848d448185b40a89204890362d8568eb2270d7a2762d5cb7711504d1ae10c195218895a488528e4e06a653d338de7bdfbcf75ac84ce38c901f9ccdb9e7fbce39f77c627ce6872df6dd71f01f781e1d9c00866003215efaf99de7d6763afb1078721262053a800908ed5a5aa9b1e3bb0802a600c0717d3cdf3fae6cccd24a25abb302a80b990c265a009859d941299763249296d6b2a6732468d25a1f24156f00e0cbd62e9b5a71a0dd9a490cad14a570b4266c780cf546797cab1b1317139747435ddcec69266c78385a53c9b1b45265b548d022d51563f45a9c778b69ce35850058de928c0cb4933fd04c7ffece812e9639e5158480865098ebc9181fbfeef07a6e9dc68805c0af8243f45480ab174e33bb9426e7484a9b942710020c3b40e24c236f3facb1bd9b634d3a00d8e100ab992cb7af7421bc225aa9b280a195a414524972054d5f679488e5a394442949d8f4b8d4d14caea09115f55a490cad155a2b9452ecfdcef37e619ddef6287706ba89c76ce2319be1fe4e926d51663e6d90cdeda3d42147ebaa4fcc161da6a61739df52cfe88d8b0ca712f8be871d0e31bb94666a7a916c2e8feb7aff3cd33ef2f4c8612dd3a0a5d1a6bfa78d544f1bbeef33bf9a617e65939fb902c50a328068bd3bb10c1c71a3210401cb24143cbc82d2459c62ad8980154b2b3909bca87e91c09fea642d26ad67f7fb32afe6bebd5958dd1c2c48ddf45f8a10d87591bdcb89b3b3f7063a337f01f30f1c1c580292640000000049454e44ae426082'
+           );
 INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
        VALUES (4,'Restart &agent',TOOL_TYPE_ACTION,'Agent.Restart',10,' ','Restart NetXMS agent on target node',
-   'NetXMS agent on host %OBJECT_NAME% (%OBJECT_IP_ADDR%) will be restarted. Are you sure?');
+           'NetXMS agent on host %OBJECT_NAME% (%OBJECT_IP_ADDR%) will be restarted. Are you sure?');
 
 INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
        VALUES (5,'&Info->&Switch forwarding database (FDB)',TOOL_TYPE_TABLE_SNMP,'Forwarding database',1,' ','Show switch forwarding database','');
@@ -49,7 +55,7 @@ INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_
        VALUES (10,0,'Parameter',' ',CFMT_STRING,1);
 
 INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
-       VALUES (11,'&Info->&Agent->Supported &actions',TOOL_TYPE_TABLE_AGENT,'Supported actions\7fAgent.ActionList\7f^(.*) (.*) #22(.*)#22.*',2,' ','Show list of actions supported by agent','');
+       VALUES (11,'&Info->&Agent->Supported &actions',TOOL_TYPE_TABLE_AGENT,'Supported actions\7fAgent.ActionList\7f^(.*) (.*) "(.*)".*',2,' ','Show list of actions supported by agent','');
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
        VALUES (11,0,'Name',' ',CFMT_STRING,1);
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
@@ -72,7 +78,7 @@ INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_
 
 INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
        VALUES (13,'&Info->&Process list',TOOL_TYPE_TABLE_AGENT,
-                'Process List\7fSystem.ProcessList\7f^([0-9]+) (.*)',2,' ','Show list of currently running processes','');
+           'Process List\7fSystem.ProcessList\7f^([0-9]+) (.*)',2,' ','Show list of currently running processes','');
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
        VALUES (13,0,'PID',' ',CFMT_STRING,1);
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
@@ -104,7 +110,7 @@ INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_
 
 INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
        VALUES (16,'&Info->Active &user sessions',TOOL_TYPE_TABLE_AGENT,
-                'Active User Sessions\7fSystem.ActiveUserSessions\7f^"(.*)" "(.*)" "(.*)"',2,' ','Show list of active user sessions','');
+           'Active User Sessions\7fSystem.ActiveUserSessions\7f^"(.*)" "(.*)" "(.*)"',2,' ','Show list of active user sessions','');
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
        VALUES (16,0,'User',' ',CFMT_STRING,1);
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
@@ -123,7 +129,7 @@ INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_
 
 INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)
        VALUES (18,'&Info->AR&P cache (Agent)',TOOL_TYPE_TABLE_AGENT,
-               'ARP Cache\7fNet.ArpCache\7f(.*) (.*) (.*)',2,' ','Show ARP cache','');
+           'ARP Cache\7fNet.ArpCache\7f(.*) (.*) (.*)',2,' ','Show ARP cache','');
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
        VALUES (18,0,'IP Address','.1.3.6.1.2.1.4.22.1.3',CFMT_STRING,2);
 INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)
index 0f2cfca..7420935 100644 (file)
@@ -1004,6 +1004,8 @@ CREATE TABLE object_tools
        flags integer not null,
        matching_oid varchar(255) null,
        confirmation_text varchar(255) null,
+   command_name varchar(255) null,
+   icon SQL_TEXT null,
        PRIMARY KEY(tool_id)
 ) TABLE_TYPE;
 
index b0adb03..aa745b7 100644 (file)
@@ -3,7 +3,7 @@
     <parent>
         <groupId>org.netxms</groupId>
         <artifactId>netxms</artifactId>
-        <version>1.2.14</version>
+        <version>1.2.15</version>
     </parent>
 
     <modelVersion>4.0.0</modelVersion>
index 6763a46..e12939b 100644 (file)
@@ -4,7 +4,7 @@
        <parent>
                <groupId>org.netxms</groupId>
                <artifactId>netxms</artifactId>
-               <version>1.2.14</version>
+               <version>1.2.15</version>
        </parent>
 
        <modelVersion>4.0.0</modelVersion>
index c0fc3f1..858cfaf 100644 (file)
@@ -4,7 +4,7 @@
        <parent>
                <groupId>org.netxms</groupId>
                <artifactId>netxms</artifactId>
-               <version>1.2.14</version>
+               <version>1.2.15</version>
        </parent>
 
        <modelVersion>4.0.0</modelVersion>
index f4dc151..696e678 100644 (file)
@@ -1,5 +1,5 @@
 package org.netxms.base;
 public final class BuildNumber {
-   public static final String TEXT = "7876";
-   public static final int NUMBER = 7876;
+   public static final String TEXT = "7877";
+   public static final int NUMBER = 7877;
 }
index 8301c0a..895b225 100644 (file)
@@ -801,6 +801,7 @@ public class NXCPCodes
    public static final long VID_URL = 471;
    public static final long VID_PEER_PROTOCOL = 472;
    public static final long VID_VIEW_REFRESH_INTERVAL = 473;
+   public static final long VID_COMMAND_NAME = 474;
 
        public static final long VID_ACL_USER_BASE = 0x00001000L;
        public static final long VID_ACL_USER_LAST = 0x00001FFFL;
index 0b56a57..152aa1c 100644 (file)
@@ -26,7 +26,7 @@ import java.util.UUID;
 public final class NXCommon
 {
        // Version information
-       public static final String VERSION = "1.2.14";
+       public static final String VERSION = "1.2.15";
        
        public static final UUID EMPTY_GUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
 }
index b0a5788..fa46b24 100644 (file)
@@ -4,7 +4,7 @@
        <parent>
                <groupId>org.netxms</groupId>
                <artifactId>netxms</artifactId>
-               <version>1.2.14</version>
+               <version>1.2.15</version>
        </parent>
 
        <modelVersion>4.0.0</modelVersion>
index 94e8f03..1f27a9e 100644 (file)
@@ -4,7 +4,7 @@
        <parent>
                <groupId>org.netxms</groupId>
                <artifactId>netxms</artifactId>
-               <version>1.2.14</version>
+               <version>1.2.15</version>
        </parent>
 
        <modelVersion>4.0.0</modelVersion>
index 1e344a4..baa111f 100644 (file)
@@ -43,6 +43,7 @@ public class ObjectTool
        public static final int ASK_CONFIRMATION      = 0x00000008;
        public static final int GENERATES_OUTPUT      = 0x00000010;
        public static final int DISABLED              = 0x00000020;
+   public static final int SHOW_IN_COMMANDS      = 0x00000040;
        public static final int SNMP_INDEXED_BY_VALUE = 0x00010000;
        
        protected long id;
@@ -54,6 +55,8 @@ public class ObjectTool
        protected String snmpOid;
        protected String data;
        protected String confirmationText;
+       protected String commandName;
+       protected byte[] imageData;
 
        /**
         * Default implicit constructor.
@@ -78,6 +81,8 @@ public class ObjectTool
                description = msg.getVariableAsString(baseId + 5);
                snmpOid = msg.getVariableAsString(baseId + 6);
                confirmationText = msg.getVariableAsString(baseId + 7);
+               commandName = msg.getVariableAsString(baseId + 8);
+               imageData = msg.getVariableAsBinary(baseId + 9);
                
                createDisplayName();
        }
@@ -194,4 +199,30 @@ public class ObjectTool
        {
                return displayName;
        }
+
+   /**
+    * @return the commandName
+    */
+   public String getCommandName()
+   {
+      return commandName;
+   }
+   
+   /**
+    * @return
+    */
+   public String getCommandDisplayName()
+   {
+      if ((commandName != null) && !commandName.isEmpty())
+         return commandName;
+      return displayName;
+   }
+
+   /**
+    * @return the imageData
+    */
+   public byte[] getImageData()
+   {
+      return imageData;
+   }
 }
index 3834fa6..dbf8bab 100644 (file)
@@ -56,6 +56,8 @@ public class ObjectToolDetails extends ObjectTool
                confirmationText = "";
                accessList = new ArrayList<Long>(0);
                columns = new ArrayList<ObjectToolTableColumn>(0);
+               commandName = "";
+               imageData = null;
 
                createDisplayName();
        }
@@ -77,6 +79,8 @@ public class ObjectToolDetails extends ObjectTool
                description = msg.getVariableAsString(NXCPCodes.VID_DESCRIPTION);
                snmpOid = msg.getVariableAsString(NXCPCodes.VID_TOOL_OID);
                confirmationText = msg.getVariableAsString(NXCPCodes.VID_CONFIRMATION_TEXT);
+               commandName = msg.getVariableAsString(NXCPCodes.VID_COMMAND_NAME);
+               imageData = msg.getVariableAsBinary(NXCPCodes.VID_IMAGE_DATA);
                
                Long[] acl = msg.getVariableAsUInt32ArrayEx(NXCPCodes.VID_ACL);
                accessList = (acl != null) ? new ArrayList<Long>(Arrays.asList(acl)) : new ArrayList<Long>(0);
@@ -108,6 +112,9 @@ public class ObjectToolDetails extends ObjectTool
                msg.setVariable(NXCPCodes.VID_TOOL_DATA, data);
                msg.setVariableInt16(NXCPCodes.VID_TOOL_TYPE, type);
                msg.setVariableInt32(NXCPCodes.VID_FLAGS, flags);
+               msg.setVariable(NXCPCodes.VID_COMMAND_NAME, commandName);
+               if (imageData != null)
+                  msg.setVariable(NXCPCodes.VID_IMAGE_DATA, imageData);
 
                msg.setVariableInt32(NXCPCodes.VID_ACL_SIZE, accessList.size());
                msg.setVariable(NXCPCodes.VID_ACL, accessList.toArray(new Long[accessList.size()]));
@@ -238,4 +245,22 @@ public class ObjectToolDetails extends ObjectTool
                this.columns = columns;
                modified = true;
        }
+       
+       /**
+        * @param commandName
+        */
+       public void setCommandName(String commandName)
+       {
+          this.commandName = commandName;
+          modified = true;
+       }
+       
+       /**
+        * @param imageData
+        */
+       public void setImageData(byte[] imageData)
+       {
+          this.imageData = imageData;
+          modified = true;
+       }
 }
index f0a6b18..86855bc 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry exported="true" kind="lib" path="jar/certificate-manager-1.2.14.jar"/>
-       <classpathentry exported="true" kind="lib" path="jar/netxms-base-1.2.14.jar" sourcepath="/netxms-base"/>
-       <classpathentry exported="true" kind="lib" path="jar/netxms-client-1.2.14.jar" sourcepath="/netxms-client"/>
-       <classpathentry exported="true" kind="lib" path="jar/netxms-client-api-1.2.14.jar" sourcepath="/netxms-client-api"/>
+       <classpathentry exported="true" kind="lib" path="jar/certificate-manager-1.2.15.jar"/>
+       <classpathentry exported="true" kind="lib" path="jar/netxms-base-1.2.15.jar"/>
+       <classpathentry exported="true" kind="lib" path="jar/netxms-client-1.2.15.jar"/>
+       <classpathentry exported="true" kind="lib" path="jar/netxms-client-api-1.2.15.jar"/>
        <classpathentry exported="true" kind="lib" path="jar/simple-xml-2.6.4.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
index 89eef60..3f0370d 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %Bundle-Name
 Bundle-SymbolicName: org.netxms.ui.eclipse.console;singleton:=true
-Bundle-Version: 1.2.14
+Bundle-Version: 1.2.15
 Bundle-Activator: org.netxms.ui.eclipse.console.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
@@ -14,10 +14,10 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Bundle-ClassPath: .,
  jar/simple-xml-2.6.4.jar,
- jar/certificate-manager-1.2.14.jar,
- jar/netxms-base-1.2.14.jar,
- jar/netxms-client-1.2.14.jar,
- jar/netxms-client-api-1.2.14.jar
+ jar/certificate-manager-1.2.15.jar,
+ jar/netxms-base-1.2.15.jar,
+ jar/netxms-client-1.2.15.jar,
+ jar/netxms-client-api-1.2.15.jar
 Export-Package: org.netxms.api.client,
  org.netxms.api.client.constants,
  org.netxms.api.client.images,
index cbfc01a..79416f1 100644 (file)
@@ -8,8 +8,8 @@ bin.includes = plugin.xml,\
                splash.bmp,\
                jar/,\
                OSGI-INF/,\
-               jar/certificate-manager-1.2.14.jar,\
-               jar/netxms-base-1.2.14.jar,\
-               jar/netxms-client-1.2.14.jar,\
-               jar/netxms-client-api-1.2.14.jar
+               jar/certificate-manager-1.2.15.jar,\
+               jar/netxms-base-1.2.15.jar,\
+               jar/netxms-client-1.2.15.jar,\
+               jar/netxms-client-api-1.2.15.jar
 jars.compile.order = .
index 3b877f3..48e8b17 100644 (file)
@@ -40,7 +40,6 @@ import org.netxms.ui.eclipse.console.resources.SharedColors;
 
 /**
  * Implements command box - vertical list of hyperlinks to given actions
- *
  */
 public class CommandBox extends Composite implements DisposeListener
 {
index b3e5df3..7025c42 100644 (file)
@@ -2,16 +2,16 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NXMC Object Tools plugin
 Bundle-SymbolicName: org.netxms.ui.eclipse.objecttools;singleton:=true
-Bundle-Version: 1.2.13
+Bundle-Version: 1.2.15
 Bundle-Activator: org.netxms.ui.eclipse.objecttools.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
  org.eclipse.core.runtime;bundle-version="3.7.0",
  org.eclipse.core.expressions;bundle-version="3.4.300",
  org.eclipse.ui.console;bundle-version="3.5.100",
- org.netxms.ui.eclipse.console;bundle-version="1.2.13",
- org.netxms.ui.eclipse.usermanager;bundle-version="1.2.7",
- org.netxms.ui.eclipse.snmp;bundle-version="1.2.10",
+ org.netxms.ui.eclipse.console;bundle-version="1.2.15",
+ org.netxms.ui.eclipse.usermanager;bundle-version="1.2.14",
+ org.netxms.ui.eclipse.snmp;bundle-version="1.2.12",
  org.eclipse.ui.workbench.texteditor;bundle-version="3.7.0",
  org.eclipse.jface.text;bundle-version="3.7.2"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
index b4bed13..30a13c9 100644 (file)
             class="org.netxms.ui.eclipse.objecttools.LoginListener">
       </loginlistener>
    </extension>
+   <extension
+         point="org.netxms.ui.eclipse.objecttools.toolhandlers">
+      <handler
+            class="org.netxms.ui.eclipse.objecttools.WakeupToolHandler"
+            id="wakeup">
+      </handler>
+   </extension>
 
 </plugin>
index 5b071b0..60d6a21 100644 (file)
  */
 package org.netxms.ui.eclipse.objecttools;
 
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -88,4 +90,35 @@ public class Activator extends AbstractUIPlugin
        {
                return imageDescriptorFromPlugin(PLUGIN_ID, path);
        }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logInfo(String msg)
+   {
+      log(Status.INFO, msg, null);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logError(String msg, Throwable t)
+   {
+      log(Status.ERROR, msg, t);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    * @param t
+    */
+   public static void log(int status, String msg, Throwable t)
+   {
+      getDefault().getLog().log(new Status(status, PLUGIN_ID, Status.OK, msg, t));
+   }
 }
index 686007c..0756d90 100644 (file)
@@ -21,6 +21,7 @@ package org.netxms.ui.eclipse.objecttools;
 import org.eclipse.swt.widgets.Display;
 import org.netxms.client.NXCSession;
 import org.netxms.ui.eclipse.console.api.ConsoleLoginListener;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 
 /**
  * Early startup class
index 26d0c60..18cc75d 100644 (file)
  */
 package org.netxms.ui.eclipse.objecttools;
 
-import java.io.IOException;
-import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.MenuItem;
 import org.eclipse.ui.ISources;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.menus.IWorkbenchContribution;
 import org.eclipse.ui.services.IEvaluationService;
 import org.eclipse.ui.services.IServiceLocator;
-import org.netxms.client.AgentFile;
 import org.netxms.client.NXCSession;
 import org.netxms.client.events.Alarm;
 import org.netxms.client.objects.AbstractNode;
@@ -53,15 +47,11 @@ import org.netxms.client.objects.Container;
 import org.netxms.client.objects.ServiceRoot;
 import org.netxms.client.objects.Subnet;
 import org.netxms.client.objecttools.ObjectTool;
-import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler;
-import org.netxms.ui.eclipse.objecttools.views.BrowserView;
-import org.netxms.ui.eclipse.objecttools.views.FileViewer;
-import org.netxms.ui.eclipse.objecttools.views.LocalCommandResults;
-import org.netxms.ui.eclipse.objecttools.views.TableToolResults;
+import org.netxms.ui.eclipse.objecttools.api.NodeInfo;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolExecutor;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.ImageCache;
 
 /**
  * Dynamic object tools menu creator
@@ -110,6 +100,15 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                final Set<NodeInfo> nodes = buildNodeSet((IStructuredSelection)selection);
                final Menu toolsMenu = new Menu(menu);
                
+               final ImageCache imageCache = new ImageCache();
+               toolsMenu.addDisposeListener(new DisposeListener() {
+         @Override
+         public void widgetDisposed(DisposeEvent e)
+         {
+            imageCache.dispose();
+         }
+      });
+               
                ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
                Arrays.sort(tools, new Comparator<ObjectTool>() {
                        @Override
@@ -124,7 +123,7 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                for(int i = 0; i < tools.length; i++)
                {
                        boolean enabled = (tools[i].getFlags() & ObjectTool.DISABLED) == 0;
-                       if (enabled && isToolAllowed(tools[i], nodes) && isToolApplicable(tools[i], nodes))
+                       if (enabled && ObjectToolExecutor.isToolAllowed(tools[i], nodes) && ObjectToolExecutor.isToolApplicable(tools[i], nodes))
                        {
                                String[] path = tools[i].getName().split("\\-\\>"); //$NON-NLS-1$
                        
@@ -146,12 +145,15 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                                
                                final MenuItem item = new MenuItem(rootMenu, SWT.PUSH);
                                item.setText(path[path.length - 1]);
+                               ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tools[i].getId());
+                               if (icon != null)
+                                  item.setImage(imageCache.add(icon));
                                item.setData(tools[i]);
                                item.addSelectionListener(new SelectionAdapter() {
                                        @Override
                                        public void widgetSelected(SelectionEvent e)
                                        {
-                                               executeObjectTool(nodes, (ObjectTool)item.getData());
+                                          ObjectToolExecutor.execute(nodes, (ObjectTool)item.getData());
                                        }
                                });
                                
@@ -202,454 +204,4 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                }
                return nodes;
        }
-       
-       /**
-        * Check if tool is allowed for execution on each node from set
-        * 
-        * @param tool
-        * @param nodes
-        * @return
-        */
-       private static boolean isToolAllowed(ObjectTool tool, Set<NodeInfo> nodes)
-       {
-               if (tool.getType() != ObjectTool.TYPE_INTERNAL)
-                       return true;
-               
-               ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
-               if (handler != null)
-               {
-                       for(NodeInfo n : nodes)
-                               if (!handler.canExecuteOnNode(n.object, tool))
-                                       return false;
-                       return true;
-               }
-               else
-               {
-                       return false;
-               }
-       }
-       
-       /**
-        * Check if given tool is applicable for all nodes in set
-        * 
-        * @param tool
-        * @param nodes
-        * @return
-        */
-       private static boolean isToolApplicable(ObjectTool tool, Set<NodeInfo> nodes)
-       {
-               for(NodeInfo n : nodes)
-                       if (!tool.isApplicableForNode(n.object))
-                               return false;
-               return true;
-       }
-       
-       /**
-        * Execute object tool on node set
-        * @param tool Object tool
-        */
-       private void executeObjectTool(final Set<NodeInfo> nodes, final ObjectTool tool)
-       {
-               if ((tool.getFlags() & ObjectTool.ASK_CONFIRMATION) != 0)
-               {
-                       String message = tool.getConfirmationText();
-                       if (nodes.size() == 1)
-                       {
-                          NodeInfo node = nodes.iterator().next();
-                               message = message.replace("%OBJECT_IP_ADDR%", node.object.getPrimaryIP().getHostAddress()); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_NAME%", node.object.getObjectName()); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_ID%", Long.toString(node.object.getObjectId())); //$NON-NLS-1$
-                       }
-                       else
-                       {
-                               message = message.replace("%OBJECT_IP_ADDR%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_NAME%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_ID%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
-                       }
-                       if (!MessageDialogHelper.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
-                                       Messages.get().ObjectToolsDynamicMenu_ConfirmExec, message))
-                               return;
-               }
-               
-               for(NodeInfo n : nodes)
-                       executeObjectToolOnNode(n, tool);
-       }
-       
-       /**
-        * Execute object tool on single node
-        * 
-        * @param node
-        * @param tool
-        */
-       private void executeObjectToolOnNode(final NodeInfo node, final ObjectTool tool)
-       {
-               switch(tool.getType())
-               {
-                       case ObjectTool.TYPE_INTERNAL:
-                               executeInternalTool(node, tool);
-                               break;
-                       case ObjectTool.TYPE_LOCAL_COMMAND:
-                               executeLocalCommand(node, tool);
-                               break;
-                       case ObjectTool.TYPE_SERVER_COMMAND:
-                               executeServerCommand(node, tool);
-                               break;
-                       case ObjectTool.TYPE_ACTION:
-                               executeAgentAction(node, tool);
-                               break;
-                       case ObjectTool.TYPE_TABLE_AGENT:
-                       case ObjectTool.TYPE_TABLE_SNMP:
-                               executeTableTool(node, tool);
-                               break;
-                       case ObjectTool.TYPE_URL:
-                               openURL(node, tool);
-                               break;
-                       case ObjectTool.TYPE_FILE_DOWNLOAD:
-                               executeFileDownload(node, tool);
-                               break;
-               }
-       }
-       
-       /**
-        * Execute table tool
-        * 
-        * @param node
-        * @param tool
-        */
-       private void executeTableTool(final NodeInfo node, final ObjectTool tool)
-       {
-               final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-               try
-               {
-                       final IWorkbenchPage page = window.getActivePage();
-                       final TableToolResults view = (TableToolResults)page.showView(TableToolResults.ID,
-                                       Long.toString(tool.getId()) + "&" + Long.toString(node.object.getObjectId()), IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$
-                       view.refreshTable();
-               }
-               catch(PartInitException e)
-               {
-                       MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
-               }
-       }
-
-       /**
-        * @param node
-        * @param tool
-        */
-       private void executeAgentAction(final NodeInfo node, final ObjectTool tool)
-       {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               final String action = substituteMacros(tool.getData(), node);
-               new ConsoleJob(String.format(Messages.get().ObjectToolsDynamicMenu_ExecuteOnNode, node.object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return String.format(Messages.get().ObjectToolsDynamicMenu_CannotExecuteOnNode, node.object.getObjectName());
-                       }
-
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.executeAction(node.object.getObjectId(), action);
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_ToolExecution, String.format(Messages.get().ObjectToolsDynamicMenu_ExecSuccess, action, node.object.getObjectName()));
-                                       }
-                               });
-                       }
-               }.start();
-       }
-
-       /**
-        * Execute server command
-        * 
-        * @param node
-        * @param tool
-        */
-       private void executeServerCommand(final NodeInfo node, final ObjectTool tool)
-       {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_ExecuteServerCmd, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.executeServerCommand(node.object.getObjectId(), tool.getData());
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_Information, Messages.get().ObjectToolsDynamicMenu_ServerCommandExecuted);
-                                       }
-                               });
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ObjectToolsDynamicMenu_ServerCmdExecError;
-                       }
-               }.start();
-       }
-       
-       /**
-        * Execute local command
-        * 
-        * @param node
-        * @param tool
-        */
-       private void executeLocalCommand(final NodeInfo node, final ObjectTool tool)
-       {
-               String command = substituteMacros(tool.getData(), node);
-               
-               if ((tool.getFlags() & ObjectTool.GENERATES_OUTPUT) == 0)
-               {
-                       final String os = Platform.getOS();
-                       
-                       try
-                       {
-                               if (os.equals(Platform.OS_WIN32))
-                               {
-                                       command = "CMD.EXE /C START \"NetXMS\" " + command; //$NON-NLS-1$
-                                       Runtime.getRuntime().exec(command);
-                               }
-                               else
-                               {
-                                       Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", command }); //$NON-NLS-1$ //$NON-NLS-2$
-                               }
-                       }
-                       catch(IOException e)
-                       {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       }
-               }
-               else
-               {
-                       final String secondaryId = Long.toString(node.object.getObjectId()) + "&" + Long.toString(tool.getId()); //$NON-NLS-1$
-                       final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-                       try
-                       {
-                               LocalCommandResults view = (LocalCommandResults)window.getActivePage().showView(LocalCommandResults.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
-                               view.runCommand(command);
-                       }
-                       catch(Exception e)
-                       {
-                               MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
-                       }
-               }
-       }
-
-       /**
-        * @param node
-        * @param tool
-        */
-       private void executeFileDownload(final NodeInfo node, final ObjectTool tool)
-       {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               String[] parameters = tool.getData().split("\u007F"); //$NON-NLS-1$
-               
-               final String fileName = parameters[0];
-               final int maxFileSize = Integer.parseInt(parameters[1]);
-               final boolean follow = parameters[2].equals("true") ? true : false; //$NON-NLS-1$
-               
-               ConsoleJob job = new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_DownloadFromAgent, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, fileName, node.object.getObjectName());
-                       }
-
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-            final AgentFile file = session.downloadFileFromAgent(node.object.getObjectId(), fileName, maxFileSize, follow);
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-                                               try
-                                               {
-                                                       String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
-                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
-                           IWorkbenchPage.VIEW_ACTIVATE);
-                     view.showFile(file.getFile(), follow, file.getId(), maxFileSize);
-                                               }
-                                               catch(Exception e)
-                                               {
-                                                       MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
-                                               }
-                                       }
-                               });
-                       }
-               };
-               job.start();
-       }
-
-       /**
-        * @param node
-        * @param tool
-        */
-       private void executeInternalTool(final NodeInfo node, final ObjectTool tool)
-       {
-               ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
-               if (handler != null)
-               {
-                       handler.execute(node.object, tool);
-               }
-               else
-               {
-                       MessageDialogHelper.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ObjectToolsDynamicMenu_Error, Messages.get().ObjectToolsDynamicMenu_HandlerNotDefined);
-               }
-       }
-
-       /**
-        * @param node
-        * @param tool
-        */
-       private void openURL(final NodeInfo node, final ObjectTool tool)
-       {
-               final String url = substituteMacros(tool.getData(), node);
-               
-               final String sid = Long.toString(node.object.getObjectId()) + "&" + Long.toString(tool.getId()); //$NON-NLS-1$
-               final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-               try
-               {
-                       BrowserView view = (BrowserView)window.getActivePage().showView(BrowserView.ID, sid, IWorkbenchPage.VIEW_ACTIVATE);
-                       view.openUrl(url);
-               }
-               catch(PartInitException e)
-               {
-                       MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, Messages.get().ObjectToolsDynamicMenu_CannotOpenWebBrowser + e.getLocalizedMessage());
-               }
-       }
-       
-       /**
-        * Substitute macros in string
-        * 
-        * @param s
-        * @param node
-        * @return
-        */
-       private static String substituteMacros(String s, NodeInfo node)
-       {
-               StringBuilder sb = new StringBuilder();
-               
-               char[] src = s.toCharArray();
-               for(int i = 0; i < s.length(); i++)
-               {
-                       if (src[i] == '%')
-                       {
-                               StringBuilder p = new StringBuilder();
-                               for(i++; src[i] != '%' && i < s.length(); i++)
-                                       p.append(src[i]);
-                               if (p.length() == 0)            // %%
-                               {
-                                       sb.append('%');
-                               }
-                               else
-                               {
-                                       String name = p.toString();
-                                       if (name.equals("OBJECT_IP_ADDR")) //$NON-NLS-1$
-                                       {
-                                               sb.append(node.object.getPrimaryIP().getHostAddress());
-                                       }
-                                       else if (name.equals("OBJECT_NAME")) //$NON-NLS-1$
-                                       {
-                                               sb.append(node.object.getObjectName());
-                                       }
-                                       else if (name.equals("OBJECT_ID")) //$NON-NLS-1$
-                                       {
-                                               sb.append(node.object.getObjectId());
-                                       }
-               else if (name.equals("ALARM_ID")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getId());
-               }
-               else if (name.equals("ALARM_MESSAGE")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getMessage());
-               }
-               else if (name.equals("ALARM_SEVERITY")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getCurrentSeverity());
-               }
-               else if (name.equals("ALARM_SEVERITY_TEXT")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(StatusDisplayInfo.getStatusText(node.alarm.getCurrentSeverity()));
-               }
-               else if (name.equals("ALARM_STATE")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getState());
-               }
-                                       else
-                                       {
-                                               String custAttr = node.object.getCustomAttributes().get(name);
-                                               if (custAttr != null)
-                                                       sb.append(custAttr);
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               sb.append(src[i]);
-                       }
-               }
-               
-               return sb.toString();
-       }
-       
-       /**
-        * Class to hold information about selected node
-        */
-       private class NodeInfo
-       {
-          AbstractNode object;
-          Alarm alarm;
-          
-      NodeInfo(AbstractNode object, Alarm alarm)
-      {
-         this.object = object;
-         this.alarm = alarm;
-      }
-
-      /* (non-Javadoc)
-       * @see java.lang.Object#hashCode()
-       */
-      @Override
-      public int hashCode()
-      {
-         final int prime = 31;
-         int result = 1;
-         result = prime * result + ObjectToolsDynamicMenu.this.hashCode();
-         result = prime * result + ((alarm == null) ? 0 : alarm.hashCode());
-         result = prime * result + ((object == null) ? 0 : object.hashCode());
-         return result;
-      }
-
-      /* (non-Javadoc)
-       * @see java.lang.Object#equals(java.lang.Object)
-       */
-      @Override
-      public boolean equals(Object obj)
-      {
-         if (this == obj)
-            return true;
-         if (obj == null)
-            return false;
-         if (getClass() != obj.getClass())
-            return false;
-         NodeInfo other = (NodeInfo)obj;
-         if ((other.object == null) || (this.object == null))
-            return (other.object == null) && (this.object == null);
-         return other.object.getObjectId() == this.object.getObjectId();
-      }
-       }
 }
diff --git a/src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/WakeupToolHandler.java b/src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/WakeupToolHandler.java
new file mode 100644 (file)
index 0000000..af42a7d
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2014 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.objecttools;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractNode;
+import org.netxms.client.objecttools.ObjectTool;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+
+/**
+ * Tool hand;er for "wakeup" internal tool
+ */
+public class WakeupToolHandler implements ObjectToolHandler
+{
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler#canExecuteOnNode(org.netxms.client.objects.AbstractNode, org.netxms.client.objecttools.ObjectTool)
+    */
+   @Override
+   public boolean canExecuteOnNode(AbstractNode node, ObjectTool tool)
+   {
+      return true;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler#execute(org.netxms.client.objects.AbstractNode, org.netxms.client.objecttools.ObjectTool)
+    */
+   @Override
+   public void execute(final AbstractNode node, ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      new ConsoleJob("Wakeup node", null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.wakeupNode(node.getObjectId());
+         }
+
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot send wake-on-LAN packet to node";
+         }
+      }.start();
+   }
+}
diff --git a/src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/NodeInfo.java b/src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/NodeInfo.java
new file mode 100644 (file)
index 0000000..55efb33
--- /dev/null
@@ -0,0 +1,50 @@
+package org.netxms.ui.eclipse.objecttools.api;
+
+import org.netxms.client.events.Alarm;
+import org.netxms.client.objects.AbstractNode;
+
+/**
+ * Class to hold information about selected node
+ */
+public class NodeInfo
+{
+   AbstractNode object;
+   Alarm alarm;
+   
+   public NodeInfo(AbstractNode object, Alarm alarm)
+   {
+      this.object = object;
+      this.alarm = alarm;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((alarm == null) ? 0 : alarm.hashCode());
+      result = prime * result + ((object == null) ? 0 : object.hashCode());
+      return result;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      NodeInfo other = (NodeInfo)obj;
+      if ((other.object == null) || (this.object == null))
+         return (other.object == null) && (this.object == null);
+      return other.object.getObjectId() == this.object.getObjectId();
+   }
+}
\ No newline at end of file
diff --git a/src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java b/src/java/netxms-eclipse/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java
new file mode 100644 (file)
index 0000000..7bb0552
--- /dev/null
@@ -0,0 +1,443 @@
+/**
+ * 
+ */
+package org.netxms.ui.eclipse.objecttools.api;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.Set;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.netxms.client.AgentFile;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objecttools.ObjectTool;
+import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objecttools.Activator;
+import org.netxms.ui.eclipse.objecttools.Messages;
+import org.netxms.ui.eclipse.objecttools.views.BrowserView;
+import org.netxms.ui.eclipse.objecttools.views.FileViewer;
+import org.netxms.ui.eclipse.objecttools.views.LocalCommandResults;
+import org.netxms.ui.eclipse.objecttools.views.TableToolResults;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+/**
+ * Executor for object tool
+ */
+public final class ObjectToolExecutor
+{
+   /**
+    * Private constructor to forbid instantiation 
+    */
+   private ObjectToolExecutor()
+   {
+   }
+   
+   /**
+    * Check if tool is allowed for execution on each node from set
+    * 
+    * @param tool
+    * @param nodes
+    * @return
+    */
+   public static boolean isToolAllowed(ObjectTool tool, Set<NodeInfo> nodes)
+   {
+      if (tool.getType() != ObjectTool.TYPE_INTERNAL)
+         return true;
+      
+      ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
+      if (handler != null)
+      {
+         for(NodeInfo n : nodes)
+            if (!handler.canExecuteOnNode(n.object, tool))
+               return false;
+         return true;
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   /**
+    * Check if given tool is applicable for all nodes in set
+    * 
+    * @param tool
+    * @param nodes
+    * @return
+    */
+   public static boolean isToolApplicable(ObjectTool tool, Set<NodeInfo> nodes)
+   {
+      for(NodeInfo n : nodes)
+         if (!tool.isApplicableForNode(n.object))
+            return false;
+      return true;
+   }
+   
+   /**
+    * Execute object tool on node set
+    * @param tool Object tool
+    */
+   public static void execute(final Set<NodeInfo> nodes, final ObjectTool tool)
+   {
+      if ((tool.getFlags() & ObjectTool.ASK_CONFIRMATION) != 0)
+      {
+         String message = tool.getConfirmationText();
+         if (nodes.size() == 1)
+         {
+            NodeInfo node = nodes.iterator().next();
+            message = message.replace("%OBJECT_IP_ADDR%", node.object.getPrimaryIP().getHostAddress()); //$NON-NLS-1$
+            message = message.replace("%OBJECT_NAME%", node.object.getObjectName()); //$NON-NLS-1$
+            message = message.replace("%OBJECT_ID%", Long.toString(node.object.getObjectId())); //$NON-NLS-1$
+         }
+         else
+         {
+            message = message.replace("%OBJECT_IP_ADDR%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
+            message = message.replace("%OBJECT_NAME%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
+            message = message.replace("%OBJECT_ID%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
+         }
+         if (!MessageDialogHelper.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
+               Messages.get().ObjectToolsDynamicMenu_ConfirmExec, message))
+            return;
+      }
+      
+      for(NodeInfo n : nodes)
+         executeOnNode(n, tool);
+   }
+   
+   /**
+    * Execute object tool on single node
+    * 
+    * @param node
+    * @param tool
+    */
+   private static void executeOnNode(final NodeInfo node, final ObjectTool tool)
+   {
+      switch(tool.getType())
+      {
+         case ObjectTool.TYPE_INTERNAL:
+            executeInternalTool(node, tool);
+            break;
+         case ObjectTool.TYPE_LOCAL_COMMAND:
+            executeLocalCommand(node, tool);
+            break;
+         case ObjectTool.TYPE_SERVER_COMMAND:
+            executeServerCommand(node, tool);
+            break;
+         case ObjectTool.TYPE_ACTION:
+            executeAgentAction(node, tool);
+            break;
+         case ObjectTool.TYPE_TABLE_AGENT:
+         case ObjectTool.TYPE_TABLE_SNMP:
+            executeTableTool(node, tool);
+            break;
+         case ObjectTool.TYPE_URL:
+            openURL(node, tool);
+            break;
+         case ObjectTool.TYPE_FILE_DOWNLOAD:
+            executeFileDownload(node, tool);
+            break;
+      }
+   }
+   
+   /**
+    * Execute table tool
+    * 
+    * @param node
+    * @param tool
+    */
+   private static void executeTableTool(final NodeInfo node, final ObjectTool tool)
+   {
+      final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+      try
+      {
+         final IWorkbenchPage page = window.getActivePage();
+         final TableToolResults view = (TableToolResults)page.showView(TableToolResults.ID,
+               Long.toString(tool.getId()) + "&" + Long.toString(node.object.getObjectId()), IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$
+         view.refreshTable();
+      }
+      catch(PartInitException e)
+      {
+         MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
+      }
+   }
+
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void executeAgentAction(final NodeInfo node, final ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      final String action = substituteMacros(tool.getData(), node);
+      new ConsoleJob(String.format(Messages.get().ObjectToolsDynamicMenu_ExecuteOnNode, node.object.getObjectName()), null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format(Messages.get().ObjectToolsDynamicMenu_CannotExecuteOnNode, node.object.getObjectName());
+         }
+
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.executeAction(node.object.getObjectId(), action);
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_ToolExecution, String.format(Messages.get().ObjectToolsDynamicMenu_ExecSuccess, action, node.object.getObjectName()));
+               }
+            });
+         }
+      }.start();
+   }
+
+   /**
+    * Execute server command
+    * 
+    * @param node
+    * @param tool
+    */
+   private static void executeServerCommand(final NodeInfo node, final ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_ExecuteServerCmd, null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.executeServerCommand(node.object.getObjectId(), tool.getData());
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_Information, Messages.get().ObjectToolsDynamicMenu_ServerCommandExecuted);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return Messages.get().ObjectToolsDynamicMenu_ServerCmdExecError;
+         }
+      }.start();
+   }
+   
+   /**
+    * Execute local command
+    * 
+    * @param node
+    * @param tool
+    */
+   private static void executeLocalCommand(final NodeInfo node, final ObjectTool tool)
+   {
+      String command = substituteMacros(tool.getData(), node);
+      
+      if ((tool.getFlags() & ObjectTool.GENERATES_OUTPUT) == 0)
+      {
+         final String os = Platform.getOS();
+         
+         try
+         {
+            if (os.equals(Platform.OS_WIN32))
+            {
+               command = "CMD.EXE /C START \"NetXMS\" " + command; //$NON-NLS-1$
+               Runtime.getRuntime().exec(command);
+            }
+            else
+            {
+               Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", command }); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+         }
+         catch(IOException e)
+         {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+         }
+      }
+      else
+      {
+         final String secondaryId = Long.toString(node.object.getObjectId()) + "&" + Long.toString(tool.getId()); //$NON-NLS-1$
+         final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+         try
+         {
+            LocalCommandResults view = (LocalCommandResults)window.getActivePage().showView(LocalCommandResults.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
+            view.runCommand(command);
+         }
+         catch(Exception e)
+         {
+            MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
+         }
+      }
+   }
+
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void executeFileDownload(final NodeInfo node, final ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      String[] parameters = tool.getData().split("\u007F"); //$NON-NLS-1$
+      
+      final String fileName = parameters[0];
+      final int maxFileSize = Integer.parseInt(parameters[1]);
+      final boolean follow = parameters[2].equals("true") ? true : false; //$NON-NLS-1$
+      
+      ConsoleJob job = new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_DownloadFromAgent, null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, fileName, node.object.getObjectName());
+         }
+
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final AgentFile file = session.downloadFileFromAgent(node.object.getObjectId(), fileName, maxFileSize, follow);
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+                  try
+                  {
+                     String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
+                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
+                           IWorkbenchPage.VIEW_ACTIVATE);
+                     view.showFile(file.getFile(), follow, file.getId(), maxFileSize);
+                  }
+                  catch(Exception e)
+                  {
+                     MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
+                  }
+               }
+            });
+         }
+      };
+      job.start();
+   }
+
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void executeInternalTool(final NodeInfo node, final ObjectTool tool)
+   {
+      ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
+      if (handler != null)
+      {
+         handler.execute(node.object, tool);
+      }
+      else
+      {
+         MessageDialogHelper.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ObjectToolsDynamicMenu_Error, Messages.get().ObjectToolsDynamicMenu_HandlerNotDefined);
+      }
+   }
+
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void openURL(final NodeInfo node, final ObjectTool tool)
+   {
+      final String url = substituteMacros(tool.getData(), node);
+      
+      final String sid = Long.toString(node.object.getObjectId()) + "&" + Long.toString(tool.getId()); //$NON-NLS-1$
+      final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+      try
+      {
+         BrowserView view = (BrowserView)window.getActivePage().showView(BrowserView.ID, sid, IWorkbenchPage.VIEW_ACTIVATE);
+         view.openUrl(url);
+      }
+      catch(PartInitException e)
+      {
+         MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, Messages.get().ObjectToolsDynamicMenu_CannotOpenWebBrowser + e.getLocalizedMessage());
+      }
+   }
+   
+   /**
+    * Substitute macros in string
+    * 
+    * @param s
+    * @param node
+    * @return
+    */
+   private static String substituteMacros(String s, NodeInfo node)
+   {
+      StringBuilder sb = new StringBuilder();
+      
+      char[] src = s.toCharArray();
+      for(int i = 0; i < s.length(); i++)
+      {
+         if (src[i] == '%')
+         {
+            StringBuilder p = new StringBuilder();
+            for(i++; src[i] != '%' && i < s.length(); i++)
+               p.append(src[i]);
+            if (p.length() == 0)    // %%
+            {
+               sb.append('%');
+            }
+            else
+            {
+               String name = p.toString();
+               if (name.equals("OBJECT_IP_ADDR")) //$NON-NLS-1$
+               {
+                  sb.append(node.object.getPrimaryIP().getHostAddress());
+               }
+               else if (name.equals("OBJECT_NAME")) //$NON-NLS-1$
+               {
+                  sb.append(node.object.getObjectName());
+               }
+               else if (name.equals("OBJECT_ID")) //$NON-NLS-1$
+               {
+                  sb.append(node.object.getObjectId());
+               }
+               else if (name.equals("ALARM_ID")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getId());
+               }
+               else if (name.equals("ALARM_MESSAGE")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getMessage());
+               }
+               else if (name.equals("ALARM_SEVERITY")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getCurrentSeverity());
+               }
+               else if (name.equals("ALARM_SEVERITY_TEXT")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(StatusDisplayInfo.getStatusText(node.alarm.getCurrentSeverity()));
+               }
+               else if (name.equals("ALARM_STATE")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getState());
+               }
+               else
+               {
+                  String custAttr = node.object.getCustomAttributes().get(name);
+                  if (custAttr != null)
+                     sb.append(custAttr);
+               }
+            }
+         }
+         else
+         {
+            sb.append(src[i]);
+         }
+      }
+      
+      return sb.toString();
+   }
+}
@@ -16,8 +16,9 @@
  * 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.objecttools;
+package org.netxms.ui.eclipse.objecttools.api;
 
+import java.io.ByteArrayInputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -25,12 +26,14 @@ 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.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.ImageData;
 import org.netxms.api.client.SessionNotification;
 import org.netxms.client.NXCListener;
 import org.netxms.client.NXCNotification;
 import org.netxms.client.NXCSession;
 import org.netxms.client.objecttools.ObjectTool;
-import org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler;
+import org.netxms.ui.eclipse.objecttools.Activator;
 
 /**
  * Cache for object tools
@@ -41,6 +44,7 @@ public class ObjectToolsCache
    private static ObjectToolsCache instance = null;
    
    private Map<Long, ObjectTool> objectTools = new HashMap<Long, ObjectTool>();
+   private Map<Long, ImageDescriptor> icons = new HashMap<Long, ImageDescriptor>();
        private NXCSession session = null;
        
        /**
@@ -137,11 +141,31 @@ public class ObjectToolsCache
                                        objectTools.put(tool.getId(), tool);
                                }
                        }
+                       synchronized(icons)
+         {
+                          icons.clear();
+                          
+            for(ObjectTool tool : list)
+            {
+               byte[] imageBytes = tool.getImageData();
+               if ((imageBytes == null) || (imageBytes.length == 0))
+                  continue;
+               
+               ByteArrayInputStream input = new ByteArrayInputStream(imageBytes);
+               try
+               {
+                  icons.put(tool.getId(), ImageDescriptor.createFromImageData(new ImageData(input)));
+               }
+               catch(Exception e)
+               {
+                  Activator.logError("Exception in ObjectToolsCache.reload()", e);
+               }
+            }
+         }
                }
                catch(Exception e)
                {
-                       e.printStackTrace();
-                       // TODO: add logging
+                  Activator.logError("Exception in ObjectToolsCache.reload()", e);
                }
        }
        
@@ -172,6 +196,10 @@ public class ObjectToolsCache
                {
                        objectTools.remove(toolId);
                }
+               synchronized(icons)
+      {
+                  icons.clear();
+      }
        }
        
        /**
@@ -198,12 +226,22 @@ public class ObjectToolsCache
         */
        public ObjectTool findTool(long toolId)
        {
-               ObjectTool tool;
                synchronized(objectTools)
                {
-                       tool = objectTools.get(toolId);
+                       return objectTools.get(toolId);
                }
-               return tool;
+       }
+       
+       /**
+        * @param toolId
+        * @return
+        */
+       public ImageDescriptor findIcon(long toolId)
+       {
+          synchronized(icons)
+      {
+         return icons.get(toolId);
+      }
        }
        
        /**
index bc166da..0aa064f 100644 (file)
@@ -49,7 +49,7 @@ import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.objecttools.Messages;
-import org.netxms.ui.eclipse.objecttools.ObjectToolsCache;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 
 /**
index db98197..6a6e818 100644 (file)
@@ -44,7 +44,7 @@ import org.netxms.ui.eclipse.actions.RefreshAction;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.objecttools.Messages;
-import org.netxms.ui.eclipse.objecttools.ObjectToolsCache;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.netxms.ui.eclipse.objecttools.views.helpers.TableContentProvider;
 import org.netxms.ui.eclipse.objecttools.views.helpers.TableItemComparator;
 import org.netxms.ui.eclipse.objecttools.views.helpers.TableLabelProvider;
index e0b0e57..6d34034 100644 (file)
@@ -2,13 +2,14 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NXMC Object Viewer Plug-in
 Bundle-SymbolicName: org.netxms.ui.eclipse.objectview;singleton:=true
-Bundle-Version: 1.2.14
+Bundle-Version: 1.2.15
 Bundle-Activator: org.netxms.ui.eclipse.objectview.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.ui;bundle-version="3.7.0",
  org.eclipse.core.runtime;bundle-version="3.7.0",
- org.netxms.ui.eclipse.console;bundle-version="1.2.13",
- org.netxms.ui.eclipse.charts;bundle-version="1.2.11"
+ org.netxms.ui.eclipse.console;bundle-version="1.2.15",
+ org.netxms.ui.eclipse.charts;bundle-version="1.2.11",
+ org.netxms.ui.eclipse.objecttools;bundle-version="1.2.15"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Export-Package: org.netxms.ui.eclipse.objectview.api,
index 868531c..a8a0446 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2013 Victor Kirhenshtein
+ * Copyright (C) 2003-2014 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
index e82b1cb..9647250 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2013 Victor Kirhenshtein
+ * Copyright (C) 2003-2014 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
  */
 package org.netxms.ui.eclipse.objectview.objecttabs.elements;
 
+import java.util.HashSet;
+import java.util.Set;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractNode;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Interface;
 import org.netxms.client.objects.Node;
+import org.netxms.client.objecttools.ObjectTool;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objecttools.api.NodeInfo;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolExecutor;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.netxms.ui.eclipse.objectview.Activator;
 import org.netxms.ui.eclipse.objectview.Messages;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.widgets.CommandBox;
 
 /**
@@ -40,9 +47,6 @@ import org.netxms.ui.eclipse.widgets.CommandBox;
 public class Commands extends OverviewPageElement
 {
        private CommandBox commandBox;
-       private Action actionRestartAgent;
-       private Action actionRestart;
-       private Action actionShutdown;
        private Action actionWakeup;
        
        /**
@@ -82,84 +86,6 @@ public class Commands extends OverviewPageElement
                        }
                };
                actionWakeup.setImageDescriptor(Activator.getImageDescriptor("icons/wol.png")); //$NON-NLS-1$
-               
-               actionRestartAgent = new Action(Messages.get().Commands_ActionRestartAgent) {
-                       @Override
-                       public void run()
-                       {
-                               final AbstractObject object = getObject();
-                               if (MessageDialogHelper.openQuestion(commandBox.getShell(), Messages.get().Commands_Confirmation, 
-                                     String.format(Messages.get().Commands_AgentRestartConfirmation, object.getObjectName())))
-                               {
-                                       new ConsoleJob(String.format(Messages.get().Commands_AgentRestartJobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                                               @Override
-                                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                                               {
-                                                       session.executeAction(object.getObjectId(), "Agent.Restart"); //$NON-NLS-1$
-                                               }
-       
-                                               @Override
-                                               protected String getErrorMessage()
-                                               {
-                                                       return String.format(Messages.get().Commands_AgentRestartJobError, object.getObjectName());
-                                               }
-                                       }.start();
-                               }
-                       }
-               };
-               actionRestartAgent.setImageDescriptor(Activator.getImageDescriptor("icons/restart.png")); //$NON-NLS-1$
-               
-               actionRestart = new Action(Messages.get().Commands_ActionRestartNode) {
-                       @Override
-                       public void run()
-                       {
-                               final AbstractObject object = getObject();
-                               if (MessageDialogHelper.openQuestion(commandBox.getShell(), Messages.get().Commands_Confirmation, 
-                  String.format(Messages.get().Commands_RestartNodeConfirmation, object.getObjectName())))
-                               {
-                                       new ConsoleJob(String.format(Messages.get().Commands_RestartNodeJobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                                               @Override
-                                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                                               {
-                                                       session.executeAction(object.getObjectId(), "System.Restart"); //$NON-NLS-1$
-                                               }
-       
-                                               @Override
-                                               protected String getErrorMessage()
-                                               {
-                                                       return String.format(Messages.get().Commands_RestartNodeJobError, object.getObjectName());
-                                               }
-                                       }.start();
-                               }
-                       }
-               };
-               actionRestart.setImageDescriptor(Activator.getImageDescriptor("icons/restart.png")); //$NON-NLS-1$
-               
-               actionShutdown = new Action(Messages.get().Commands_ActionShutdown) {
-                       @Override
-                       public void run()
-                       {
-                               final AbstractObject object = getObject();
-                               if (MessageDialogHelper.openQuestion(commandBox.getShell(), Messages.get().Commands_Confirmation, 
-                                     String.format(Messages.get().Commands_ShutdownConfirmation, object.getObjectName())))
-                               {
-                                       new ConsoleJob(String.format(Messages.get().Commands_ShutdownJobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                                               @Override
-                                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                                               {
-                                                       session.executeAction(object.getObjectId(), "System.Shutdown"); //$NON-NLS-1$
-                                               }
-       
-                                               @Override
-                                               protected String getErrorMessage()
-                                               {
-                                                       return String.format(Messages.get().Commands_ShutdownJobError, object.getObjectName());
-                                               }
-                                       }.start();
-                               }
-                       }
-               };
-               actionShutdown.setImageDescriptor(Activator.getImageDescriptor("icons/shutdown.png")); //$NON-NLS-1$
        }
 
        /* (non-Javadoc)
@@ -178,14 +104,31 @@ public class Commands extends OverviewPageElement
        protected void onObjectChange()
        {
                commandBox.deleteAll(false);
-               if (getObject() instanceof Node)
+               if (getObject() instanceof AbstractNode)
                {
-                       commandBox.add(actionWakeup, false);
-                       if (((Node)getObject()).hasAgent())
-                       {
-                               commandBox.add(actionRestart, false);
-                               commandBox.add(actionShutdown, false);
-                       }
+                  ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
+                  for(final ObjectTool tool : tools)
+                  {
+                     if (((tool.getFlags() & ObjectTool.SHOW_IN_COMMANDS) == 0) || !tool.isApplicableForNode((AbstractNode)getObject()))
+                        continue;
+
+            final Set<NodeInfo> nodes = new HashSet<NodeInfo>(1);
+            nodes.add(new NodeInfo((AbstractNode)getObject(), null));
+            if (!ObjectToolExecutor.isToolAllowed(tool, nodes))
+               continue;
+                     
+                     final Action action = new Action(tool.getCommandDisplayName()) {
+               @Override
+               public void run()
+               {
+                  ObjectToolExecutor.execute(nodes, tool);
+               }
+            };
+            ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tool.getId());
+            if (icon != null)
+               action.setImageDescriptor(icon);
+                commandBox.add(action, false);
+                  }
                }
                else if (getObject() instanceof Interface)
                {
index 4422b6b..07dc964 100644 (file)
@@ -3,7 +3,7 @@
 
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.netxms</groupId>
-  <version>1.2.14</version>
+  <version>1.2.15</version>
   <artifactId>netxms</artifactId>
   <packaging>pom</packaging>
   <name>NetXMS Meta-package</name>
index 5ddebb5..18f5195 100644 (file)
@@ -777,6 +777,28 @@ UINT32 CSCPMessage::GetVariableBinary(UINT32 fieldId, BYTE *pBuffer, UINT32 dwBu
 }
 
 /**
+ * get binary (byte array) field
+ * Returns pointer to internal buffer or NULL if field not found
+ * Data length set in size parameter.
+ */
+BYTE *CSCPMessage::getBinaryFieldPtr(UINT32 fieldId, size_t *size)
+{
+   BYTE *data;
+   void *value = get(fieldId, CSCP_DT_BINARY);
+   if (value != NULL)
+   {
+      *size = (size_t)(*((UINT32 *)value));
+      data = (BYTE *)value + 4;
+   }
+   else
+   {
+      *size = 0;
+      data = NULL;
+   }
+   return data;
+}
+
+/**
  * Build protocol message ready to be send over the wire
  */
 CSCP_MESSAGE *CSCPMessage::createMessage()
index d07ebd2..e174049 100644 (file)
@@ -738,9 +738,9 @@ char LIBNETXMS_EXPORTABLE *BinToStrA(const BYTE *pData, size_t size, char *pStr)
  * Convert string of hexadecimal digits to byte array (wide character version)
  * Returns number of bytes written to destination
  */
-UINT32 LIBNETXMS_EXPORTABLE StrToBinW(const WCHAR *pStr, BYTE *pData, UINT32 size)
+size_t LIBNETXMS_EXPORTABLE StrToBinW(const WCHAR *pStr, BYTE *pData, size_t size)
 {
-   UINT32 i;
+   size_t i;
    const WCHAR *pCurr;
 
    memset(pData, 0, size);
@@ -761,9 +761,9 @@ UINT32 LIBNETXMS_EXPORTABLE StrToBinW(const WCHAR *pStr, BYTE *pData, UINT32 siz
  * Convert string of hexadecimal digits to byte array (multibyte character version)
  * Returns number of bytes written to destination
  */
-UINT32 LIBNETXMS_EXPORTABLE StrToBinA(const char *pStr, BYTE *pData, UINT32 size)
+size_t LIBNETXMS_EXPORTABLE StrToBinA(const char *pStr, BYTE *pData, size_t size)
 {
-   UINT32 i;
+   size_t i;
    const char *pCurr;
 
    memset(pData, 0, size);
index 123e4e6..ca467c1 100644 (file)
@@ -660,8 +660,6 @@ UINT32 ChangeObjectToolStatus(UINT32 toolId, bool enabled)
  */
 UINT32 UpdateObjectToolFromMessage(CSCPMessage *pMsg)
 {
-   DB_RESULT hResult;
-   BOOL bUpdate = FALSE;
    TCHAR szBuffer[MAX_DB_STRING];
    UINT32 i, dwToolId, dwAclSize, *pdwAcl;
    DB_STATEMENT statment;
@@ -676,29 +674,17 @@ UINT32 UpdateObjectToolFromMessage(CSCPMessage *pMsg)
 
    // Check if tool already exist
    dwToolId = pMsg->GetVariableLong(VID_TOOL_ID);
-   statment = DBPrepare(hdb, _T("SELECT tool_id FROM object_tools WHERE tool_id=?"));
-   if (statment == NULL)
-      return ReturnDBFailure(hdb, statment);
-   DBBind(statment, 1, DB_SQLTYPE_INTEGER, dwToolId);
-
-   hResult = DBSelectPrepared(statment);
-   if (hResult != NULL)
-   {
-      if (DBGetNumRows(hResult) > 0)
-         bUpdate = TRUE;
-      DBFreeResult(hResult);
-   }
-   DBFreeStatement(statment);
+   bool doUpdate = IsDatabaseRecordExist(hdb, _T("object_tools"), _T("tool_id"), dwToolId);
 
    // Insert or update common properties
    /* prep */
    int nType = pMsg->GetVariableShort(VID_TOOL_TYPE);
    int bindID = 1;
-   if (bUpdate)
+   if (doUpdate)
    {
       statment = DBPrepare(hdb, _T("UPDATE object_tools SET tool_name=?,tool_type=?,")
                              _T("tool_data=?,description=?,flags=?,")
-                             _T("matching_oid=?,confirmation_text=? ")
+                             _T("matching_oid=?,confirmation_text=?,command_name=?,icon=? ")
                              _T("WHERE tool_id=?"));
       if (statment == NULL)
          return ReturnDBFailure(hdb, statment);
@@ -707,8 +693,8 @@ UINT32 UpdateObjectToolFromMessage(CSCPMessage *pMsg)
    {
       statment = DBPrepare(hdb, _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,")
                              _T("tool_data,description,flags,matching_oid,")
-                             _T("confirmation_text) VALUES ")
-                             _T("(?,?,?,?,?,?,?,?)"));
+                             _T("confirmation_text,command_name,icon) VALUES ")
+                             _T("(?,?,?,?,?,?,?,?,?,?)"));
       if (statment == NULL)
          return ReturnDBFailure(hdb, statment);
       DBBind(statment, bindID++, DB_SQLTYPE_INTEGER, dwToolId);
@@ -721,8 +707,23 @@ UINT32 UpdateObjectToolFromMessage(CSCPMessage *pMsg)
    DBBind(statment, bindID++, DB_SQLTYPE_INTEGER, pMsg->GetVariableLong(VID_FLAGS));
    DBBind(statment, bindID++, DB_SQLTYPE_VARCHAR, pMsg->GetVariableStr(VID_TOOL_OID), DB_BIND_DYNAMIC);
    DBBind(statment, bindID++, DB_SQLTYPE_VARCHAR, pMsg->GetVariableStr(VID_CONFIRMATION_TEXT), DB_BIND_DYNAMIC);
+   DBBind(statment, bindID++, DB_SQLTYPE_VARCHAR, pMsg->GetVariableStr(VID_COMMAND_NAME), DB_BIND_DYNAMIC);
+
+   size_t size;
+   BYTE *imageData = pMsg->getBinaryFieldPtr(VID_IMAGE_DATA, &size);
+   if (size > 0)
+   {
+      pMsg->GetVariableBinary(VID_IMAGE_DATA, imageData, (UINT32)size);
+      TCHAR *imageHexData = (TCHAR *)malloc((size + 1) * sizeof(TCHAR));
+      BinToStr(imageData, size, imageHexData);
+      DBBind(statment, bindID++, DB_SQLTYPE_TEXT, imageHexData, DB_BIND_DYNAMIC);
+   }
+   else
+   {
+      DBBind(statment, bindID++, DB_SQLTYPE_TEXT, _T(""), DB_BIND_STATIC);
+   }
 
-   if(bUpdate)
+   if(doUpdate)
       DBBind(statment, bindID++, DB_SQLTYPE_INTEGER, dwToolId);
 
    if(!DBExecute(statment))
index f51e4a6..4afd3b6 100644 (file)
@@ -7241,7 +7241,7 @@ void ClientSession::sendObjectTools(UINT32 dwRqId)
       }
       DBFreeResult(hResult);
 
-      hResult = DBSelect(hdb, _T("SELECT tool_id,tool_name,tool_type,tool_data,flags,description,matching_oid,confirmation_text FROM object_tools"));
+      hResult = DBSelect(hdb, _T("SELECT tool_id,tool_name,tool_type,tool_data,flags,description,matching_oid,confirmation_text,command_name,icon FROM object_tools"));
       if (hResult != NULL)
       {
          dwNumTools = DBGetNumRows(hResult);
@@ -7295,6 +7295,26 @@ void ClientSession::sendObjectTools(UINT32 dwRqId)
                DBGetField(hResult, i, 7, szBuffer, MAX_DB_STRING);
                msg.SetVariable(dwId + 7, szBuffer);
 
+               // command name
+               DBGetField(hResult, i, 8, szBuffer, MAX_DB_STRING);
+               msg.SetVariable(dwId + 8, szBuffer);
+
+               // icon
+               TCHAR *imageDataHex = DBGetField(hResult, i, 9, NULL, 0);
+               if (imageDataHex != NULL)
+               {
+                  size_t size = _tcslen(imageDataHex) / 2;
+                  BYTE *imageData = (BYTE *)malloc(size);
+                  size_t bytes = StrToBin(imageDataHex, imageData, size);
+                  msg.SetVariable(dwId + 9, imageData, (UINT32)bytes);
+                  free(imageData);
+                  free(imageDataHex);
+               }
+               else
+               {
+                  msg.SetVariable(dwId + 9, (BYTE *)NULL, 0);
+               }
+
                dwNumMsgRec++;
                dwId += 10;
             }
@@ -7340,7 +7360,7 @@ void ClientSession::sendObjectToolDetails(CSCPMessage *pRequest)
    {
 
       dwToolId = pRequest->GetVariableLong(VID_TOOL_ID);
-      DB_STATEMENT statment = DBPrepare(hdb, _T("SELECT tool_name,tool_type,tool_data,description,flags,matching_oid,confirmation_text FROM object_tools WHERE tool_id=?"));
+      DB_STATEMENT statment = DBPrepare(hdb, _T("SELECT tool_name,tool_type,tool_data,description,flags,matching_oid,confirmation_text,command_name,icon FROM object_tools WHERE tool_id=?"));
       if (statment == NULL)
          goto failure;
       DBBind(statment, 1, DB_SQLTYPE_INTEGER, dwToolId);
@@ -7373,6 +7393,25 @@ void ClientSession::sendObjectToolDetails(CSCPMessage *pRequest)
             DBGetField(hResult, 0, 6, szBuffer, MAX_DB_STRING);
             msg.SetVariable(VID_CONFIRMATION_TEXT, szBuffer);
 
+            DBGetField(hResult, 0, 7, szBuffer, MAX_DB_STRING);
+            msg.SetVariable(VID_COMMAND_NAME, szBuffer);
+
+            // icon
+            TCHAR *imageDataHex = DBGetField(hResult, 0, 8, NULL, 0);
+            if (imageDataHex != NULL)
+            {
+               size_t size = _tcslen(imageDataHex) / 2;
+               BYTE *imageData = (BYTE *)malloc(size);
+               size_t bytes = StrToBin(imageDataHex, imageData, size);
+               msg.SetVariable(VID_IMAGE_DATA, imageData, (UINT32)bytes);
+               free(imageData);
+               free(imageDataHex);
+            }
+            else
+            {
+               msg.SetVariable(VID_IMAGE_DATA, (BYTE *)NULL, 0);
+            }
+
             DBFreeResult(hResult);
 
             // Access list
index 3567d4f..d628a0c 100644 (file)
@@ -360,6 +360,23 @@ static BOOL RecreateTData(const TCHAR *className, bool multipleTables)
 }
 
 /**
+ * Upgrade from V318 to V319
+ */
+static BOOL H_UpgradeFromV318(int currVersion, int newVersion)
+{
+   static TCHAR batch[] =
+      _T("ALTER TABLE object_tools ADD icon $SQL:TEXT\n")
+      _T("ALTER TABLE object_tools ADD command_name varchar(255)\n")
+      _T("UPDATE object_tools SET flags=74,command_name='Shutdown system',icon='89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000000473424954080808087c086488000002bf49444154388d95933f689c7518c73fbf3f7779efaede995c137369d54123ba4843070b1204c10ed24db182939b90c1c1e2eee05871e8d0d2b98a8ba0c52ee2d0cb622acd99222dd1084d9a18cd3597f7bd6bdebbdffbfbe7701d82e8e0071ebec303dfe7e1e1fb883fea7542aba54c080dac153c261ed1a30540b51a8f359bd9c9e565afedd4943ab6b4f4d56873f38d5014ff6af04f95950aaad5fa7e7d7dfdbcee1d1c3cd95d59395b5a5c7c82ffc1fd4ee7acc9f349fd683090b1db15499ae2013b3f8f1c0e296f6f539c380140796707333747a856296d6ca081d1e1a138cc73a95d8cc28f468834459f3ecd7367cee0b38ccd7bf7787e711180dfaf5ee599850544a3c1760898d5556c51e06314d2c5288be150186b995d58404bc9eef5ebb87e86140229257690b17be33b4a4a3173ea14236b71d60a17a3901684b59652b34952ab31dcda6470f76794c9b0b6c0160665320eefae317ab04552ad529e9ec6c78003292dc861bf2f4408e369fb7b948a8cb2cd7085c115868998936887eb75514a617a3db66eb68505211d30f86b97dde536420844a341b17e8bf8db0a21ed12d23ddcda0ff46f7e4dac24482939b8b386b3060f4207206a457afb16be9f519f7f91f22baf52f9e91bfca7ef00829a4fb1af9fa3fed2cbf8419f6c75054a0a0fc800a025f151cafdcb17514af3ecc79f939fbf40d69c259d9ca1ffd687cc7d7411a5145b573e230e52d0120f68ffd8400ad8b97685c9934f31f9ee07b4de5e227ff37d8c311c4f12aad50afb5f5c62e7da65a400519204408f37108408de471e5cfa04fbe3b74c9d7b8ff2d32f1042805f7e25bdf1257fdeee103c8408528d53afa356c85a42b107d6812920bdd3c16f7448cae3d81a0b837cdc2b1c380f724203445d8ff161767cb66df1afe5380a0d3d05ca8d0f148110c02bb035b013109b1a17747b06baa20d3c84897dc93420feeb0b8f22203603dd19307f037f0665861328b32e0000000049454e44ae426082' WHERE tool_id=1\n")
+      _T("UPDATE object_tools SET flags=74,command_name='Restart system',icon='89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000000473424954080808087c0864880000029849444154388d85934d8b1c5514869f73eeadaaae6ea77bda388999882241fc5c0e09ae4484c4857b4177fa0b5474256edcfa075cbacbc23f6074a12332a0a2200a2189e8c468a23d93e99e9eaeaaae7beb1e1733f9902c7ce06c0ebc2f2fe7f0ca5fe311fdd71e77d93332922e08b749dcc5fe3bc9f72d5d1fcf861f7dd6f9f295353778ebdd0b71ff977374ad60f7888e1003bbb3379ceb930f4e7fbe7be5a7573da7f65697db17cf2ff2e757fe6e06a00e1141040aab59ebb5dc47076efbdb739cacc63edc9aabee4f64796248efb10dbcf738e750556268e97eff14b937ce6d1607126e55eae33c4956d5f4f72f21ae40d6cfe0bc4755c9f39cd4ccc0d27d7a695ae23c896fe7a645d5482c26340f0d19e639beb9811463c85788610a29c1d11d4284cc416a82848589861a49754bab390fac3f4ba69174f963ba7040d745249f4136033f63efd859769f78933a792c244265ea436d9a9a99e86895bc28b0e90fc03632bd88e463acb787580696f3e0fa299ade09e275a5feed2b09b5898f4ba35bdc40bb6b0034f5357cda4277bec354400d0b0d5d75406a5e42caa751d90596c425e22d00aa48771933a3c99e6230a8d1b241dcd1eb03a4a2c4563600f07615bc622da80510149aefa1b982ef3dc24d7d071b7afc71f0c781d58c83d107e48347d1f62a1a7f44f4d0c0130c4c4196d89fefa1273f215f7d9d4b379fa4dfdf22cb32bc7f99b5f533c45893edbc4fe75a8c0116c05b008b408434fd9a327f031b7d08c73670ee2c65595296259afe20fbe76de2fc9ba39e1cd6c6a7e4b0ae87d5200a4cbea4acce3318bd8865cfe1a283dd9fe9a65f901615a982d400c96360be9eda4ebbfdf0a6ec752f741ac11f1a89db02d9ba5bc8d483ae877587e2f0abdfac2b26b209488fa218b07627d7ff636dc524d52cff0513e53f37235ac3190000000049454e44ae426082' WHERE tool_id=2\n")
+      _T("UPDATE object_tools SET flags=64,command_name='Wakeup node using Wake-On-LAN',icon='89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000000473424954080808087c086488000000097048597300000dd700000dd70142289b780000001974455874536f667477617265007777772e696e6b73636170652e6f72679bee3c1a0000023649444154388d8d924f48545114c67ff7bd37ff7cf9071bc70a4d47271ca15c848d448185b40a89204890362d8568eb2270d7a2762d5cb7711504d1ae10c195218895a488528e4e06a653d338de7bdfbcf75ac84ce38c901f9ccdb9e7fbce39f77c627ce6872df6dd71f01f781e1d9c00866003215efaf99de7d6763afb1078721262053a800908ed5a5aa9b1e3bb0802a600c0717d3cdf3fae6cccd24a25abb302a80b990c265a009859d941299763249296d6b2a6732468d25a1f24156f00e0cbd62e9b5a71a0dd9a490cad14a570b4266c780cf546797cab1b1317139747435ddcec69266c78385a53c9b1b45265b548d022d51563f45a9c778b69ce35850058de928c0cb4933fd04c7ffece812e9639e5158480865098ebc9181fbfeef07a6e9dc68805c0af8243f45480ab174e33bb9426e7484a9b942710020c3b40e24c236f3facb1bd9b634d3a00d8e100ab992cb7af7421bc225aa9b280a195a414524972054d5f679488e5a394442949d8f4b8d4d14caea09115f55a490cad155a2b9452ecfdcef37e619ddef6287706ba89c76ce2319be1fe4e926d51663e6d90cdeda3d42147ebaa4fcc161da6a61739df52cfe88d8b0ca712f8be871d0e31bb94666a7a916c2e8feb7aff3cd33ef2f4c8612dd3a0a5d1a6bfa78d544f1bbeef33bf9a617e65939fb902c50a328068bd3bb10c1c71a3210401cb24143cbc82d2459c62ad8980154b2b3909bca87e91c09fea642d26ad67f7fb32afe6bebd5958dd1c2c48ddf45f8a10d87591bdcb89b3b3f7063a337f01f30f1c1c580292640000000049454e44ae426082' WHERE tool_id=3\n")
+      _T("<END>");
+   CHK_EXEC(SQLBatch(batch));
+   CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='319' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+/**
  * Upgrade from V317 to V318
  */
 static BOOL H_UpgradeFromV317(int currVersion, int newVersion)
@@ -7703,6 +7720,7 @@ static struct
    { 315, 316, H_UpgradeFromV315 },
    { 316, 317, H_UpgradeFromV316 },
    { 317, 318, H_UpgradeFromV317 },
+   { 318, 319, H_UpgradeFromV318 },
    { 0, 0, NULL }
 };
 
index ae056f7..86855bc 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry exported="true" kind="lib" path="jar/certificate-manager-1.2.14.jar"/>
-       <classpathentry exported="true" kind="lib" path="jar/netxms-base-1.2.14.jar"/>
-       <classpathentry exported="true" kind="lib" path="jar/netxms-client-1.2.14.jar"/>
-       <classpathentry exported="true" kind="lib" path="jar/netxms-client-api-1.2.14.jar"/>
+       <classpathentry exported="true" kind="lib" path="jar/certificate-manager-1.2.15.jar"/>
+       <classpathentry exported="true" kind="lib" path="jar/netxms-base-1.2.15.jar"/>
+       <classpathentry exported="true" kind="lib" path="jar/netxms-client-1.2.15.jar"/>
+       <classpathentry exported="true" kind="lib" path="jar/netxms-client-api-1.2.15.jar"/>
        <classpathentry exported="true" kind="lib" path="jar/simple-xml-2.6.4.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
index fa029f4..6622fe1 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NetXMS WebUI Core
 Bundle-SymbolicName: org.netxms.webui.core; singleton:=true
-Bundle-Version: 1.2.14
+Bundle-Version: 1.2.15
 Bundle-Activator: org.netxms.ui.eclipse.console.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
@@ -14,10 +14,10 @@ Import-Package: javax.servlet;version="2.5.0",
  javax.servlet.http;version="2.5.0"
 Bundle-ClassPath: .,
  jar/simple-xml-2.6.4.jar,
- jar/certificate-manager-1.2.14.jar,
- jar/netxms-base-1.2.14.jar,
- jar/netxms-client-1.2.14.jar,
- jar/netxms-client-api-1.2.14.jar
+ jar/certificate-manager-1.2.15.jar,
+ jar/netxms-base-1.2.15.jar,
+ jar/netxms-client-1.2.15.jar,
+ jar/netxms-client-api-1.2.15.jar
 Export-Package: org.netxms.api.client,
  org.netxms.api.client.constants,
  org.netxms.api.client.images,
index 57501b4..4b8e9d2 100644 (file)
@@ -8,7 +8,7 @@ bin.includes = plugin.xml,\
                theme/,\
                js/,\
                jar/,\
-               jar/certificate-manager-1.2.14.jar,\
-               jar/netxms-base-1.2.14.jar,\
-               jar/netxms-client-1.2.14.jar,\
-               jar/netxms-client-api-1.2.14.jar
+               jar/certificate-manager-1.2.15.jar,\
+               jar/netxms-base-1.2.15.jar,\
+               jar/netxms-client-1.2.15.jar,\
+               jar/netxms-client-api-1.2.15.jar
index bf15b1b..1fe4dce 100644 (file)
@@ -2,15 +2,15 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NXMC Object Tools plugin
 Bundle-SymbolicName: org.netxms.ui.eclipse.objecttools;singleton:=true
-Bundle-Version: 1.2.13
+Bundle-Version: 1.2.15
 Bundle-Activator: org.netxms.ui.eclipse.objecttools.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
  org.eclipse.core.expressions;bundle-version="3.4.401",
- org.netxms.ui.eclipse.usermanager;bundle-version="1.2.1",
- org.netxms.ui.eclipse.snmp;bundle-version="1.2.7",
+ org.netxms.ui.eclipse.usermanager;bundle-version="1.2.14",
+ org.netxms.ui.eclipse.snmp;bundle-version="1.2.12",
  org.eclipse.rap.ui;bundle-version="2.0.0",
- org.netxms.webui.core;bundle-version="1.2.13"
+ org.netxms.webui.core;bundle-version="1.2.15"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Export-Package: org.netxms.ui.eclipse.objecttools.api
index 61e3264..337e301 100644 (file)
             class="org.netxms.ui.eclipse.objecttools.LoginListener">
       </loginlistener>
    </extension>
+   <extension
+         point="org.netxms.ui.eclipse.objecttools.toolhandlers">
+      <handler
+            class="org.netxms.ui.eclipse.objecttools.WakeupToolHandler"
+            id="wakeup">
+      </handler>
+   </extension>
 
 </plugin>
index 5b071b0..60d6a21 100644 (file)
  */
 package org.netxms.ui.eclipse.objecttools;
 
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -88,4 +90,35 @@ public class Activator extends AbstractUIPlugin
        {
                return imageDescriptorFromPlugin(PLUGIN_ID, path);
        }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logInfo(String msg)
+   {
+      log(Status.INFO, msg, null);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logError(String msg, Throwable t)
+   {
+      log(Status.ERROR, msg, t);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    * @param t
+    */
+   public static void log(int status, String msg, Throwable t)
+   {
+      getDefault().getLog().log(new Status(status, PLUGIN_ID, Status.OK, msg, t));
+   }
 }
index c8a2c4e..c757680 100644 (file)
@@ -21,6 +21,7 @@ package org.netxms.ui.eclipse.objecttools;
 import org.eclipse.swt.widgets.Display;
 import org.netxms.client.NXCSession;
 import org.netxms.ui.eclipse.console.api.ConsoleLoginListener;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 
 /**
  * Early startup class
index ba307ab..18cc75d 100644 (file)
  */
 package org.netxms.ui.eclipse.objecttools;
 
-import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.rap.rwt.RWT;
-import org.eclipse.rap.rwt.client.service.UrlLauncher;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.MenuItem;
 import org.eclipse.ui.ISources;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.menus.IWorkbenchContribution;
 import org.eclipse.ui.services.IEvaluationService;
 import org.eclipse.ui.services.IServiceLocator;
-import org.netxms.client.AgentFile;
 import org.netxms.client.NXCSession;
 import org.netxms.client.events.Alarm;
 import org.netxms.client.objects.AbstractNode;
@@ -53,13 +47,11 @@ import org.netxms.client.objects.Container;
 import org.netxms.client.objects.ServiceRoot;
 import org.netxms.client.objects.Subnet;
 import org.netxms.client.objecttools.ObjectTool;
-import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler;
-import org.netxms.ui.eclipse.objecttools.views.FileViewer;
-import org.netxms.ui.eclipse.objecttools.views.TableToolResults;
+import org.netxms.ui.eclipse.objecttools.api.NodeInfo;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolExecutor;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.ImageCache;
 
 /**
  * Dynamic object tools menu creator
@@ -108,6 +100,15 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                final Set<NodeInfo> nodes = buildNodeSet((IStructuredSelection)selection);
                final Menu toolsMenu = new Menu(menu);
                
+               final ImageCache imageCache = new ImageCache();
+               toolsMenu.addDisposeListener(new DisposeListener() {
+         @Override
+         public void widgetDisposed(DisposeEvent e)
+         {
+            imageCache.dispose();
+         }
+      });
+               
                ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
                Arrays.sort(tools, new Comparator<ObjectTool>() {
                        @Override
@@ -122,7 +123,7 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                for(int i = 0; i < tools.length; i++)
                {
                        boolean enabled = (tools[i].getFlags() & ObjectTool.DISABLED) == 0;
-                       if (enabled && isToolAllowed(tools[i], nodes) && isToolApplicable(tools[i], nodes))
+                       if (enabled && ObjectToolExecutor.isToolAllowed(tools[i], nodes) && ObjectToolExecutor.isToolApplicable(tools[i], nodes))
                        {
                                String[] path = tools[i].getName().split("\\-\\>"); //$NON-NLS-1$
                        
@@ -144,12 +145,15 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                                
                                final MenuItem item = new MenuItem(rootMenu, SWT.PUSH);
                                item.setText(path[path.length - 1]);
+                               ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tools[i].getId());
+                               if (icon != null)
+                                  item.setImage(imageCache.add(icon));
                                item.setData(tools[i]);
                                item.addSelectionListener(new SelectionAdapter() {
                                        @Override
                                        public void widgetSelected(SelectionEvent e)
                                        {
-                                               executeObjectTool(nodes, (ObjectTool)item.getData());
+                                          ObjectToolExecutor.execute(nodes, (ObjectTool)item.getData());
                                        }
                                });
                                
@@ -200,397 +204,4 @@ public class ObjectToolsDynamicMenu extends ContributionItem implements IWorkben
                }
                return nodes;
        }
-       
-       /**
-        * Check if tool is allowed for execution on each node from set
-        * 
-        * @param tool
-        * @param nodes
-        * @return
-        */
-       private static boolean isToolAllowed(ObjectTool tool, Set<NodeInfo> nodes)
-       {
-               if (tool.getType() != ObjectTool.TYPE_INTERNAL)
-                       return true;
-               
-               ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
-               if (handler != null)
-               {
-                       for(NodeInfo n : nodes)
-                               if (!handler.canExecuteOnNode(n.object, tool))
-                                       return false;
-                       return true;
-               }
-               else
-               {
-                       return false;
-               }
-       }
-       
-       /**
-        * Check if given tool is applicable for all nodes in set
-        * 
-        * @param tool
-        * @param nodes
-        * @return
-        */
-       private static boolean isToolApplicable(ObjectTool tool, Set<NodeInfo> nodes)
-       {
-               for(NodeInfo n : nodes)
-                       if (!tool.isApplicableForNode(n.object))
-                               return false;
-               return true;
-       }
-       
-       /**
-        * Execute object tool on node set
-        * @param tool Object tool
-        */
-       private void executeObjectTool(final Set<NodeInfo> nodes, final ObjectTool tool)
-       {
-               if ((tool.getFlags() & ObjectTool.ASK_CONFIRMATION) != 0)
-               {
-                       String message = tool.getConfirmationText();
-                       if (nodes.size() == 1)
-                       {
-                          NodeInfo node = nodes.iterator().next();
-                               message = message.replace("%OBJECT_IP_ADDR%", node.object.getPrimaryIP().getHostAddress()); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_NAME%", node.object.getObjectName()); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_ID%", Long.toString(node.object.getObjectId())); //$NON-NLS-1$
-                       }
-                       else
-                       {
-                               message = message.replace("%OBJECT_IP_ADDR%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_NAME%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
-                               message = message.replace("%OBJECT_ID%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
-                       }
-                       if (!MessageDialogHelper.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
-                                       Messages.get().ObjectToolsDynamicMenu_ConfirmExec, message))
-                               return;
-               }
-               
-               for(NodeInfo n : nodes)
-                       executeObjectToolOnNode(n, tool);
-       }
-       
-       /**
-        * Execute object tool on single node
-        * 
-        * @param node
-        * @param tool
-        */
-       private void executeObjectToolOnNode(final NodeInfo node, final ObjectTool tool)
-       {
-               switch(tool.getType())
-               {
-                       case ObjectTool.TYPE_INTERNAL:
-                               executeInternalTool(node, tool);
-                               break;
-                       case ObjectTool.TYPE_LOCAL_COMMAND:
-                               // local commands cannot be executed via browser
-                               //executeLocalCommand(node, tool);
-                               break;
-                       case ObjectTool.TYPE_SERVER_COMMAND:
-                               executeServerCommand(node, tool);
-                               break;
-                       case ObjectTool.TYPE_ACTION:
-                               executeAgentAction(node, tool);
-                               break;
-                       case ObjectTool.TYPE_TABLE_AGENT:
-                       case ObjectTool.TYPE_TABLE_SNMP:
-                               executeTableTool(node, tool);
-                               break;
-                       case ObjectTool.TYPE_URL:
-                               openURL(node, tool);
-                               break;
-                       case ObjectTool.TYPE_FILE_DOWNLOAD:
-                               executeFileDownload(node, tool);
-                               break;
-               }
-       }
-       
-       /**
-        * Execute table tool
-        * 
-        * @param node
-        * @param tool
-        */
-       private void executeTableTool(final NodeInfo node, final ObjectTool tool)
-       {
-               final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-               try
-               {
-                       final IWorkbenchPage page = window.getActivePage();
-                       final TableToolResults view = (TableToolResults)page.showView(TableToolResults.ID,
-                                       Long.toString(tool.getId()) + "&" + Long.toString(node.object.getObjectId()), IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$
-                       view.refreshTable();
-               }
-               catch(PartInitException e)
-               {
-                       MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
-               }
-       }
-
-       /**
-        * @param node
-        * @param tool
-        */
-       private void executeAgentAction(final NodeInfo node, final ObjectTool tool)
-       {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               final String action = substituteMacros(tool.getData(), node);
-               new ConsoleJob(String.format(Messages.get().ObjectToolsDynamicMenu_ExecuteOnNode, node.object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return String.format(Messages.get().ObjectToolsDynamicMenu_CannotExecuteOnNode, node.object.getObjectName());
-                       }
-
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.executeAction(node.object.getObjectId(), action);
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_ToolExecution, String.format(Messages.get().ObjectToolsDynamicMenu_ExecSuccess, action, node.object.getObjectName()));
-                                       }
-                               });
-                       }
-               }.start();
-       }
-
-       /**
-        * Execute server command
-        * 
-        * @param node
-        * @param tool
-        */
-       private void executeServerCommand(final NodeInfo node, final ObjectTool tool)
-       {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_ExecuteServerCmd, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.executeServerCommand(node.object.getObjectId(), tool.getData());
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_Information, Messages.get().ObjectToolsDynamicMenu_ServerCommandExecuted);
-                                       }
-                               });
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ObjectToolsDynamicMenu_ServerCmdExecError;
-                       }
-               }.start();
-       }
-       
-       /**
-        * @param node
-        * @param tool
-        */
-       private void executeFileDownload(final NodeInfo node, final ObjectTool tool)
-       {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               String[] parameters = tool.getData().split("\u007F"); //$NON-NLS-1$
-               
-               final String fileName = parameters[0];
-               final int maxFileSize = Integer.parseInt(parameters[1]);
-               final boolean follow = parameters[2].equals("true") ? true : false; //$NON-NLS-1$
-               
-               ConsoleJob job = new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_DownloadFromAgent, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, fileName, node.object.getObjectName());
-                       }
-
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-            final AgentFile file = session.downloadFileFromAgent(node.object.getObjectId(), fileName, maxFileSize, follow);
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-                                               try
-                                               {
-                                                       String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
-                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
-                           IWorkbenchPage.VIEW_ACTIVATE);
-                     view.showFile(file.getFile(), follow, file.getId(), maxFileSize);
-                                               }
-                                               catch(Exception e)
-                                               {
-                                                       MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
-                                               }
-                                       }
-                               });
-                       }
-               };
-               job.start();
-       }
-
-       /**
-        * @param node
-        * @param tool
-        */
-       private void executeInternalTool(final NodeInfo node, final ObjectTool tool)
-       {
-               ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
-               if (handler != null)
-               {
-                       handler.execute(node.object, tool);
-               }
-               else
-               {
-                       MessageDialogHelper.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ObjectToolsDynamicMenu_Error, Messages.get().ObjectToolsDynamicMenu_HandlerNotDefined);
-               }
-       }
-
-       /**
-        * @param node
-        * @param tool
-        */
-       private void openURL(final NodeInfo node, final ObjectTool tool)
-       {
-               final String url = substituteMacros(tool.getData(), node);
-      final UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
-      launcher.openURL(url);
-       }
-       
-       /**
-        * Substitute macros in string
-        * 
-        * @param s
-        * @param node
-        * @return
-        */
-       private static String substituteMacros(String s, NodeInfo node)
-       {
-               StringBuilder sb = new StringBuilder();
-               
-               char[] src = s.toCharArray();
-               for(int i = 0; i < s.length(); i++)
-               {
-                       if (src[i] == '%')
-                       {
-                               StringBuilder p = new StringBuilder();
-                               for(i++; src[i] != '%' && i < s.length(); i++)
-                                       p.append(src[i]);
-                               if (p.length() == 0)            // %%
-                               {
-                                       sb.append('%');
-                               }
-                               else
-                               {
-                                       String name = p.toString();
-                                       if (name.equals("OBJECT_IP_ADDR")) //$NON-NLS-1$
-                                       {
-                                               sb.append(node.object.getPrimaryIP().getHostAddress());
-                                       }
-                                       else if (name.equals("OBJECT_NAME")) //$NON-NLS-1$
-                                       {
-                                               sb.append(node.object.getObjectName());
-                                       }
-                                       else if (name.equals("OBJECT_ID")) //$NON-NLS-1$
-                                       {
-                                               sb.append(node.object.getObjectId());
-                                       }
-               else if (name.equals("ALARM_ID")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getId());
-               }
-               else if (name.equals("ALARM_MESSAGE")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getMessage());
-               }
-               else if (name.equals("ALARM_SEVERITY")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getCurrentSeverity());
-               }
-               else if (name.equals("ALARM_SEVERITY_TEXT")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(StatusDisplayInfo.getStatusText(node.alarm.getCurrentSeverity()));
-               }
-               else if (name.equals("ALARM_STATE")) //$NON-NLS-1$
-               {
-                  if (node.alarm != null)
-                     sb.append(node.alarm.getState());
-               }
-                                       else
-                                       {
-                                               String custAttr = node.object.getCustomAttributes().get(name);
-                                               if (custAttr != null)
-                                                       sb.append(custAttr);
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               sb.append(src[i]);
-                       }
-               }
-               
-               return sb.toString();
-       }
-       
-       /**
-        * Class to hold information about selected node
-        */
-       private class NodeInfo
-       {
-          AbstractNode object;
-          Alarm alarm;
-          
-      NodeInfo(AbstractNode object, Alarm alarm)
-      {
-         this.object = object;
-         this.alarm = alarm;
-      }
-
-      /* (non-Javadoc)
-       * @see java.lang.Object#hashCode()
-       */
-      @Override
-      public int hashCode()
-      {
-         final int prime = 31;
-         int result = 1;
-         result = prime * result + ObjectToolsDynamicMenu.this.hashCode();
-         result = prime * result + ((alarm == null) ? 0 : alarm.hashCode());
-         result = prime * result + ((object == null) ? 0 : object.hashCode());
-         return result;
-      }
-
-      /* (non-Javadoc)
-       * @see java.lang.Object#equals(java.lang.Object)
-       */
-      @Override
-      public boolean equals(Object obj)
-      {
-         if (this == obj)
-            return true;
-         if (obj == null)
-            return false;
-         if (getClass() != obj.getClass())
-            return false;
-         NodeInfo other = (NodeInfo)obj;
-         if ((other.object == null) || (this.object == null))
-            return (other.object == null) && (this.object == null);
-         return other.object.getObjectId() == this.object.getObjectId();
-      }
-       }
 }
diff --git a/webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/WakeupToolHandler.java b/webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/WakeupToolHandler.java
new file mode 100644 (file)
index 0000000..af42a7d
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2014 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.objecttools;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractNode;
+import org.netxms.client.objecttools.ObjectTool;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+
+/**
+ * Tool hand;er for "wakeup" internal tool
+ */
+public class WakeupToolHandler implements ObjectToolHandler
+{
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler#canExecuteOnNode(org.netxms.client.objects.AbstractNode, org.netxms.client.objecttools.ObjectTool)
+    */
+   @Override
+   public boolean canExecuteOnNode(AbstractNode node, ObjectTool tool)
+   {
+      return true;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler#execute(org.netxms.client.objects.AbstractNode, org.netxms.client.objecttools.ObjectTool)
+    */
+   @Override
+   public void execute(final AbstractNode node, ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      new ConsoleJob("Wakeup node", null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.wakeupNode(node.getObjectId());
+         }
+
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot send wake-on-LAN packet to node";
+         }
+      }.start();
+   }
+}
diff --git a/webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/NodeInfo.java b/webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/NodeInfo.java
new file mode 100644 (file)
index 0000000..55efb33
--- /dev/null
@@ -0,0 +1,50 @@
+package org.netxms.ui.eclipse.objecttools.api;
+
+import org.netxms.client.events.Alarm;
+import org.netxms.client.objects.AbstractNode;
+
+/**
+ * Class to hold information about selected node
+ */
+public class NodeInfo
+{
+   AbstractNode object;
+   Alarm alarm;
+   
+   public NodeInfo(AbstractNode object, Alarm alarm)
+   {
+      this.object = object;
+      this.alarm = alarm;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((alarm == null) ? 0 : alarm.hashCode());
+      result = prime * result + ((object == null) ? 0 : object.hashCode());
+      return result;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      NodeInfo other = (NodeInfo)obj;
+      if ((other.object == null) || (this.object == null))
+         return (other.object == null) && (this.object == null);
+      return other.object.getObjectId() == this.object.getObjectId();
+   }
+}
\ No newline at end of file
diff --git a/webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java b/webui/webapp/ObjectTools/src/org/netxms/ui/eclipse/objecttools/api/ObjectToolExecutor.java
new file mode 100644 (file)
index 0000000..8b49f7b
--- /dev/null
@@ -0,0 +1,380 @@
+/**
+ * 
+ */
+package org.netxms.ui.eclipse.objecttools.api;
+
+import java.net.URLEncoder;
+import java.util.Set;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.rap.rwt.RWT;
+import org.eclipse.rap.rwt.client.service.UrlLauncher;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.netxms.client.AgentFile;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objecttools.ObjectTool;
+import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objecttools.Activator;
+import org.netxms.ui.eclipse.objecttools.Messages;
+import org.netxms.ui.eclipse.objecttools.views.FileViewer;
+import org.netxms.ui.eclipse.objecttools.views.TableToolResults;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+/**
+ * Executor for object tool
+ */
+public final class ObjectToolExecutor
+{
+   /**
+    * Private constructor to forbid instantiation 
+    */
+   private ObjectToolExecutor()
+   {
+   }
+   
+   /**
+    * Check if tool is allowed for execution on each node from set
+    * 
+    * @param tool
+    * @param nodes
+    * @return
+    */
+   public static boolean isToolAllowed(ObjectTool tool, Set<NodeInfo> nodes)
+   {
+      if (tool.getType() != ObjectTool.TYPE_INTERNAL)
+         return true;
+      
+      ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
+      if (handler != null)
+      {
+         for(NodeInfo n : nodes)
+            if (!handler.canExecuteOnNode(n.object, tool))
+               return false;
+         return true;
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   /**
+    * Check if given tool is applicable for all nodes in set
+    * 
+    * @param tool
+    * @param nodes
+    * @return
+    */
+   public static boolean isToolApplicable(ObjectTool tool, Set<NodeInfo> nodes)
+   {
+      for(NodeInfo n : nodes)
+         if (!tool.isApplicableForNode(n.object))
+            return false;
+      return true;
+   }
+   
+   /**
+    * Execute object tool on node set
+    * @param tool Object tool
+    */
+   public static void execute(final Set<NodeInfo> nodes, final ObjectTool tool)
+   {
+      if ((tool.getFlags() & ObjectTool.ASK_CONFIRMATION) != 0)
+      {
+         String message = tool.getConfirmationText();
+         if (nodes.size() == 1)
+         {
+            NodeInfo node = nodes.iterator().next();
+            message = message.replace("%OBJECT_IP_ADDR%", node.object.getPrimaryIP().getHostAddress()); //$NON-NLS-1$
+            message = message.replace("%OBJECT_NAME%", node.object.getObjectName()); //$NON-NLS-1$
+            message = message.replace("%OBJECT_ID%", Long.toString(node.object.getObjectId())); //$NON-NLS-1$
+         }
+         else
+         {
+            message = message.replace("%OBJECT_IP_ADDR%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
+            message = message.replace("%OBJECT_NAME%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
+            message = message.replace("%OBJECT_ID%", Messages.get().ObjectToolsDynamicMenu_MultipleNodes); //$NON-NLS-1$
+         }
+         if (!MessageDialogHelper.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
+               Messages.get().ObjectToolsDynamicMenu_ConfirmExec, message))
+            return;
+      }
+      
+      for(NodeInfo n : nodes)
+         executeOnNode(n, tool);
+   }
+   
+   /**
+    * Execute object tool on single node
+    * 
+    * @param node
+    * @param tool
+    */
+   private static void executeOnNode(final NodeInfo node, final ObjectTool tool)
+   {
+      switch(tool.getType())
+      {
+         case ObjectTool.TYPE_INTERNAL:
+            executeInternalTool(node, tool);
+            break;
+         case ObjectTool.TYPE_SERVER_COMMAND:
+            executeServerCommand(node, tool);
+            break;
+         case ObjectTool.TYPE_ACTION:
+            executeAgentAction(node, tool);
+            break;
+         case ObjectTool.TYPE_TABLE_AGENT:
+         case ObjectTool.TYPE_TABLE_SNMP:
+            executeTableTool(node, tool);
+            break;
+         case ObjectTool.TYPE_URL:
+            openURL(node, tool);
+            break;
+         case ObjectTool.TYPE_FILE_DOWNLOAD:
+            executeFileDownload(node, tool);
+            break;
+      }
+   }
+   
+   /**
+    * Execute table tool
+    * 
+    * @param node
+    * @param tool
+    */
+   private static void executeTableTool(final NodeInfo node, final ObjectTool tool)
+   {
+      final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+      try
+      {
+         final IWorkbenchPage page = window.getActivePage();
+         final TableToolResults view = (TableToolResults)page.showView(TableToolResults.ID,
+               Long.toString(tool.getId()) + "&" + Long.toString(node.object.getObjectId()), IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$
+         view.refreshTable();
+      }
+      catch(PartInitException e)
+      {
+         MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
+      }
+   }
+
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void executeAgentAction(final NodeInfo node, final ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      final String action = substituteMacros(tool.getData(), node);
+      new ConsoleJob(String.format(Messages.get().ObjectToolsDynamicMenu_ExecuteOnNode, node.object.getObjectName()), null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format(Messages.get().ObjectToolsDynamicMenu_CannotExecuteOnNode, node.object.getObjectName());
+         }
+
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.executeAction(node.object.getObjectId(), action);
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_ToolExecution, String.format(Messages.get().ObjectToolsDynamicMenu_ExecSuccess, action, node.object.getObjectName()));
+               }
+            });
+         }
+      }.start();
+   }
+
+   /**
+    * Execute server command
+    * 
+    * @param node
+    * @param tool
+    */
+   private static void executeServerCommand(final NodeInfo node, final ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_ExecuteServerCmd, null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.executeServerCommand(node.object.getObjectId(), tool.getData());
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_Information, Messages.get().ObjectToolsDynamicMenu_ServerCommandExecuted);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return Messages.get().ObjectToolsDynamicMenu_ServerCmdExecError;
+         }
+      }.start();
+   }
+   
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void executeFileDownload(final NodeInfo node, final ObjectTool tool)
+   {
+      final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+      String[] parameters = tool.getData().split("\u007F"); //$NON-NLS-1$
+      
+      final String fileName = parameters[0];
+      final int maxFileSize = Integer.parseInt(parameters[1]);
+      final boolean follow = parameters[2].equals("true") ? true : false; //$NON-NLS-1$
+      
+      ConsoleJob job = new ConsoleJob(Messages.get().ObjectToolsDynamicMenu_DownloadFromAgent, null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format(Messages.get().ObjectToolsDynamicMenu_DownloadError, fileName, node.object.getObjectName());
+         }
+
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final AgentFile file = session.downloadFileFromAgent(node.object.getObjectId(), fileName, maxFileSize, follow);
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+                  try
+                  {
+                     String secondaryId = Long.toString(node.object.getObjectId()) + "&" + URLEncoder.encode(fileName, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
+                     FileViewer view = (FileViewer)window.getActivePage().showView(FileViewer.ID, secondaryId,
+                           IWorkbenchPage.VIEW_ACTIVATE);
+                     view.showFile(file.getFile(), follow, file.getId(), maxFileSize);
+                  }
+                  catch(Exception e)
+                  {
+                     MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
+                  }
+               }
+            });
+         }
+      };
+      job.start();
+   }
+
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void executeInternalTool(final NodeInfo node, final ObjectTool tool)
+   {
+      ObjectToolHandler handler = ObjectToolsCache.findHandler(tool.getData());
+      if (handler != null)
+      {
+         handler.execute(node.object, tool);
+      }
+      else
+      {
+         MessageDialogHelper.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.get().ObjectToolsDynamicMenu_Error, Messages.get().ObjectToolsDynamicMenu_HandlerNotDefined);
+      }
+   }
+
+   /**
+    * @param node
+    * @param tool
+    */
+   private static void openURL(final NodeInfo node, final ObjectTool tool)
+   {
+      final String url = substituteMacros(tool.getData(), node);
+      final UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
+      launcher.openURL(url);
+   }
+   
+   /**
+    * Substitute macros in string
+    * 
+    * @param s
+    * @param node
+    * @return
+    */
+   private static String substituteMacros(String s, NodeInfo node)
+   {
+      StringBuilder sb = new StringBuilder();
+      
+      char[] src = s.toCharArray();
+      for(int i = 0; i < s.length(); i++)
+      {
+         if (src[i] == '%')
+         {
+            StringBuilder p = new StringBuilder();
+            for(i++; src[i] != '%' && i < s.length(); i++)
+               p.append(src[i]);
+            if (p.length() == 0)    // %%
+            {
+               sb.append('%');
+            }
+            else
+            {
+               String name = p.toString();
+               if (name.equals("OBJECT_IP_ADDR")) //$NON-NLS-1$
+               {
+                  sb.append(node.object.getPrimaryIP().getHostAddress());
+               }
+               else if (name.equals("OBJECT_NAME")) //$NON-NLS-1$
+               {
+                  sb.append(node.object.getObjectName());
+               }
+               else if (name.equals("OBJECT_ID")) //$NON-NLS-1$
+               {
+                  sb.append(node.object.getObjectId());
+               }
+               else if (name.equals("ALARM_ID")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getId());
+               }
+               else if (name.equals("ALARM_MESSAGE")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getMessage());
+               }
+               else if (name.equals("ALARM_SEVERITY")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getCurrentSeverity());
+               }
+               else if (name.equals("ALARM_SEVERITY_TEXT")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(StatusDisplayInfo.getStatusText(node.alarm.getCurrentSeverity()));
+               }
+               else if (name.equals("ALARM_STATE")) //$NON-NLS-1$
+               {
+                  if (node.alarm != null)
+                     sb.append(node.alarm.getState());
+               }
+               else
+               {
+                  String custAttr = node.object.getCustomAttributes().get(name);
+                  if (custAttr != null)
+                     sb.append(custAttr);
+               }
+            }
+         }
+         else
+         {
+            sb.append(src[i]);
+         }
+      }
+      
+      return sb.toString();
+   }
+}
@@ -16,8 +16,9 @@
  * 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.objecttools;
+package org.netxms.ui.eclipse.objecttools.api;
 
+import java.io.ByteArrayInputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -25,13 +26,15 @@ 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.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.widgets.Display;
 import org.netxms.api.client.SessionNotification;
 import org.netxms.client.NXCListener;
 import org.netxms.client.NXCNotification;
 import org.netxms.client.NXCSession;
 import org.netxms.client.objecttools.ObjectTool;
-import org.netxms.ui.eclipse.objecttools.api.ObjectToolHandler;
+import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 
 /**
@@ -42,6 +45,7 @@ public class ObjectToolsCache
    private static Map<String, ObjectToolHandler> handlers = new HashMap<String, ObjectToolHandler>();
    
    private Map<Long, ObjectTool> objectTools = new HashMap<Long, ObjectTool>();
+   private Map<Long, ImageDescriptor> icons = new HashMap<Long, ImageDescriptor>();
        private NXCSession session = null;
        
        /**
@@ -140,11 +144,31 @@ public class ObjectToolsCache
                                                objectTools.put(tool.getId(), tool);
                                }
                        }
+                       synchronized(icons)
+         {
+                          icons.clear();
+                          
+            for(ObjectTool tool : list)
+            {
+               byte[] imageBytes = tool.getImageData();
+               if ((imageBytes == null) || (imageBytes.length == 0))
+                  continue;
+               
+               ByteArrayInputStream input = new ByteArrayInputStream(imageBytes);
+               try
+               {
+                  icons.put(tool.getId(), ImageDescriptor.createFromImageData(new ImageData(input)));
+               }
+               catch(Exception e)
+               {
+                  Activator.logError("Exception in ObjectToolsCache.reload()", e);
+               }
+            }
+         }
                }
                catch(Exception e)
                {
-                       e.printStackTrace();
-                       // TODO: add logging
+                  Activator.logError("Exception in ObjectToolsCache.reload()", e);
                }
        }
        
@@ -175,6 +199,10 @@ public class ObjectToolsCache
                {
                        objectTools.remove(toolId);
                }
+               synchronized(icons)
+      {
+                  icons.clear();
+      }
        }
        
        /**
@@ -201,12 +229,22 @@ public class ObjectToolsCache
         */
        public ObjectTool findTool(long toolId)
        {
-               ObjectTool tool;
                synchronized(objectTools)
                {
-                       tool = objectTools.get(toolId);
+                       return objectTools.get(toolId);
+               }
+       }
+       
+       /**
+        * @param toolId
+        * @return
+        */
+       public ImageDescriptor findIcon(long toolId)
+       {
+          synchronized(icons)
+      {
+         return icons.get(toolId);
                }
-               return tool;
        }
        
        /**
index db98197..6a6e818 100644 (file)
@@ -44,7 +44,7 @@ import org.netxms.ui.eclipse.actions.RefreshAction;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objecttools.Activator;
 import org.netxms.ui.eclipse.objecttools.Messages;
-import org.netxms.ui.eclipse.objecttools.ObjectToolsCache;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.netxms.ui.eclipse.objecttools.views.helpers.TableContentProvider;
 import org.netxms.ui.eclipse.objecttools.views.helpers.TableItemComparator;
 import org.netxms.ui.eclipse.objecttools.views.helpers.TableLabelProvider;
index 68501c4..63f6742 100644 (file)
@@ -2,12 +2,13 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NXMC Object Viewer Plug-in
 Bundle-SymbolicName: org.netxms.ui.eclipse.objectview;singleton:=true
-Bundle-Version: 1.2.14
+Bundle-Version: 1.2.15
 Bundle-Activator: org.netxms.ui.eclipse.objectview.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.netxms.ui.eclipse.charts;bundle-version="1.2.11",
- org.netxms.webui.core;bundle-version="1.2.13",
- org.eclipse.rap.ui;bundle-version="2.2.0"
+ org.netxms.webui.core;bundle-version="1.2.15",
+ org.eclipse.rap.ui;bundle-version="2.2.0",
+ org.netxms.ui.eclipse.objecttools;bundle-version="1.2.15"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Export-Package: org.netxms.ui.eclipse.objectview.api,
index d265a19..7bb99d2 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2013 Victor Kirhenshtein
+ * Copyright (C) 2003-2014 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
index e82b1cb..b6b361d 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2013 Victor Kirhenshtein
+ * Copyright (C) 2003-2014 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
  */
 package org.netxms.ui.eclipse.objectview.objecttabs.elements;
 
+import java.util.HashSet;
+import java.util.Set;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractNode;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Interface;
 import org.netxms.client.objects.Node;
+import org.netxms.client.objecttools.ObjectTool;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objecttools.api.NodeInfo;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolExecutor;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
 import org.netxms.ui.eclipse.objectview.Activator;
 import org.netxms.ui.eclipse.objectview.Messages;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.widgets.CommandBox;
 
 /**
@@ -40,9 +47,6 @@ import org.netxms.ui.eclipse.widgets.CommandBox;
 public class Commands extends OverviewPageElement
 {
        private CommandBox commandBox;
-       private Action actionRestartAgent;
-       private Action actionRestart;
-       private Action actionShutdown;
        private Action actionWakeup;
        
        /**
@@ -82,84 +86,6 @@ public class Commands extends OverviewPageElement
                        }
                };
                actionWakeup.setImageDescriptor(Activator.getImageDescriptor("icons/wol.png")); //$NON-NLS-1$
-               
-               actionRestartAgent = new Action(Messages.get().Commands_ActionRestartAgent) {
-                       @Override
-                       public void run()
-                       {
-                               final AbstractObject object = getObject();
-                               if (MessageDialogHelper.openQuestion(commandBox.getShell(), Messages.get().Commands_Confirmation, 
-                                     String.format(Messages.get().Commands_AgentRestartConfirmation, object.getObjectName())))
-                               {
-                                       new ConsoleJob(String.format(Messages.get().Commands_AgentRestartJobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                                               @Override
-                                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                                               {
-                                                       session.executeAction(object.getObjectId(), "Agent.Restart"); //$NON-NLS-1$
-                                               }
-       
-                                               @Override
-                                               protected String getErrorMessage()
-                                               {
-                                                       return String.format(Messages.get().Commands_AgentRestartJobError, object.getObjectName());
-                                               }
-                                       }.start();
-                               }
-                       }
-               };
-               actionRestartAgent.setImageDescriptor(Activator.getImageDescriptor("icons/restart.png")); //$NON-NLS-1$
-               
-               actionRestart = new Action(Messages.get().Commands_ActionRestartNode) {
-                       @Override
-                       public void run()
-                       {
-                               final AbstractObject object = getObject();
-                               if (MessageDialogHelper.openQuestion(commandBox.getShell(), Messages.get().Commands_Confirmation, 
-                  String.format(Messages.get().Commands_RestartNodeConfirmation, object.getObjectName())))
-                               {
-                                       new ConsoleJob(String.format(Messages.get().Commands_RestartNodeJobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                                               @Override
-                                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                                               {
-                                                       session.executeAction(object.getObjectId(), "System.Restart"); //$NON-NLS-1$
-                                               }
-       
-                                               @Override
-                                               protected String getErrorMessage()
-                                               {
-                                                       return String.format(Messages.get().Commands_RestartNodeJobError, object.getObjectName());
-                                               }
-                                       }.start();
-                               }
-                       }
-               };
-               actionRestart.setImageDescriptor(Activator.getImageDescriptor("icons/restart.png")); //$NON-NLS-1$
-               
-               actionShutdown = new Action(Messages.get().Commands_ActionShutdown) {
-                       @Override
-                       public void run()
-                       {
-                               final AbstractObject object = getObject();
-                               if (MessageDialogHelper.openQuestion(commandBox.getShell(), Messages.get().Commands_Confirmation, 
-                                     String.format(Messages.get().Commands_ShutdownConfirmation, object.getObjectName())))
-                               {
-                                       new ConsoleJob(String.format(Messages.get().Commands_ShutdownJobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
-                                               @Override
-                                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                                               {
-                                                       session.executeAction(object.getObjectId(), "System.Shutdown"); //$NON-NLS-1$
-                                               }
-       
-                                               @Override
-                                               protected String getErrorMessage()
-                                               {
-                                                       return String.format(Messages.get().Commands_ShutdownJobError, object.getObjectName());
-                                               }
-                                       }.start();
-                               }
-                       }
-               };
-               actionShutdown.setImageDescriptor(Activator.getImageDescriptor("icons/shutdown.png")); //$NON-NLS-1$
        }
 
        /* (non-Javadoc)
@@ -178,13 +104,30 @@ public class Commands extends OverviewPageElement
        protected void onObjectChange()
        {
                commandBox.deleteAll(false);
-               if (getObject() instanceof Node)
+               if (getObject() instanceof AbstractNode)
                {
-                       commandBox.add(actionWakeup, false);
-                       if (((Node)getObject()).hasAgent())
+                  ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
+                  for(final ObjectTool tool : tools)
                        {
-                               commandBox.add(actionRestart, false);
-                               commandBox.add(actionShutdown, false);
+                     if (((tool.getFlags() & ObjectTool.SHOW_IN_COMMANDS) == 0) || !tool.isApplicableForNode((AbstractNode)getObject()))
+                        continue;
+                     
+            final Set<NodeInfo> nodes = new HashSet<NodeInfo>(1);
+            nodes.add(new NodeInfo((AbstractNode)getObject(), null));
+            if (!ObjectToolExecutor.isToolAllowed(tool, nodes))
+               continue;
+                     
+                     final Action action = new Action(tool.getCommandDisplayName()) {
+               @Override
+               public void run()
+               {
+                  ObjectToolExecutor.execute(nodes, tool);
+               }
+            };
+            ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tool.getId());
+            if (icon != null)
+               action.setImageDescriptor(icon);
+                commandBox.add(action, false);
                        }
                }
                else if (getObject() instanceof Interface)