Apply policy to node by clicking on node and selecting policies from list fixes #69
authorEriks Jenkevics <eriks@netxms.org>
Mon, 5 Sep 2016 15:00:06 +0000 (18:00 +0300)
committerEriks Jenkevics <eriks@netxms.org>
Mon, 5 Sep 2016 15:00:14 +0000 (18:00 +0300)
12 files changed:
src/java/netxms-eclipse/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/api/ObjectSelectionFilterFactory.java
src/java/netxms-eclipse/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/dialogs/ObjectSelectionDialog.java
src/java/netxms-eclipse/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/views/ObjectBrowser.java
src/java/netxms-eclipse/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/widgets/ObjectTree.java
src/java/netxms-eclipse/ObjectManager/plugin.xml
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ApplyPolicy.java [new file with mode: 0644]
webui/webapp/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/api/ObjectSelectionFilterFactory.java
webui/webapp/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/dialogs/ObjectSelectionDialog.java
webui/webapp/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/views/ObjectBrowser.java
webui/webapp/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/widgets/ObjectTree.java
webui/webapp/ObjectManager/plugin.xml
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ApplyPolicy.java [new file with mode: 0644]

index 1ee3f2e..ab2fd5b 100644 (file)
@@ -128,13 +128,29 @@ public class ObjectSelectionFilterFactory
     * 
     * @return Class filter for policies group selection
     */
-   public Set<Integer> createPolicySelectionFilter()
+   public Set<Integer> createPolicyGroupSelectionFilter()
    {
       HashSet<Integer> classFilter = new HashSet<Integer>(2);
       classFilter.add(AbstractObject.OBJECT_POLICYROOT);
       classFilter.add(AbstractObject.OBJECT_POLICYGROUP);      
       return classFilter;
    }
+   
+   /**
+    * Create filter for policies selection.
+    * 
+    * @return Class filter for policies selection
+    */
+   public Set<Integer> createPolicySelectionFilter()
+   {
+      HashSet<Integer> classFilter = new HashSet<Integer>(5);
+      classFilter.add(AbstractObject.OBJECT_POLICYROOT);
+      classFilter.add(AbstractObject.OBJECT_POLICYGROUP);
+      classFilter.add(AbstractObject.OBJECT_AGENTPOLICY);
+      classFilter.add(AbstractObject.OBJECT_AGENTPOLICY_CONFIG);
+      classFilter.add(AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER);
+      return classFilter;
+   }
        
    /**
     * Create filter for dashboard selection.
index 8153bef..1a1c225 100644 (file)
@@ -96,6 +96,16 @@ public class ObjectSelectionDialog extends Dialog
        }
        
        /**
+    * Create filter for policy group selection.
+    * 
+    * @return Class filter for policy group selection
+    */
+   public static Set<Integer> createPolicyGroupSelectionFilter()
+   {
+      return ObjectSelectionFilterFactory.getInstance().createPolicyGroupSelectionFilter();
+   }
+   
+   /**
     * Create filter for policy selection.
     * 
     * @return Class filter for policy selection
index cb32a9a..919098d 100644 (file)
@@ -729,7 +729,7 @@ public class ObjectBrowser extends ViewPart
                           filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
                           break;
                        case POLICIES:
-                          filter = ObjectSelectionDialog.createPolicySelectionFilter();
+                          filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
                           break;
                        default:
                                filter = null;
index 265eca1..bf2cd9e 100644 (file)
@@ -709,7 +709,7 @@ public class ObjectTree extends Composite
                      filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
                      break;
                   case POLICIES:
-                     filter = ObjectSelectionDialog.createPolicySelectionFilter();
+                     filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
                      break;
                   default:
                      filter = null;
index c4af134..b9602a4 100644 (file)
                label="%action.label.CreateIface"
                menubarPath="CreateObjectSubmenu/additions">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.objectmanager.actions.ApplyPolicy"
+               enablesFor="+"
+               id="org.netxms.ui.eclipse.objectmanager.actions.ApplyPolicy"
+               label="Apply policy"
+               menubarPath="objectbinding">
+         </action>
       </objectContribution>
 
 
diff --git a/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ApplyPolicy.java b/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ApplyPolicy.java
new file mode 100644 (file)
index 0000000..c0f4317
--- /dev/null
@@ -0,0 +1,113 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2016 RadenSolutions
+ *
+ * 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.objectmanager.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AccessPoint;
+import org.netxms.client.objects.Interface;
+import org.netxms.client.objects.Node;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
+import org.netxms.ui.eclipse.objectmanager.Activator;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+
+
+/**
+ * Apply agent policy from node menu
+ *
+ */
+public class ApplyPolicy implements IObjectActionDelegate
+{
+   private Shell shell;
+   private List<AbstractObject> selectedObjects = null;
+
+   @Override
+   public void run(IAction action)
+   {
+      final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, null, ObjectSelectionDialog.createPolicySelectionFilter());
+      
+      if (dlg.open() == Window.OK)
+      {
+         final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+
+         new ConsoleJob("Deploy agent policy", null, Activator.PLUGIN_ID, null) {
+
+            @Override
+            protected void runInternal(IProgressMonitor monitor) throws Exception
+            {
+               for(int i = 0; i < selectedObjects.size(); i++)
+               {
+                  for(int n = 0; n < dlg.getSelectedObjects().size(); n++)
+                  {
+                     session.deployAgentPolicy(dlg.getSelectedObjects().get(n).getObjectId(), selectedObjects.get(i).getObjectId());
+                  }
+               }
+            }
+
+            @Override
+            protected String getErrorMessage()
+            {
+               return "Cannot deploy agent policy";
+            }
+         }.start();
+
+      }
+   }
+
+   @Override
+   public void selectionChanged(IAction action, ISelection selection)
+   {
+      if ((selection instanceof IStructuredSelection) &&
+          (((IStructuredSelection)selection).size() != 0))
+      {
+         selectedObjects = new ArrayList<AbstractObject>();
+         for (Object s : ((IStructuredSelection)selection).toList())
+         {
+            if ((s instanceof Node) || (s instanceof Interface) || (s instanceof AccessPoint))
+            {
+               action.setEnabled(true);
+               selectedObjects.add(((AbstractObject)s));
+            }
+         }
+      }
+      else
+      {
+         action.setEnabled(false);
+         selectedObjects = null;
+      }
+   }
+
+   @Override
+   public void setActivePart(IAction action, IWorkbenchPart targetPart)
+   {
+      shell = targetPart.getSite().getShell();
+   }
+
+}
index 1ee3f2e..ab2fd5b 100644 (file)
@@ -128,13 +128,29 @@ public class ObjectSelectionFilterFactory
     * 
     * @return Class filter for policies group selection
     */
-   public Set<Integer> createPolicySelectionFilter()
+   public Set<Integer> createPolicyGroupSelectionFilter()
    {
       HashSet<Integer> classFilter = new HashSet<Integer>(2);
       classFilter.add(AbstractObject.OBJECT_POLICYROOT);
       classFilter.add(AbstractObject.OBJECT_POLICYGROUP);      
       return classFilter;
    }
+   
+   /**
+    * Create filter for policies selection.
+    * 
+    * @return Class filter for policies selection
+    */
+   public Set<Integer> createPolicySelectionFilter()
+   {
+      HashSet<Integer> classFilter = new HashSet<Integer>(5);
+      classFilter.add(AbstractObject.OBJECT_POLICYROOT);
+      classFilter.add(AbstractObject.OBJECT_POLICYGROUP);
+      classFilter.add(AbstractObject.OBJECT_AGENTPOLICY);
+      classFilter.add(AbstractObject.OBJECT_AGENTPOLICY_CONFIG);
+      classFilter.add(AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER);
+      return classFilter;
+   }
        
    /**
     * Create filter for dashboard selection.
index 8153bef..1a1c225 100644 (file)
@@ -96,6 +96,16 @@ public class ObjectSelectionDialog extends Dialog
        }
        
        /**
+    * Create filter for policy group selection.
+    * 
+    * @return Class filter for policy group selection
+    */
+   public static Set<Integer> createPolicyGroupSelectionFilter()
+   {
+      return ObjectSelectionFilterFactory.getInstance().createPolicyGroupSelectionFilter();
+   }
+   
+   /**
     * Create filter for policy selection.
     * 
     * @return Class filter for policy selection
index 278e217..1dc876d 100644 (file)
@@ -731,7 +731,7 @@ public class ObjectBrowser extends ViewPart
                           filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
                           break;
                        case POLICIES:
-                          filter = ObjectSelectionDialog.createPolicySelectionFilter();
+                          filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
                           break;
                        default:
                                filter = null;
index 265eca1..bf2cd9e 100644 (file)
@@ -709,7 +709,7 @@ public class ObjectTree extends Composite
                      filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
                      break;
                   case POLICIES:
-                     filter = ObjectSelectionDialog.createPolicySelectionFilter();
+                     filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
                      break;
                   default:
                      filter = null;
index c4af134..c8d3dfb 100644 (file)
                label="%action.label.CreateIface"
                menubarPath="CreateObjectSubmenu/additions">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.objectmanager.actions.ApplyPolicy"
+               id="org.netxms.ui.eclipse.objectmanager.actions.ApplyPolicy"
+               label="Apply policy"
+               menubarPath="objectbinding">
+         </action>
       </objectContribution>
 
 
diff --git a/webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ApplyPolicy.java b/webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ApplyPolicy.java
new file mode 100644 (file)
index 0000000..c0f4317
--- /dev/null
@@ -0,0 +1,113 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2016 RadenSolutions
+ *
+ * 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.objectmanager.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AccessPoint;
+import org.netxms.client.objects.Interface;
+import org.netxms.client.objects.Node;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
+import org.netxms.ui.eclipse.objectmanager.Activator;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+
+
+/**
+ * Apply agent policy from node menu
+ *
+ */
+public class ApplyPolicy implements IObjectActionDelegate
+{
+   private Shell shell;
+   private List<AbstractObject> selectedObjects = null;
+
+   @Override
+   public void run(IAction action)
+   {
+      final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, null, ObjectSelectionDialog.createPolicySelectionFilter());
+      
+      if (dlg.open() == Window.OK)
+      {
+         final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+
+         new ConsoleJob("Deploy agent policy", null, Activator.PLUGIN_ID, null) {
+
+            @Override
+            protected void runInternal(IProgressMonitor monitor) throws Exception
+            {
+               for(int i = 0; i < selectedObjects.size(); i++)
+               {
+                  for(int n = 0; n < dlg.getSelectedObjects().size(); n++)
+                  {
+                     session.deployAgentPolicy(dlg.getSelectedObjects().get(n).getObjectId(), selectedObjects.get(i).getObjectId());
+                  }
+               }
+            }
+
+            @Override
+            protected String getErrorMessage()
+            {
+               return "Cannot deploy agent policy";
+            }
+         }.start();
+
+      }
+   }
+
+   @Override
+   public void selectionChanged(IAction action, ISelection selection)
+   {
+      if ((selection instanceof IStructuredSelection) &&
+          (((IStructuredSelection)selection).size() != 0))
+      {
+         selectedObjects = new ArrayList<AbstractObject>();
+         for (Object s : ((IStructuredSelection)selection).toList())
+         {
+            if ((s instanceof Node) || (s instanceof Interface) || (s instanceof AccessPoint))
+            {
+               action.setEnabled(true);
+               selectedObjects.add(((AbstractObject)s));
+            }
+         }
+      }
+      else
+      {
+         action.setEnabled(false);
+         selectedObjects = null;
+      }
+   }
+
+   @Override
+   public void setActivePart(IAction action, IWorkbenchPart targetPart)
+   {
+      shell = targetPart.getSite().getShell();
+   }
+
+}