object tools can be exported (no import yet)
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 24 Apr 2015 09:04:05 +0000 (12:04 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 24 Apr 2015 09:04:05 +0000 (12:04 +0300)
include/nxdbapi.h
src/db/libnxdb/session.cpp
src/java/netxms-eclipse/ServerConfig/META-INF/MANIFEST.MF
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ObjectToolSelectionDialog.java [new file with mode: 0644]
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ExportFileBuilder.java
src/server/core/objtools.cpp
webui/webapp/ObjectTools/META-INF/MANIFEST.MF
webui/webapp/ServerConfig/META-INF/MANIFEST.MF
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ObjectToolSelectionDialog.java [new file with mode: 0644]
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ExportFileBuilder.java

index 8fb9814..b256e69 100644 (file)
@@ -145,7 +145,8 @@ bool LIBNXDB_EXPORTABLE DBGetColumnName(DB_RESULT hResult, int column, TCHAR *bu
 int LIBNXDB_EXPORTABLE DBGetNumRows(DB_RESULT hResult);
 void LIBNXDB_EXPORTABLE DBFreeResult(DB_RESULT hResult);
 
-TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn, TCHAR *pszBuffer, int nBufLen);
+TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int row, int col, TCHAR *pszBuffer, int nBufLen);
+TCHAR LIBNXDB_EXPORTABLE *DBGetFieldForXML(DB_RESULT hResult, int row, int col);
 char LIBNXDB_EXPORTABLE *DBGetFieldA(DB_RESULT hResult, int iRow, int iColumn, char *pszBuffer, int nBufLen);
 char LIBNXDB_EXPORTABLE *DBGetFieldUTF8(DB_RESULT hResult, int iRow, int iColumn, char *pszBuffer, int nBufLen);
 INT32 LIBNXDB_EXPORTABLE DBGetFieldLong(DB_RESULT hResult, int iRow, int iColumn);
index 0f889fb..23875d6 100644 (file)
@@ -552,6 +552,18 @@ char LIBNXDB_EXPORTABLE *DBGetFieldA(DB_RESULT hResult, int iRow, int iColumn, c
    return pszRet;
 }
 
+/**
+ * Get text field and escape it for XML document. Returned string
+ * always dynamically allocated and must be destroyed by caller.
+ */
+TCHAR LIBNXDB_EXPORTABLE *DBGetFieldForXML(DB_RESULT hResult, int row, int col)
+{
+   TCHAR *value = DBGetField(hResult, row, col, NULL, 0);
+   TCHAR *xmlString = EscapeStringForXML(value, -1);
+   safe_free(value);
+   return xmlString;
+}
+
 /**
  * Get field's value as unsigned long
  */
index a152eaf..a8632bc 100644 (file)
@@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
  org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.3",
  org.netxms.ui.eclipse.filemanager;bundle-version="2.0.1",
  org.netxms.ui.eclipse.nxsl;bundle-version="2.0.0",
- org.netxms.ui.eclipse.epp;bundle-version="2.0.0"
+ org.netxms.ui.eclipse.epp;bundle-version="2.0.0",
+ org.netxms.ui.eclipse.objecttools;bundle-version="2.0.3"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
diff --git a/src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ObjectToolSelectionDialog.java b/src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ObjectToolSelectionDialog.java
new file mode 100644 (file)
index 0000000..0e65ec4
--- /dev/null
@@ -0,0 +1,110 @@
+/**
+ * 
+ */
+package org.netxms.ui.eclipse.serverconfig.dialogs;
+
+import java.util.List;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.netxms.client.objecttools.ObjectTool;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+
+/**
+ * Object tool selection dialog
+ */
+public class ObjectToolSelectionDialog extends Dialog
+{
+   private TableViewer viewer;
+   private List<ObjectTool> selection;
+   
+   /**
+    * @param parentShell
+    */
+   public ObjectToolSelectionDialog(Shell parentShell)
+   {
+      super(parentShell);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+    */
+   @Override
+   protected void configureShell(Shell newShell)
+   {
+      super.configureShell(newShell);
+      newShell.setText("Select Object Tool");
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   protected Control createDialogArea(Composite parent)
+   {
+      final Composite dialogArea = (Composite)super.createDialogArea(parent);
+      
+      GridLayout layout = new GridLayout();
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
+      dialogArea.setLayout(layout);
+      
+      viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
+      viewer.setContentProvider(new ArrayContentProvider());
+      viewer.setLabelProvider(new LabelProvider() {
+         @Override
+         public String getText(Object element)
+         {
+            return ((ObjectTool)element).getName();
+         }
+      });
+      viewer.setComparator(new ViewerComparator() {
+         @Override
+         public int compare(Viewer viewer, Object e1, Object e2)
+         {
+            return ((ObjectTool)e1).getName().compareToIgnoreCase(((ObjectTool)e2).getName());
+         }
+      });
+      viewer.setInput(ObjectToolsCache.getInstance().getTools());
+      
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.verticalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.grabExcessVerticalSpace = true;
+      gd.heightHint = 400;
+      viewer.getControl().setLayoutData(gd);
+      
+      return dialogArea;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+    */
+   @SuppressWarnings("unchecked")
+   @Override
+   protected void okPressed()
+   {
+      selection = ((IStructuredSelection)viewer.getSelection()).toList();
+      super.okPressed();
+   }
+
+   /**
+    * @return the selection
+    */
+   public List<ObjectTool> getSelection()
+   {
+      return selection;
+   }
+}
index 4cd17f3..3eafb3e 100644 (file)
@@ -73,6 +73,7 @@ import org.netxms.ui.eclipse.nxsl.dialogs.SelectScriptDialog;
 import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.Activator;
 import org.netxms.ui.eclipse.serverconfig.Messages;
+import org.netxms.ui.eclipse.serverconfig.dialogs.ObjectToolSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.SelectSnmpTrapDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.helpers.TrapListLabelProvider;
 import org.netxms.ui.eclipse.serverconfig.views.helpers.RuleComparator;
@@ -606,6 +607,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
          @Override
          public void linkActivated(HyperlinkEvent e)
          {
+            addObjectTools();
          }
       });
       
@@ -1102,4 +1104,19 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
          setModified();
       }
    }
+   
+   /**
+    * Add oject tools to list
+    */
+   private void addObjectTools()
+   {
+      ObjectToolSelectionDialog dlg = new ObjectToolSelectionDialog(getSite().getShell());
+      if (dlg.open() == Window.OK)
+      {
+         for(ObjectTool t : dlg.getSelection())
+            tools.put(t.getId(), t);
+         toolsViewer.setInput(tools.values().toArray());
+         setModified();
+      }
+   }
 }
index cb4b3a4..aa28854 100644 (file)
@@ -791,15 +791,15 @@ void CreateObjectToolExportRecord(String &xml, UINT32 id)
 {
    DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
 
-   DB_STATEMENT statment = DBPrepare(hdb, _T("SELECT tool_name,tool_type,tool_data,description,flags,tool_filter,confirmation_text,command_name,command_short_name,icon FROM object_tools WHERE tool_id=?"));
-   if (statment == NULL)
+   DB_STATEMENT hStmt = DBPrepare(hdb, _T("SELECT tool_name,tool_type,tool_data,description,flags,tool_filter,confirmation_text,command_name,command_short_name,icon FROM object_tools WHERE tool_id=?"));
+   if (hStmt == NULL)
    {
       DBConnectionPoolReleaseConnection(hdb);
       return;
    }
 
-   DBBind(statment, 1, DB_SQLTYPE_INTEGER, id);
-   hResult = DBSelectPrepared(statment);
+   DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
+   DB_RESULT hResult = DBSelectPrepared(hStmt);
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -807,14 +807,30 @@ void CreateObjectToolExportRecord(String &xml, UINT32 id)
          xml.append(_T("\t\t<objectTool id=\""));
          xml.append(id);
          xml.append(_T("\">\n\t\t\t<name>"));
-         xml.appendPreallocated(DBGetField(hResult, 0, 0, NULL, 0));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 0));
          xml.append(_T("</name>\n\t\t\t<type>"));
          xml.append(DBGetFieldLong(hResult, 0, 1));
          xml.append(_T("</type>\n\t\t\t<data>"));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 2));
+         xml.append(_T("</data>\n\t\t\t<description>"));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 3));
+         xml.append(_T("</description>\n\t\t\t<flags>"));
+         xml.append(DBGetFieldLong(hResult, 0, 4));
+         xml.append(_T("</flags>\n\t\t\t<filter>"));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 5));
+         xml.append(_T("</filter>\n\t\t\t<confirmation>"));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 6));
+         xml.append(_T("</confirmation>\n\t\t\t<commandName>"));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 7));
+         xml.append(_T("</commandName>\n\t\t\t<commandShortName>"));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 8));
+         xml.append(_T("</commandShortName>\n\t\t\t<icon>"));
+         xml.appendPreallocated(DBGetFieldForXML(hResult, 0, 9));
+         xml.append(_T("</icon>\n\t\t</objectTool>\n"));
       }
       DBFreeResult(hResult);
    }
 
-   DBFreeStatement(statement);
+   DBFreeStatement(hStmt);
    DBConnectionPoolReleaseConnection(hdb);
 }
index 69aab14..c3a5caa 100644 (file)
@@ -2,14 +2,14 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NXMC Object Tools plugin
 Bundle-SymbolicName: org.netxms.ui.eclipse.objecttools;singleton:=true
-Bundle-Version: 2.0.1
+Bundle-Version: 2.0.4
 Bundle-Activator: org.netxms.ui.eclipse.objecttools.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.rap.ui;bundle-version="2.3.1",
  org.eclipse.core.runtime;bundle-version="3.8.0",
  org.eclipse.core.expressions;bundle-version="3.4.401",
- org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.0",
- org.netxms.webui.core;bundle-version="2.0.0",
+ org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.4",
+ org.netxms.webui.core;bundle-version="2.0.4",
  org.netxms.ui.eclipse.usermanager;bundle-version="2.0.0",
  org.netxms.ui.eclipse.snmp;bundle-version="2.0.0",
  org.eclipse.rap.addons.filedialog;bundle-version="0.6.0"
index 02d9a58..0894d61 100644 (file)
@@ -5,16 +5,17 @@ Bundle-SymbolicName: org.netxms.ui.eclipse.serverconfig;singleton:=true
 Bundle-Version: 2.0.4
 Bundle-Activator: org.netxms.ui.eclipse.serverconfig.Activator
 Bundle-Vendor: netxms.org
-Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.10.0",
  org.eclipse.rap.ui;bundle-version="2.3.1",
  org.eclipse.rap.ui.forms;bundle-version="2.3.1",
  org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.4",
  org.netxms.webui.core;bundle-version="2.0.4",
  org.netxms.ui.eclipse.filemanager;bundle-version="2.0.1",
  org.netxms.ui.eclipse.eventmanager;bundle-version="2.0.0",
- org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.0",
+ org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.3",
  org.netxms.ui.eclipse.nxsl;bundle-version="2.0.0",
  org.netxms.ui.eclipse.epp;bundle-version="2.0.0",
- org.eclipse.rap.addons.filedialog;bundle-version="0.6.0"
+ org.eclipse.rap.addons.filedialog;bundle-version="0.6.0",
+ org.netxms.ui.eclipse.objecttools;bundle-version="2.0.4"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
diff --git a/webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ObjectToolSelectionDialog.java b/webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ObjectToolSelectionDialog.java
new file mode 100644 (file)
index 0000000..0e65ec4
--- /dev/null
@@ -0,0 +1,110 @@
+/**
+ * 
+ */
+package org.netxms.ui.eclipse.serverconfig.dialogs;
+
+import java.util.List;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.netxms.client.objecttools.ObjectTool;
+import org.netxms.ui.eclipse.objecttools.api.ObjectToolsCache;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+
+/**
+ * Object tool selection dialog
+ */
+public class ObjectToolSelectionDialog extends Dialog
+{
+   private TableViewer viewer;
+   private List<ObjectTool> selection;
+   
+   /**
+    * @param parentShell
+    */
+   public ObjectToolSelectionDialog(Shell parentShell)
+   {
+      super(parentShell);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+    */
+   @Override
+   protected void configureShell(Shell newShell)
+   {
+      super.configureShell(newShell);
+      newShell.setText("Select Object Tool");
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   protected Control createDialogArea(Composite parent)
+   {
+      final Composite dialogArea = (Composite)super.createDialogArea(parent);
+      
+      GridLayout layout = new GridLayout();
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
+      dialogArea.setLayout(layout);
+      
+      viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
+      viewer.setContentProvider(new ArrayContentProvider());
+      viewer.setLabelProvider(new LabelProvider() {
+         @Override
+         public String getText(Object element)
+         {
+            return ((ObjectTool)element).getName();
+         }
+      });
+      viewer.setComparator(new ViewerComparator() {
+         @Override
+         public int compare(Viewer viewer, Object e1, Object e2)
+         {
+            return ((ObjectTool)e1).getName().compareToIgnoreCase(((ObjectTool)e2).getName());
+         }
+      });
+      viewer.setInput(ObjectToolsCache.getInstance().getTools());
+      
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.verticalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.grabExcessVerticalSpace = true;
+      gd.heightHint = 400;
+      viewer.getControl().setLayoutData(gd);
+      
+      return dialogArea;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+    */
+   @SuppressWarnings("unchecked")
+   @Override
+   protected void okPressed()
+   {
+      selection = ((IStructuredSelection)viewer.getSelection()).toList();
+      super.okPressed();
+   }
+
+   /**
+    * @return the selection
+    */
+   public List<ObjectTool> getSelection()
+   {
+      return selection;
+   }
+}
index a6ba23a..4ede57d 100644 (file)
@@ -76,6 +76,7 @@ import org.netxms.ui.eclipse.nxsl.dialogs.SelectScriptDialog;
 import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.Activator;
 import org.netxms.ui.eclipse.serverconfig.Messages;
+import org.netxms.ui.eclipse.serverconfig.dialogs.ObjectToolSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.SelectSnmpTrapDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.helpers.TrapListLabelProvider;
 import org.netxms.ui.eclipse.serverconfig.views.helpers.RuleComparator;
@@ -608,6 +609,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
          @Override
          public void linkActivated(HyperlinkEvent e)
          {
+            addObjectTools();
          }
       });
       
@@ -1096,4 +1098,19 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
                        setModified();
                }
        }
+   
+   /**
+    * Add oject tools to list
+    */
+   private void addObjectTools()
+   {
+      ObjectToolSelectionDialog dlg = new ObjectToolSelectionDialog(getSite().getShell());
+      if (dlg.open() == Window.OK)
+      {
+         for(ObjectTool t : dlg.getSelection())
+            tools.put(t.getId(), t);
+         toolsViewer.setInput(tools.values().toArray());
+         setModified();
+      }
+   }
 }