Created normal editors for Agent Config Policy and Log Parser Policy. Updated log...
authorTatjana Dubrovica <zev@radensolutions.com>
Wed, 4 May 2016 22:06:20 +0000 (01:06 +0300)
committerTatjana Dubrovica <zev@radensolutions.com>
Wed, 4 May 2016 22:14:54 +0000 (01:14 +0300)
41 files changed:
src/java/netxms-eclipse/AgentManager/META-INF/MANIFEST.MF
src/java/netxms-eclipse/AgentManager/build.properties
src/java/netxms-eclipse/AgentManager/src/org/netxms/ui/eclipse/agentmanager/views/AgentConfigEditorView.java
src/java/netxms-eclipse/Core/META-INF/MANIFEST.MF
src/java/netxms-eclipse/Core/build.properties
src/java/netxms-eclipse/Core/resource.properties [copied from src/java/netxms-eclipse/AgentManager/resource.properties with 100% similarity]
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/tools/NXFindAndReplaceAction.java [new file with mode: 0644]
src/java/netxms-eclipse/NXSL/src/org/netxms/ui/eclipse/nxsl/views/ScriptEditorView.java
src/java/netxms-eclipse/PolicyManager/META-INF/MANIFEST.MF
src/java/netxms-eclipse/PolicyManager/plugin.xml
src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/EditPolicy.java [new file with mode: 0644]
src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ConfigFile.java [deleted file]
src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java [deleted file]
src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/ConfigPolicyEditor.java [new file with mode: 0644]
src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/LogParserPolicyEditor.java [new file with mode: 0644]
src/java/netxms-eclipse/ServerConfig/META-INF/MANIFEST.MF
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/SyslogParserConfigurator.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/LogParserEditor.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParser.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserContext.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserMatch.java [copied from src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserContext.java with 50% similarity]
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserRule.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserRuleEditor.java
webui/webapp/AgentManager/META-INF/MANIFEST.MF
webui/webapp/Core/build.properties
webui/webapp/Core/resource.properties [moved from src/java/netxms-eclipse/AgentManager/resource.properties with 100% similarity]
webui/webapp/PolicyManager/META-INF/MANIFEST.MF
webui/webapp/PolicyManager/plugin.xml
webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/EditPolicy.java [new file with mode: 0644]
webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ConfigFile.java [deleted file]
webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java [deleted file]
webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/ConfigPolicyEditor.java [new file with mode: 0644]
webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/LogParserPolicyEditor.java [new file with mode: 0644]
webui/webapp/ServerConfig/META-INF/MANIFEST.MF
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/SyslogParserConfigurator.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/LogParserEditor.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParser.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserContext.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserMatch.java [copied from src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserContext.java with 50% similarity]
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserRule.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/widgets/helpers/LogParserRuleEditor.java

index ac9e22a..7a0e178 100644 (file)
@@ -16,3 +16,5 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
  org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
+Export-Package: org.netxms.ui.eclipse.agentmanager.dialogs,
+ org.netxms.ui.eclipse.agentmanager.widgets
index 3585e0b..2de0626 100644 (file)
@@ -2,7 +2,6 @@ source.. = src/
 output.. = bin/
 bin.includes = .,\
                plugin.xml,\
-               resource.properties,\
-               icons/,\
                META-INF/,\
+               icons/,\
                OSGI-INF/
index 967173b..9a5edbb 100644 (file)
  */
 package org.netxms.ui.eclipse.agentmanager.views;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.PropertyResourceBundle;
-import java.util.ResourceBundle;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuManager;
@@ -37,8 +33,6 @@ import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.ISaveablePart2;
 import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.commands.ActionHandler;
-import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.part.ViewPart;
 import org.eclipse.ui.texteditor.FindReplaceAction;
 import org.netxms.client.NXCSession;
@@ -50,6 +44,7 @@ import org.netxms.ui.eclipse.agentmanager.widgets.AgentConfigEditor;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.NXFindAndReplaceAction;
 
 /**
  * Agent's master config editor
@@ -139,16 +134,7 @@ public class AgentConfigEditorView extends ViewPart implements ISaveablePart2
         */
        private void createActions()
        {
-               try
-               {
-                       actionFindReplace = new FindReplaceAction(getResourceBundle(), "actions.find_and_replace.", this); //$NON-NLS-1$
-                       IHandlerService hs = (IHandlerService)getSite().getService(IHandlerService.class);
-                       hs.activateHandler("org.eclipse.ui.edit.findReplace", new ActionHandler(actionFindReplace));             //$NON-NLS-1$
-               }
-               catch(IOException e)
-               {
-                       e.printStackTrace();
-               }
+      actionFindReplace = NXFindAndReplaceAction.getFindReplaceAction(this);
                
                actionRefresh = new RefreshAction()
                {
@@ -264,28 +250,6 @@ public class AgentConfigEditorView extends ViewPart implements ISaveablePart2
                return modified;
        }
 
-       /**
-        * Get resource bundle
-        * @return
-        * @throws IOException
-        */
-       private ResourceBundle getResourceBundle() throws IOException
-       {
-               InputStream in = null;
-               String resource = "resource.properties"; //$NON-NLS-1$
-               ClassLoader loader = this.getClass().getClassLoader();
-               if (loader != null)
-               {
-                       in = loader.getResourceAsStream(resource);
-               }
-               else
-               {
-                       in = ClassLoader.getSystemResourceAsStream(resource);
-               }
-               
-               return new PropertyResourceBundle(in);
-       }
-
        /* (non-Javadoc)
         * @see org.eclipse.ui.ISaveablePart2#promptToSaveOnClose()
         */
index 8917580..92acfb9 100644 (file)
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.8.2,4.0.0)",
  org.eclipse.ui.forms;bundle-version="3.5.200",
  org.eclipse.ui.console;bundle-version="3.5.100",
  org.eclipse.jface.text;bundle-version="3.8.2",
- org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.10"
+ org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.10",
+ org.eclipse.ui.workbench.texteditor;bundle-version="3.8.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Bundle-ClassPath: .
index b63887e..429463a 100644 (file)
@@ -6,5 +6,6 @@ bin.includes = plugin.xml,\
                .,\
                plugin_customization.ini,\
                splash.bmp,\
-               OSGI-INF/
+               OSGI-INF/,\
+               resource.properties
 jars.compile.order = .
diff --git a/src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/tools/NXFindAndReplaceAction.java b/src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/tools/NXFindAndReplaceAction.java
new file mode 100644 (file)
index 0000000..43e1060
--- /dev/null
@@ -0,0 +1,52 @@
+package org.netxms.ui.eclipse.tools;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+import org.eclipse.ui.commands.ActionHandler;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.texteditor.FindReplaceAction;
+import org.netxms.ui.eclipse.console.Activator;
+
+public class NXFindAndReplaceAction
+{
+   public static FindReplaceAction getFindReplaceAction(ViewPart wp)
+   {
+      FindReplaceAction action = null;
+      try
+      {
+         action = new FindReplaceAction(getResourceBundle(wp), "actions.find_and_replace.", wp); //$NON-NLS-1$
+         IHandlerService hs = (IHandlerService)wp.getSite().getService(IHandlerService.class);
+         hs.activateHandler("org.eclipse.ui.edit.findReplace", new ActionHandler(action));        //$NON-NLS-1$
+      }
+      catch(IOException e)
+      {
+         e.printStackTrace();
+      }
+      return action;
+   }
+   
+   /**
+    * Get resource bundle
+    * @return
+    * @throws IOException
+    */
+   private static ResourceBundle getResourceBundle(ViewPart wp) throws IOException
+   {
+      InputStream in = null;
+      String resource = "resource.properties"; //$NON-NLS-1$
+      ClassLoader loader = Activator.getDefault().getClass().getClassLoader();
+      if (loader != null)
+      {
+         in = loader.getResourceAsStream(resource);
+      }
+      else
+      {
+         in = ClassLoader.getSystemResourceAsStream(resource);
+      }
+
+      return new PropertyResourceBundle(in);
+   }
+}
index 3544895..cb3589f 100644 (file)
@@ -68,6 +68,7 @@ import org.netxms.ui.eclipse.nxsl.Messages;
 import org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.NXFindAndReplaceAction;
 import org.netxms.ui.eclipse.widgets.CompositeWithMessageBar;
 
 /**
@@ -186,28 +187,6 @@ public class ScriptEditorView extends ViewPart implements ISaveablePart
        {
                editor.setFocus();
        }
-       
-       /**
-        * Get resource bundle
-        * @return
-        * @throws IOException
-        */
-       private ResourceBundle getResourceBundle() throws IOException
-       {
-               InputStream in = null;
-               String resource = "resource.properties"; //$NON-NLS-1$
-               ClassLoader loader = this.getClass().getClassLoader();
-               if (loader != null)
-               {
-                       in = loader.getResourceAsStream(resource);
-               }
-               else
-               {
-                       in = ClassLoader.getSystemResourceAsStream(resource);
-               }
-               
-               return new PropertyResourceBundle(in);
-       }
 
        /**
         * Create actions
@@ -216,15 +195,8 @@ public class ScriptEditorView extends ViewPart implements ISaveablePart
        {
       final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
       
-               try
-               {
-                       actionFindReplace = new FindReplaceAction(getResourceBundle(), "actions.find_and_replace.", this); //$NON-NLS-1$
-                       handlerService.activateHandler("org.eclipse.ui.edit.findReplace", new ActionHandler(actionFindReplace));                 //$NON-NLS-1$
-               }
-               catch(IOException e)
-               {
-                  Activator.logError("Cannot create find/replace action", e);
-               }
+
+      actionFindReplace = NXFindAndReplaceAction.getFindReplaceAction(this);
                
                actionRefresh = new RefreshAction(this) {
                        @Override
index d58f842..7d6f2a0 100644 (file)
@@ -5,10 +5,13 @@ Bundle-SymbolicName: org.netxms.ui.eclipse.policymanager;singleton:=true
 Bundle-Version: 2.0.0
 Bundle-Activator: org.netxms.ui.eclipse.policymanager.Activator
 Bundle-Vendor: netxms.org
-Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
- org.eclipse.core.runtime;bundle-version="3.8.0",
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
  org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.0",
  org.netxms.ui.eclipse.console;bundle-version="2.0.0",
- org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.0"
+ org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.0",
+ org.netxms.ui.eclipse.serverconfig;bundle-version="2.0.7",
+ org.eclipse.ui;bundle-version="3.8.2",
+ org.netxms.ui.eclipse.agentmanager;bundle-version="2.0.1",
+ org.eclipse.ui.workbench.texteditor;bundle-version="3.8.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
index 02661dc..c9ef9c9 100644 (file)
@@ -2,30 +2,6 @@
 <?eclipse version="3.2"?>
 <plugin>
 
-  <extension
-     point = "org.eclipse.ui.propertyPages">
-
-        <page
-           id="org.netxms.ui.eclipse.policymanager.propertypages.ConfigFile"
-           name="%page.name.ConfigFile"
-              class="org.netxms.ui.eclipse.policymanager.propertypages.ConfigFile">
-          <enabledWhen>
-             <instanceof
-                  value="org.netxms.client.objects.AgentPolicyConfig">
-             </instanceof>
-          </enabledWhen>
-        </page>
-        <page
-              class="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
-              id="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
-              name="Log Parser File">
-           <enabledWhen>
-              <instanceof
-                    value="org.netxms.client.objects.AgentPolicyLogParser">
-              </instanceof>
-           </enabledWhen>
-        </page>
-  </extension>
 
    <extension
          point="org.eclipse.ui.popupMenus">
                label="%action.label.Install"
                menubarPath="objectmgmt">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.policymanager.actions.EditPolicy"
+               enablesFor="+"
+               id="org.netxms.ui.eclipse.policymanager.popupActions.EditPolicy"
+               label="Edit Policy..."
+               menubarPath="objectmgmt">
+         </action>
       </objectContribution>
    </extension>
+   <extension
+         point="org.eclipse.ui.views">
+      <view
+            class="org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor"
+            id="org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor"
+            name="Agent Policy Config Editor"
+            restorable="true">
+      </view>
+      <view
+            class="org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor"
+            id="org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor"
+            name="Agent Policy Log Parser Editor"
+            restorable="true">
+      </view>
+   </extension>
 
 </plugin>
diff --git a/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/EditPolicy.java b/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/EditPolicy.java
new file mode 100644 (file)
index 0000000..50c91f7
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2010 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.policymanager.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AgentPolicyConfig;
+import org.netxms.client.objects.AgentPolicyLogParser;
+import org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor;
+import org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+/**
+ * Create policy group
+ */
+public class EditPolicy implements IObjectActionDelegate
+{
+   private IWorkbenchWindow window;
+   private AbstractObject currentSelection = null;
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
+        */
+       @Override
+       public void setActivePart(IAction action, IWorkbenchPart targetPart)
+       {
+          window = targetPart.getSite().getWorkbenchWindow();
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+        */
+       @Override
+       public void run(IAction action)
+       {
+          if(currentSelection != null)
+          {
+          if(currentSelection instanceof AgentPolicyConfig)
+          {
+             try
+             {
+                ConfigPolicyEditor view = (ConfigPolicyEditor)window.getActivePage().showView(ConfigPolicyEditor.ID);
+                view.setPolicy(currentSelection);
+             }
+             catch(PartInitException e)
+             {
+                MessageDialogHelper.openError(window.getShell(), "", "");
+             }                               
+          }
+          else if(currentSelection instanceof AgentPolicyLogParser)
+          {
+            try
+            {
+               LogParserPolicyEditor view = (LogParserPolicyEditor)window.getActivePage().showView(LogParserPolicyEditor.ID);
+               view.setPolicy(currentSelection);
+            }
+            catch(PartInitException e)
+            {
+               MessageDialogHelper.openError(window.getShell(), "", "");
+            }                
+          }
+          }
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+        */
+       @Override
+       public void selectionChanged(IAction action, ISelection selection)
+       {
+          currentSelection = null;
+               if (selection instanceof TreeSelection)
+               {
+                  currentSelection = (AbstractObject)((TreeSelection)selection).getFirstElement();
+                       action.setEnabled((currentSelection instanceof AgentPolicyConfig) || (currentSelection instanceof AgentPolicyLogParser));
+               }
+       }
+}
diff --git a/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ConfigFile.java b/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ConfigFile.java
deleted file mode 100644 (file)
index 167cec5..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * NetXMS - open source network management system
- * Copyright (C) 2003-2010 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.policymanager.propertypages;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-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.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.PropertyPage;
-import org.netxms.client.NXCObjectModificationData;
-import org.netxms.client.NXCSession;
-import org.netxms.client.objects.AgentPolicyConfig;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.policymanager.Activator;
-import org.netxms.ui.eclipse.policymanager.Messages;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.WidgetHelper;
-
-/**
- * Property page for agent configuration policy
- *
- */
-public class ConfigFile extends PropertyPage
-{
-       private Text textContent;
-       private String initialContent;
-       private AgentPolicyConfig object;
-       
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
-        */
-       @Override
-       protected Control createContents(Composite parent)
-       {
-               Composite dialogArea = new Composite(parent, SWT.NONE);
-               
-               object = (AgentPolicyConfig)getElement().getAdapter(AgentPolicyConfig.class);
-               if (object == null)     // Paranoid check
-                       return dialogArea;
-               
-               GridLayout layout = new GridLayout();
-               layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
-               layout.marginWidth = 0;
-               layout.marginHeight = 0;
-               //FormLayout layout = new FormLayout();
-      dialogArea.setLayout(layout);
-      
-               // File content
-      Label label = new Label(dialogArea, SWT.NONE);
-      label.setText(Messages.get().ConfigFile_File);
-      
-      initialContent = new String(object.getFileContent());
-      GridData gd = new GridData();
-      gd.grabExcessHorizontalSpace = true;
-      gd.grabExcessVerticalSpace = true;
-      gd.horizontalAlignment = GridData.FILL;
-      gd.verticalAlignment = GridData.FILL;
-      gd.heightHint = 0;
-      textContent = new Text(dialogArea, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
-      textContent.setText(object.getFileContent());
-      textContent.setLayoutData(gd);
-      
-               return dialogArea;
-       }
-       
-       
-       /**
-        * Apply changes
-        * 
-        * @param isApply true if update operation caused by "Apply" button
-        */
-       protected void applyChanges(final boolean isApply)
-       {
-               if (textContent.getText().equals(initialContent))
-                       return;         // Nothing to apply
-               
-               if (isApply)
-                       setValid(false);
-               
-               final String newContent = new String(textContent.getText());
-               new ConsoleJob(Messages.get().ConfigFile_JobName, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               if (object != null)
-                               {
-                                       NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
-                                       md.setConfigFileContent(newContent);
-                                       ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
-                               }
-                               initialContent = newContent;
-                       }
-
-                       @Override
-                       protected void jobFinalize()
-                       {
-                               if (isApply)
-                               {
-                                  runInUIThread(new Runnable() {
-                  @Override
-                  public void run()
-                  {
-                     ConfigFile.this.setValid(true);
-                  }
-               });
-                               }
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ConfigFile_JobError;
-                       }
-               }.start();
-       }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performOk()
-        */
-       @Override
-       public boolean performOk()
-       {
-               applyChanges(false);
-               return true;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performApply()
-        */
-       @Override
-       protected void performApply()
-       {
-               applyChanges(true);
-       }
-}
diff --git a/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java b/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java
deleted file mode 100644 (file)
index fb40927..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * NetXMS - open source network management system
- * Copyright (C) 2003-2010 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.policymanager.propertypages;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-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.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.PropertyPage;
-import org.netxms.client.NXCObjectModificationData;
-import org.netxms.client.NXCSession;
-import org.netxms.client.objects.AgentPolicyLogParser;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.policymanager.Activator;
-import org.netxms.ui.eclipse.policymanager.Messages;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.WidgetHelper;
-
-/**
- * Property page for agent configuration policy
- *
- */
-public class ParserFile extends PropertyPage
-{
-       private Text textContent;
-       private String initialContent;
-       private AgentPolicyLogParser object;
-       
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
-        */
-       @Override
-       protected Control createContents(Composite parent)
-       {
-               Composite dialogArea = new Composite(parent, SWT.NONE);
-               
-               object = (AgentPolicyLogParser)getElement().getAdapter(AgentPolicyLogParser.class);
-               if (object == null)     // Paranoid check
-                       return dialogArea;
-               
-               GridLayout layout = new GridLayout();
-               layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
-               layout.marginWidth = 0;
-               layout.marginHeight = 0;
-               //FormLayout layout = new FormLayout();
-      dialogArea.setLayout(layout);
-      
-               // File content
-      Label label = new Label(dialogArea, SWT.NONE);
-      label.setText(Messages.get().ConfigFile_File);
-      
-      initialContent = new String(object.getFileContent());
-      GridData gd = new GridData();
-      gd.grabExcessHorizontalSpace = true;
-      gd.grabExcessVerticalSpace = true;
-      gd.horizontalAlignment = GridData.FILL;
-      gd.verticalAlignment = GridData.FILL;
-      gd.heightHint = 0;
-      textContent = new Text(dialogArea, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
-      textContent.setText(object.getFileContent());
-      textContent.setLayoutData(gd);
-      
-               return dialogArea;
-       }
-       
-       
-       /**
-        * Apply changes
-        * 
-        * @param isApply true if update operation caused by "Apply" button
-        */
-       protected void applyChanges(final boolean isApply)
-       {
-               if (textContent.getText().equals(initialContent))
-                       return;         // Nothing to apply
-               
-               if (isApply)
-                       setValid(false);
-               
-               final String newContent = new String(textContent.getText());
-               new ConsoleJob(Messages.get().ConfigFile_JobName, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               if (object != null)
-                               {
-                                       NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
-                                       md.setConfigFileContent(newContent);
-                                       ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
-                               }
-                               initialContent = newContent;
-                       }
-
-                       @Override
-                       protected void jobFinalize()
-                       {
-                               if (isApply)
-                               {
-                                  runInUIThread(new Runnable() {
-                  @Override
-                  public void run()
-                  {
-                     ParserFile.this.setValid(true);
-                  }
-               });
-                               }
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ConfigFile_JobError;
-                       }
-               }.start();
-       }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performOk()
-        */
-       @Override
-       public boolean performOk()
-       {
-               applyChanges(false);
-               return true;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performApply()
-        */
-       @Override
-       protected void performApply()
-       {
-               applyChanges(true);
-       }
-}
diff --git a/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/ConfigPolicyEditor.java b/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/ConfigPolicyEditor.java
new file mode 100644 (file)
index 0000000..acfa124
--- /dev/null
@@ -0,0 +1,213 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2016 RadenSoutions
+ *
+ * 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.policymanager.views;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISaveablePart2;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.texteditor.FindReplaceAction;
+import org.netxms.client.NXCObjectModificationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AgentPolicyConfig;
+import org.netxms.ui.eclipse.agentmanager.dialogs.SaveStoredConfigDialog;
+import org.netxms.ui.eclipse.agentmanager.widgets.AgentConfigEditor;
+import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.NXFindAndReplaceAction;
+
+public class ConfigPolicyEditor extends ViewPart implements ISaveablePart2
+{
+   public static final String ID = "org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor";
+   
+   private AgentConfigEditor editor;
+   private boolean modified = false;
+   private boolean dirty = false;
+   private AgentPolicyConfig configPolicy;
+   
+   private Action actionSave;
+   private FindReplaceAction actionFindReplace;
+   
+   @Override
+   public void createPartControl(Composite parent)
+   {
+      parent.setLayout(new FillLayout());
+      
+      editor = new AgentConfigEditor(parent, SWT.NONE, SWT.H_SCROLL | SWT.V_SCROLL);
+      editor.getTextWidget().addModifyListener(new ModifyListener() {
+         @Override
+         public void modifyText(ModifyEvent e)
+         {
+            if (!dirty)
+            {
+               modified = true;
+               dirty = true;
+               firePropertyChange(PROP_DIRTY);
+               actionSave.setEnabled(true);
+               actionFindReplace.update();
+            }
+         }
+      });
+      
+      createActions();
+      contributeToActionBars();
+      actionSave.setEnabled(false);
+   }
+
+   @Override
+   public void setFocus()
+   {
+      editor.setFocus();      
+   }
+   
+   /**
+    * Set configuration file content
+    * 
+    * @param config
+    */
+   public void setPolicy(final AbstractObject policy)
+   {
+      configPolicy = (AgentPolicyConfig)policy;
+      editor.setText(configPolicy.getFileContent());
+      setPartName("Edit Policy \""+ configPolicy.getObjectName() +"\"");
+   }
+   
+   /**
+    * Create actions
+    */
+   private void createActions()
+   {
+      actionFindReplace = NXFindAndReplaceAction.getFindReplaceAction(this);
+      
+      actionSave = new Action() {
+         @Override
+         public void run()
+         {
+            doSave(null);
+            actionSave.setEnabled(false);
+            dirty=false;
+         }
+      };
+      actionSave.setText("Save");
+      actionSave.setImageDescriptor(SharedIcons.SAVE);
+   }
+   
+   /**
+    * Contribute actions to action bar
+    */
+   private void contributeToActionBars()
+   {
+      IActionBars bars = getViewSite().getActionBars();
+      fillLocalPullDown(bars.getMenuManager());
+      fillLocalToolBar(bars.getToolBarManager());
+   }
+
+   /**
+    * Fill local pull-down menu
+    * 
+    * @param manager
+    *           Menu manager for pull-down menu
+    */
+   private void fillLocalPullDown(IMenuManager manager)
+   {
+      manager.add(actionFindReplace);
+      manager.add(actionSave);
+      manager.add(new Separator());
+   }
+
+   /**
+    * Fill local tool bar
+    * 
+    * @param manager
+    *           Menu manager for local toolbar
+    */
+   private void fillLocalToolBar(IToolBarManager manager)
+   {
+      manager.add(actionSave);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+    */
+   @Override
+   public void doSave(IProgressMonitor monitor)
+   {
+      try
+      {
+         NXCObjectModificationData md = new NXCObjectModificationData(configPolicy.getObjectId());
+         md.setConfigFileContent(editor.getText());
+         ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
+      }
+      catch(Exception e)
+      {
+         MessageDialogHelper.openError(getViewSite().getShell(), "Error updating configuration agent policy object", "Error: " + e.getMessage());
+      }
+   }
+
+   @Override
+   public void doSaveAs()
+   {      
+   }
+
+   @Override
+   public boolean isDirty()
+   {
+      return dirty || modified;
+   }
+
+   @Override
+   public boolean isSaveAsAllowed()
+   {
+      return false;
+   }
+
+   @Override
+   public boolean isSaveOnCloseNeeded()
+   {
+      return modified;
+   }
+
+   @Override
+   public int promptToSaveOnClose()
+   {
+      SaveStoredConfigDialog dlg = new SaveStoredConfigDialog(getSite().getShell());
+      int rc = dlg.open();
+      if (rc == SaveStoredConfigDialog.SAVE_ID)
+      {
+         modified = false;
+         return YES;
+      }
+      if (rc == SaveStoredConfigDialog.CANCEL)
+      {
+         return CANCEL;
+      }
+      return NO;
+   }
+}
diff --git a/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/LogParserPolicyEditor.java b/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/LogParserPolicyEditor.java
new file mode 100644 (file)
index 0000000..2710c86
--- /dev/null
@@ -0,0 +1,284 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2016 RadenSoutions
+ *
+ * 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.policymanager.views;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISaveablePart;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.ViewPart;
+import org.netxms.client.NXCObjectModificationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AgentPolicyLogParser;
+import org.netxms.ui.eclipse.actions.RefreshAction;
+import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.policymanager.Activator;
+import org.netxms.ui.eclipse.serverconfig.widgets.LogParserEditor;
+import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserModifyListener;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+public class LogParserPolicyEditor  extends ViewPart implements ISaveablePart
+{
+   public static final String ID = "org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor";
+   
+   private AgentPolicyLogParser logParser;
+
+   private NXCSession session;
+   private LogParserEditor editor;
+   private boolean modified = false;
+   private String content;
+   private Action actionRefresh;
+   private Action actionSave;
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      session = (NXCSession)ConsoleSharedData.getSession();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   public void createPartControl(Composite parent)
+   {
+      editor = new LogParserEditor(parent, SWT.NONE, false);
+      editor.addModifyListener(new LogParserModifyListener() {
+         @Override
+         public void modifyParser()
+         {
+            setModified(true);
+         }
+      });
+      
+      createActions();
+      contributeToActionBars();
+      
+      refresh();
+   }
+
+   /**
+    * Create actions
+    */
+   private void createActions()
+   {
+      actionRefresh = new RefreshAction(this) {
+         @Override
+         public void run()
+         {
+            refresh();
+         }
+      };
+      
+      actionSave = new Action("Save", SharedIcons.SAVE) {
+         @Override
+         public void run()
+         {
+            save();
+         }
+      };
+   }
+   
+   /**
+    * Contribute actions to action bar
+    */
+   private void contributeToActionBars()
+   {
+      IActionBars bars = getViewSite().getActionBars();
+      fillLocalPullDown(bars.getMenuManager());
+      fillLocalToolBar(bars.getToolBarManager());
+   }
+
+   /**
+    * Fill local pull-down menu
+    * 
+    * @param manager
+    *           Menu manager for pull-down menu
+    */
+   private void fillLocalPullDown(IMenuManager manager)
+   {
+      manager.add(actionSave);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
+   }
+
+   /**
+    * Fill local tool bar
+    * 
+    * @param manager
+    *           Menu manager for local toolbar
+    */
+   private void fillLocalToolBar(IToolBarManager manager)
+   {
+      manager.add(actionSave);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+    */
+   @Override
+   public void setFocus()
+   {
+      editor.setFocus();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+    */
+   @Override
+   public void doSave(IProgressMonitor monitor)
+   {
+      editor.getDisplay().syncExec(new Runnable() {
+         @Override
+         public void run()
+         {
+            content = editor.getParserXml();
+         }
+      });
+      try
+      {
+         session.setServerConfigClob("SyslogParser", content); //$NON-NLS-1$
+      }
+      catch(Exception e)
+      {
+         MessageDialogHelper.openError(getSite().getShell(), "Error saving log parser", 
+               String.format("Error saving log parser: %s", e.getLocalizedMessage()));
+      }
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#doSaveAs()
+    */
+   @Override
+   public void doSaveAs()
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#isDirty()
+    */
+   @Override
+   public boolean isDirty()
+   {
+      return modified;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
+    */
+   @Override
+   public boolean isSaveAsAllowed()
+   {
+      return false;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
+    */
+   @Override
+   public boolean isSaveOnCloseNeeded()
+   {
+      return modified;
+   }
+
+   /**
+    * Refresh viewer
+    */
+   private void refresh()
+   {
+      if (modified)
+      {
+         if (!MessageDialogHelper.openQuestion(getSite().getShell(), "Confirm Refresh", "This will destroy all unsaved changes. Are you sure? "))
+            return;
+      }
+      
+      actionSave.setEnabled(false);
+      if(logParser != null)
+         editor.setParserXml(logParser.getFileContent());
+      setModified(false);
+   }
+   
+   /**
+    * Save config
+    */
+   private void save()
+   {
+      final String xml = editor.getParserXml();
+      actionSave.setEnabled(false);
+      new ConsoleJob("Save log parser configuration", this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            NXCObjectModificationData md = new NXCObjectModificationData(logParser.getObjectId());
+            md.setConfigFileContent(xml);
+            ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  setModified(false);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Error while saving log parser configuration";
+         }
+      }.start();
+   }
+   
+   /**
+    * Mark view as modified
+    */
+   private void setModified(boolean b)
+   {
+      if (b != modified)
+      {
+         modified = b;
+         firePropertyChange(PROP_DIRTY);
+         actionSave.setEnabled(modified);
+      }
+   }
+
+   public void setPolicy(AbstractObject policy)
+   {
+      logParser = (AgentPolicyLogParser)policy;
+      editor.setParserXml(logParser.getFileContent());    
+      setPartName("Edit Policy \""+ logParser.getObjectName() +"\"");
+   }
+   
+}
index 8c69775..dfad009 100644 (file)
@@ -19,3 +19,5 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
  org.netxms.ui.eclipse.datacollection;bundle-version="2.0.3"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
+Export-Package: org.netxms.ui.eclipse.serverconfig.widgets,
+ org.netxms.ui.eclipse.serverconfig.widgets.helpers
index c5e7d6f..bba11a3 100644 (file)
@@ -73,7 +73,7 @@ public class SyslogParserConfigurator extends ViewPart implements ISaveablePart
        @Override
        public void createPartControl(Composite parent)
        {
-               editor = new LogParserEditor(parent, SWT.NONE);
+               editor = new LogParserEditor(parent, SWT.NONE, true);
                editor.addModifyListener(new LogParserModifyListener() {
                        @Override
                        public void modifyParser()
index 8276df1..232dbe0 100644 (file)
@@ -33,12 +33,16 @@ import org.eclipse.swt.custom.CTabFolder;
 import org.eclipse.swt.custom.CTabItem;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Spinner;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
@@ -58,6 +62,9 @@ import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserModifyListene
 import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserRule;
 import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserRuleEditor;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.WidgetFactory;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.LabeledText;
 
 /**
  * Log parser editor
@@ -78,17 +85,25 @@ public class LogParserEditor extends Composite
        private Composite rulesArea;
        private ImageHyperlink addColumnLink;
        private TableViewer macroList;
+       private boolean isSyslogParser;
+       
+       /* General section */
+   private LabeledText labelFileName;
+   private Spinner spinerTrace;
+   private Button checkProcessAll;
 
        /**
         * @param parent
         * @param style
         */
-       public LogParserEditor(Composite parent, int style)
+       public LogParserEditor(Composite parent, int style, boolean isSyslogParser)
        {
                super(parent, style);
                
                setLayout(new FillLayout());
                
+               this.isSyslogParser = isSyslogParser;
+               
                tabFolder = new CTabFolder(this, SWT.BOTTOM | SWT.FLAT | SWT.MULTI);
                tabFolder.setUnselectedImageVisible(true);
                tabFolder.setSimple(true);
@@ -157,11 +172,24 @@ public class LogParserEditor extends Composite
                TableWrapLayout layout = new TableWrapLayout();
                layout.numColumns = 2;
                form.getBody().setLayout(layout);
+               
+               /* General section */
+               Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
+      section.setText("General");
+      TableWrapData td = new TableWrapData();
+      td.align = TableWrapData.FILL;
+      td.grabHorizontal = true;
+      td.colspan = 2;
+      section.setLayoutData(td);
+      
+      final Composite generalArea = toolkit.createComposite(section);
+      createGeneralArea(generalArea);      
+      section.setClient(generalArea);
 
                /* Rules section */
-               Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.COMPACT | Section.TWISTIE | Section.EXPANDED);
+               section = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.COMPACT | Section.TWISTIE | Section.EXPANDED);
                section.setText(Messages.get().LogParserEditor_Rules);
-               TableWrapData td = new TableWrapData();
+               td = new TableWrapData();
                td.align = TableWrapData.FILL;
                td.grabHorizontal = true;
                section.setLayoutData(td);
@@ -201,7 +229,70 @@ public class LogParserEditor extends Composite
                form.reflow(true);
        }
        
-       /**
+       private void createGeneralArea(Composite generalArea)
+   {
+          GridLayout layout = new GridLayout();
+          layout.makeColumnsEqualWidth = false;
+      layout.numColumns = 3;
+      generalArea.setLayout(layout);
+      
+      if(!isSyslogParser)
+      {
+         labelFileName = new LabeledText(generalArea, SWT.NONE);
+         labelFileName.setLabel("Parsing file path");
+         labelFileName.setText((parser.getFile() != null) ? parser.getFile() : ""); //$NON-NLS-1$
+         GridData gd = new GridData();
+         gd.grabExcessHorizontalSpace = true;
+         gd.horizontalAlignment = SWT.FILL;
+         labelFileName.setLayoutData(gd);
+         labelFileName.setText(parser.getFile());
+         labelFileName.getTextControl().addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e)
+            {
+               fireModifyListeners();
+               for(LogParserRule rule : parser.getRules())
+               {                  
+                  if(rule.getEditor() != null)
+                     rule.getEditor().updateWindowsEventLogFields();
+               }
+            }
+         });
+      }
+      
+      final WidgetFactory factory = new WidgetFactory() {
+         @Override
+         public Control createControl(Composite parent, int style)
+         {
+            return new Spinner(parent, style);
+         }
+      };
+      
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      spinerTrace = (Spinner)WidgetHelper.createLabeledControl(generalArea, SWT.BORDER, factory, "Trace level", gd);
+      spinerTrace.setMinimum(0);
+      spinerTrace.setMaximum(9);
+      spinerTrace.addModifyListener(new ModifyListener() {
+         @Override
+         public void modifyText(ModifyEvent e)
+         {
+            fireModifyListeners();
+         }
+      });
+      spinerTrace.setSelection(parser.getTrace() != null ? parser.getTrace() : 0);
+      
+      checkProcessAll = toolkit.createButton(generalArea, "Process all", SWT.CHECK);
+      checkProcessAll.addSelectionListener(new SelectionAdapter() {
+         @Override
+         public void widgetSelected(SelectionEvent e)
+         {
+            fireModifyListeners();
+         }
+      });          
+   }
+
+   /**
         * Create text editor for direct XML edit
         */
        private void createTextEditor()
@@ -346,6 +437,10 @@ public class LogParserEditor extends Composite
         */
        private String buildParserXml()
        {
+          parser.setFile(labelFileName.getText());
+          parser.setProcessALL(checkProcessAll.getSelection());
+          parser.setTrace(spinerTrace.getSelection());
+          
                for(LogParserRule rule : parser.getRules())
                        rule.getEditor().save();
                try
@@ -393,6 +488,13 @@ public class LogParserEditor extends Composite
                        MessageDialogHelper.openError(getShell(), Messages.get().LogParserEditor_Error, Messages.get().LogParserEditor_InvalidDefinition);
                        parser = new LogParser();
                }
+               parser.setSyslogParser(isSyslogParser);
+               
+               /* general */
+               if(!isSyslogParser)
+                  labelFileName.setText(parser.getFile());
+               spinerTrace.setSelection(parser.getTrace() != null ? parser.getTrace() : 0);
+               checkProcessAll.setSelection(parser.getProcessALL());
                
                /* rules */
                for(LogParserRule rule : parser.getRules())
@@ -534,4 +636,22 @@ public class LogParserEditor extends Composite
                getParent().layout(true, true);
                fireModifyListeners();
        }
+
+   /**
+    * @return the isSyslogParser
+    */
+   public boolean isSyslogParser()
+   {
+      return isSyslogParser;
+   }
+   
+   /**
+    * Checks if file name starts with "*" and is not null, then it it Windows Event Log parser.
+    * 
+    * @return isWindowsEventLogParser
+    */
+   public boolean isWindowsEventLogParser()
+   {
+      return labelFileName.getText().startsWith("*");
+   }
 }
index bcc4509..8a8fc64 100644 (file)
@@ -38,8 +38,11 @@ import org.simpleframework.xml.core.Persister;
 @Root(name="parser", strict=false)
 public class LogParser
 {
+   public static int PARSER_SYSLOG = 0;
+   public static int PARSER_OTHER = 1;
+   
        @Attribute(required=false)
-       private String name = null;
+       private String processALL = null;
        
        @Attribute(required=false)
        private Integer trace = null;
@@ -52,8 +55,10 @@ public class LogParser
        
        @ElementMap(entry="macro", key="name", attribute=true, required=false)
        private HashMap<String, String> macros = new HashMap<String, String>(0);
+       
+       private boolean isSyslogParser;
 
-       /**
+   /**
         * Create log parser object from XML document
         * 
         * @param xml XML document
@@ -81,25 +86,34 @@ public class LogParser
        }
        
        /**
-        * @return
-        */
-       public String getName()
-       {
-               return name;
-       }
+    * @return the isSyslogParser
+    */
+   public boolean isSyslogParser()
+   {
+      return isSyslogParser;
+   }
 
-       /**
-        * @param name
-        */
-       public void setName(String name)
-       {
-               this.name = name;
-       }
+   /**
+    * @param isSyslogParser the isSyslogParser to set
+    */
+   public void setSyslogParser(boolean isSyslogParser)
+   {
+      this.isSyslogParser = isSyslogParser;
+      if(isSyslogParser)
+      {
+         setFile(null);
+      }
 
-       /**
+      for(LogParserRule rule : rules)
+      {
+         rule.updateFieldsCorrectly(isSyslogParser);
+      }
+   }
+
+   /**
         * @return
         */
-       public int getTrace()
+       public Integer getTrace()
        {
                return trace;
        }
@@ -107,7 +121,7 @@ public class LogParser
        /**
         * @param trace
         */
-       public void setTrace(int trace)
+       public void setTrace(Integer trace)
        {
                this.trace = trace;
        }
@@ -121,6 +135,22 @@ public class LogParser
        }
 
        /**
+    * @return the processALL
+    */
+   public boolean getProcessALL()
+   {
+      return stringToBoolean(processALL);
+   }
+
+   /**
+    * @param processALL the processALL to set
+    */
+   public void setProcessALL(boolean processALL)
+   {
+      this.processALL = booleanToString(processALL);
+   }
+
+   /**
         * @param file
         */
        public void setFile(String file)
@@ -143,4 +173,36 @@ public class LogParser
        {
                return macros;
        }
+       
+       public static boolean stringToBoolean(final String value)
+       {
+          if(value != null)
+      {
+             try
+             {
+                if(Integer.parseInt(value) > 0)
+                {
+                   return true;
+                }
+             }
+         catch(Exception ex)
+         {
+            {
+               if(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"))
+                  return true;
+            }
+         }
+      }
+      return false;
+       }
+       
+       public static String booleanToString(boolean value)
+       {
+          return value ? "true" : null;
+       }
+       
+       public static String integerToString(Integer value)
+       {
+          return value == null ? "" : Integer.toString(value);
+       }
 }
index fd1d090..b8111f0 100644 (file)
@@ -28,7 +28,7 @@ import org.simpleframework.xml.Text;
 @Root(name="context", strict=false)
 public class LogParserContext
 {
-       @Attribute
+       @Attribute(required=false)
        private String action = null;
        
        @Attribute(required=false)
@@ -23,65 +23,63 @@ import org.simpleframework.xml.Root;
 import org.simpleframework.xml.Text;
 
 /**
- * Context in log parser rule
+ * Event in log parser rule
  */
-@Root(name="context", strict=false)
-public class LogParserContext
+@Root(name="match", strict=false)
+public class LogParserMatch
 {
-       @Attribute
-       private String action = null;
-       
+       @Text
+       private String match = ".*"; //$NON-NLS-1$
+
        @Attribute(required=false)
-       private String reset = null;
+       private String invert = null;
        
-       @Text(required=false)
-       private String data = ""; //$NON-NLS-1$
-
        /**
-        * @return the action
+        * Protected constructor for XML parser
         */
-       public int getAction()
+       protected LogParserMatch()
        {
-               return (action == null) ? 0 : (action.equalsIgnoreCase("set") ? 0 : 1); //$NON-NLS-1$
        }
-
+       
        /**
-        * @param action the action to set
+        * @param event
+        * @param parameterCount
         */
-       public void setAction(int action)
+       public LogParserMatch(String match, boolean invert)
        {
-               this.action = (action == 0) ? "set" : "clear"; //$NON-NLS-1$ //$NON-NLS-2$
+               this.match = match;
+               setInvert(invert);
        }
 
-       /**
-        * @return the reset
-        */
-       public int getReset()
-       {
-               return (reset == null) ? 0 : (reset.equalsIgnoreCase("auto") ? 0 : 1); //$NON-NLS-1$
-       }
+   /**
+    * @return the match
+    */
+   public String getMatch()
+   {
+      return match;
+   }
 
-       /**
-        * @param reset the reset to set
-        */
-       public void setReset(int reset)
-       {
-               this.reset = (action.equalsIgnoreCase("clear")) ? null : ((reset == 0) ? "auto" : "manual"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-       }
+   /**
+    * @param match the match to set
+    */
+   public void setMatch(String match)
+   {
+      this.match = match;
+   }
 
-       /**
-        * @return the data
-        */
-       public String getData()
-       {
-               return data;
-       }
+   /**
+    * @return the invert
+    */
+   public boolean getInvert()
+   {
+      return LogParser.stringToBoolean(invert);
+   }
 
-       /**
-        * @param data the data to set
-        */
-       public void setData(String data)
-       {
-               this.data = data;
-       }
+   /**
+    * @param invert the invert to set
+    */
+   public void setInvert(boolean invert)
+   {
+      this.invert = LogParser.booleanToString(invert);
+   }
 }
index d4ff52e..96ccc5a 100644 (file)
@@ -32,20 +32,33 @@ public class LogParserRule
        private String context = null;
 
        @Attribute(name="break", required=false)
-       private Boolean breakProcessing = null;
+       private String breakProcessing = null;
        
-       @Element(required=false)
-       private String match = ".*"; //$NON-NLS-1$
+       @Element(required=true)
+       private LogParserMatch match = new LogParserMatch();
        
        @Element(required=false)
        private LogParserEvent event = null;
-       
+   
+   //severity == level
+   //severity in syslog\level for other logs   
        @Element(required=false)
        private Integer severity = null;
        
+   @Element(required=false)
+   private Integer level = null;
+       
+       //facility == id
+   //facility in syslog\id for other logs
        @Element(required=false)
        private Integer facility = null;
        
+       @Element(required=false)
+       private Integer id = null;
+       
+       @Element(required = false)
+       private String source = null;
+       
        @Element(required=false)
        private String tag = null;
 
@@ -78,7 +91,7 @@ public class LogParserRule
         */
        public boolean isBreakProcessing()
        {
-               return (breakProcessing != null) ? breakProcessing : false;
+               return LogParser.stringToBoolean(breakProcessing);
        }
 
        /**
@@ -86,26 +99,26 @@ public class LogParserRule
         */
        public void setBreakProcessing(boolean breakProcessing)
        {
-               this.breakProcessing = breakProcessing ? Boolean.TRUE : null;
+               this.breakProcessing = LogParser.booleanToString(breakProcessing);
        }
 
        /**
-        * @return the match
-        */
-       public String getMatch()
-       {
-               return match;
-       }
+    * @return the matcher
+    */
+   public LogParserMatch getMatch()
+   {
+      return match;
+   }
 
-       /**
-        * @param match the match to set
-        */
-       public void setMatch(String match)
-       {
-               this.match = match;
-       }
+   /**
+    * @param matcher the matcher to set
+    */
+   public void setMatch(LogParserMatch matcher)
+   {
+      this.match = matcher;
+   }
 
-       /**
+   /**
         * @return the event
         */
        public LogParserEvent getEvent()
@@ -124,49 +137,91 @@ public class LogParserRule
        /**
         * @return the severity
         */
-       public Integer getSeverity()
+       public String getSeverityOrLevel(boolean isSyslogParser)
        {
-               return severity;
+          if(isSyslogParser)
+      {
+             return LogParser.integerToString(severity);
+      }
+          else
+             return LogParser.integerToString(level);
        }
 
        /**
         * @param severity the severity to set
         */
-       public void setSeverity(Integer severity)
+       public void setSeverityOrLevel(Integer severity)
        {
-               this.severity = severity;
+      if(editor.isSyslogParser())
+      {
+         this.severity = severity;
+         this.level = null;
+      }
+      else
+      {
+         this.level = severity;
+         this.severity = null;
+      }
        }
 
        /**
         * @return the facility
         */
-       public Integer getFacility()
+       public String getFacilityOrId(boolean isSyslogParser)
        {
-               return facility;
+          if(isSyslogParser)
+          {
+             return LogParser.integerToString(facility);
+          }
+          else
+             return LogParser.integerToString(id);
        }
 
        /**
         * @param facility the facility to set
         */
-       public void setFacility(Integer facility)
+       public void setFacilityOrId(Integer facility)
        {
-               this.facility = facility;
+          if(editor.isSyslogParser())
+      {
+             this.facility = facility;
+             this.id = null;
+      }
+          else
+          {
+             this.id = facility;
+             this.facility = null;
+          }
        }
 
        /**
         * @return the tag
         */
-       public String getTag()
+       public String getTagOrSource(boolean isSyslogParser)
        {
-               return tag;
+      if(isSyslogParser)
+      {
+         return tag == null ? "" : tag;
+      }
+      else
+         return source == null ? "" : source;
        }
 
        /**
         * @param tag the tag to set
         */
-       public void setTag(String tag)
+       public void setTagOrSource(String tag)
        {
-               this.tag = tag;
+      if(editor.isSyslogParser())
+      {
+         this.tag = tag;
+         this.source = null;
+      }
+      else
+      {
+         this.tag = null;
+         this.source = tag;
+      }
        }
 
        /**
@@ -182,7 +237,7 @@ public class LogParserRule
         */
        public void setDescription(String description)
        {
-               this.description = description;
+               this.description = description == null || description.trim().isEmpty() ? null : description;
        }
 
        /**
@@ -216,4 +271,27 @@ public class LogParserRule
        {
                this.editor = editor;
        }
+
+   public void updateFieldsCorrectly(boolean isSyslogParser)
+   {
+      if(isSyslogParser)
+      {
+         if(facility == null || facility == 0)
+            facility = id;
+         if(tag == null || tag.isEmpty())
+            tag = source;
+         if(severity == null || severity == 0)
+            severity = level;         
+      }
+      else
+      {
+         if(id == null || id == 0)
+            id = facility;
+         if(source == null || source.isEmpty())
+            source = tag;
+         if(level == null || level == 0)
+            level = severity;          
+      }
+      
+   }
 }
index 32dc4b7..f8039aa 100644 (file)
@@ -21,12 +21,14 @@ package org.netxms.ui.eclipse.serverconfig.widgets.helpers;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
@@ -62,15 +64,18 @@ public class LogParserRuleEditor extends DashboardComposite
        private LogParserRule rule;
        private LogParserEditor editor;
        private LabeledText regexp;
+       private Button checkboxInvert;
        private LabeledText severity;
        private LabeledText facility;
        private LabeledText tag;
        private LabeledText activeContext;
+       private LabeledText description;
        private EventSelector event;
        private Spinner eventParamCount;
        private LabeledText context;
        private Combo contextAction;
        private Combo contextResetMode;
+       private Button checkboxBreak;
 
        /**
         * @param parent
@@ -189,20 +194,41 @@ public class LogParserRuleEditor extends DashboardComposite
                        }
                };
                
-               regexp = new LabeledText(area, SWT.NONE);
-               toolkit.adapt(regexp);
+               Composite matcher = new Composite(area, SWT.NONE);
+      toolkit.adapt(matcher);
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      matcher.setLayoutData(gd);
+      
+      layout = new GridLayout();
+      layout.numColumns = 2;
+      layout.marginWidth = 0;
+      matcher.setLayout(layout);
+               
+               regexp = new LabeledText(matcher, SWT.NONE);
                regexp.setLabel(Messages.get().LogParserRuleEditor_MatchingRegExp);
-               regexp.setText(rule.getMatch());
-               GridData gd = new GridData();
+               regexp.setText(rule.getMatch().getMatch());
+               gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
                regexp.setLayoutData(gd);
                regexp.getTextControl().addModifyListener(listener);
+               
+               checkboxInvert = toolkit.createButton(matcher, "Invert", SWT.CHECK);
+               checkboxInvert.addSelectionListener(new SelectionAdapter() {
+         @Override
+         public void widgetSelected(SelectionEvent e)
+         {
+            editor.fireModifyListeners();
+         }
+      });          
+               checkboxInvert.setSelection(rule.getMatch().getInvert());
 
                severity = new LabeledText(area, SWT.NONE);
                toolkit.adapt(severity);
-               severity.setLabel(Messages.get().LogParserRuleEditor_Severity);
-               severity.setText((rule.getSeverity() != null) ? Integer.toString(rule.getSeverity()) : ""); //$NON-NLS-1$
+               severity.setLabel(editor.isSyslogParser() ? Messages.get().LogParserRuleEditor_Severity : "Level");
+               severity.setText(rule.getSeverityOrLevel(editor.isSyslogParser())); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -211,8 +237,8 @@ public class LogParserRuleEditor extends DashboardComposite
                
                facility = new LabeledText(area, SWT.NONE);
                toolkit.adapt(facility);
-               facility.setLabel(Messages.get().LogParserRuleEditor_Facility);
-               facility.setText((rule.getFacility() != null) ? Integer.toString(rule.getFacility()) : ""); //$NON-NLS-1$
+               facility.setLabel(editor.isSyslogParser() ? Messages.get().LogParserRuleEditor_Facility : "Id");
+               facility.setText(rule.getFacilityOrId(editor.isSyslogParser())); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -221,13 +247,13 @@ public class LogParserRuleEditor extends DashboardComposite
 
                tag = new LabeledText(area, SWT.NONE);
                toolkit.adapt(tag);
-               tag.setLabel(Messages.get().LogParserRuleEditor_SyslogTag);
-               tag.setText((rule.getTag() != null) ? rule.getTag() : ""); //$NON-NLS-1$
+               tag.setLabel(editor.isSyslogParser() ? Messages.get().LogParserRuleEditor_SyslogTag : "Source");
+               tag.setText(rule.getTagOrSource(editor.isSyslogParser())); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
                tag.setLayoutData(gd);
-               tag.getTextControl().addModifyListener(listener);
+               tag.getTextControl().addModifyListener(listener);               
                
                activeContext = new LabeledText(area, SWT.NONE);
                toolkit.adapt(activeContext);
@@ -239,9 +265,42 @@ public class LogParserRuleEditor extends DashboardComposite
                activeContext.setLayoutData(gd);
                activeContext.getTextControl().addModifyListener(listener);
                
+               description = new LabeledText(area, SWT.NONE);
+      toolkit.adapt(description);
+      description.setLabel("Description");
+      description.setText((rule.getDescription() != null) ? rule.getDescription() : ""); //$NON-NLS-1$
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      description.setLayoutData(gd);
+      description.getTextControl().addModifyListener(listener);
+               
+               updateWindowsEventLogFields();          
                return area;
        }
        
+       /**
+        * Enables or disables Windows syslog fields depending on filename field
+        */
+       public void updateWindowsEventLogFields()
+       {
+          if(editor.isSyslogParser())
+             return;
+             
+          if(editor.isWindowsEventLogParser())
+          {
+             severity.setEnabled(true);
+             facility.setEnabled(true);
+             tag.setEnabled(true);
+          }
+          else
+          {
+         severity.setEnabled(false);
+         facility.setEnabled(false);
+         tag.setEnabled(false);              
+          }
+       }
+       
        /**
         * Create action area
         */
@@ -412,6 +471,10 @@ public class LogParserRuleEditor extends DashboardComposite
                        }
                });
                
+               checkboxBreak = toolkit.createButton(area, "Process all", SWT.CHECK);
+               checkboxBreak.setText("Break");
+               checkboxBreak.setSelection(rule.isBreakProcessing());
+               
                return area;
        }
        
@@ -420,11 +483,13 @@ public class LogParserRuleEditor extends DashboardComposite
         */
        public void save()
        {
-               rule.setMatch(regexp.getText());
-               rule.setFacility(intOrNull(facility.getText()));
-               rule.setSeverity(intOrNull(severity.getText()));
-               rule.setTag(tag.getText().trim().isEmpty() ? null : tag.getText());
+               rule.setMatch(new LogParserMatch(regexp.getText(), checkboxInvert.getSelection()));
+      rule.setFacilityOrId(intOrNull(facility.getText()));
+      rule.setSeverityOrLevel(intOrNull(severity.getText()));
+      rule.setTagOrSource(tag.getText());
                rule.setContext(activeContext.getText().trim().isEmpty() ? null : activeContext.getText());
+               rule.setBreakProcessing(checkboxBreak.getSelection());
+               rule.setDescription(description.getText());
                if (event.getEventCode() != 0)
                {
                        rule.setEvent(new LogParserEvent(Long.toString(event.getEventCode()), eventParamCount.getSelection()));
@@ -467,4 +532,9 @@ public class LogParserRuleEditor extends DashboardComposite
                        return null;
                }
        }
+
+   public boolean isSyslogParser()
+   {
+      return editor.isSyslogParser();
+   }
 }
index 61d4ea8..64460b6 100644 (file)
@@ -15,3 +15,5 @@ Require-Bundle: org.eclipse.rap.ui;bundle-version="2.3.1",
  org.eclipse.rap.addons.filedialog;bundle-version="0.6.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
+Export-Package: org.netxms.ui.eclipse.agentmanager.dialogs,
+ org.netxms.ui.eclipse.agentmanager.widgets
index 3a67daf..c2c603e 100644 (file)
@@ -8,3 +8,4 @@ bin.includes = plugin.xml,\
                js/,\
                plugin_customization.ini,\
                META-INF/
+               resource.properties
index 3c9f9fe..f75b121 100644 (file)
@@ -9,6 +9,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.10.0",
  org.eclipse.rap.ui;bundle-version="2.3.1",
  org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.0",
  org.netxms.webui.core;bundle-version="2.0.0",
- org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.0"
+ org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.0",
+ org.netxms.ui.eclipse.agentmanager,
+ org.netxms.ui.eclipse.serverconfig
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
index 02661dc..c9ef9c9 100644 (file)
@@ -2,30 +2,6 @@
 <?eclipse version="3.2"?>
 <plugin>
 
-  <extension
-     point = "org.eclipse.ui.propertyPages">
-
-        <page
-           id="org.netxms.ui.eclipse.policymanager.propertypages.ConfigFile"
-           name="%page.name.ConfigFile"
-              class="org.netxms.ui.eclipse.policymanager.propertypages.ConfigFile">
-          <enabledWhen>
-             <instanceof
-                  value="org.netxms.client.objects.AgentPolicyConfig">
-             </instanceof>
-          </enabledWhen>
-        </page>
-        <page
-              class="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
-              id="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
-              name="Log Parser File">
-           <enabledWhen>
-              <instanceof
-                    value="org.netxms.client.objects.AgentPolicyLogParser">
-              </instanceof>
-           </enabledWhen>
-        </page>
-  </extension>
 
    <extension
          point="org.eclipse.ui.popupMenus">
                label="%action.label.Install"
                menubarPath="objectmgmt">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.policymanager.actions.EditPolicy"
+               enablesFor="+"
+               id="org.netxms.ui.eclipse.policymanager.popupActions.EditPolicy"
+               label="Edit Policy..."
+               menubarPath="objectmgmt">
+         </action>
       </objectContribution>
    </extension>
+   <extension
+         point="org.eclipse.ui.views">
+      <view
+            class="org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor"
+            id="org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor"
+            name="Agent Policy Config Editor"
+            restorable="true">
+      </view>
+      <view
+            class="org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor"
+            id="org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor"
+            name="Agent Policy Log Parser Editor"
+            restorable="true">
+      </view>
+   </extension>
 
 </plugin>
diff --git a/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/EditPolicy.java b/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/EditPolicy.java
new file mode 100644 (file)
index 0000000..50c91f7
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2010 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.policymanager.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AgentPolicyConfig;
+import org.netxms.client.objects.AgentPolicyLogParser;
+import org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor;
+import org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+/**
+ * Create policy group
+ */
+public class EditPolicy implements IObjectActionDelegate
+{
+   private IWorkbenchWindow window;
+   private AbstractObject currentSelection = null;
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
+        */
+       @Override
+       public void setActivePart(IAction action, IWorkbenchPart targetPart)
+       {
+          window = targetPart.getSite().getWorkbenchWindow();
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+        */
+       @Override
+       public void run(IAction action)
+       {
+          if(currentSelection != null)
+          {
+          if(currentSelection instanceof AgentPolicyConfig)
+          {
+             try
+             {
+                ConfigPolicyEditor view = (ConfigPolicyEditor)window.getActivePage().showView(ConfigPolicyEditor.ID);
+                view.setPolicy(currentSelection);
+             }
+             catch(PartInitException e)
+             {
+                MessageDialogHelper.openError(window.getShell(), "", "");
+             }                               
+          }
+          else if(currentSelection instanceof AgentPolicyLogParser)
+          {
+            try
+            {
+               LogParserPolicyEditor view = (LogParserPolicyEditor)window.getActivePage().showView(LogParserPolicyEditor.ID);
+               view.setPolicy(currentSelection);
+            }
+            catch(PartInitException e)
+            {
+               MessageDialogHelper.openError(window.getShell(), "", "");
+            }                
+          }
+          }
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+        */
+       @Override
+       public void selectionChanged(IAction action, ISelection selection)
+       {
+          currentSelection = null;
+               if (selection instanceof TreeSelection)
+               {
+                  currentSelection = (AbstractObject)((TreeSelection)selection).getFirstElement();
+                       action.setEnabled((currentSelection instanceof AgentPolicyConfig) || (currentSelection instanceof AgentPolicyLogParser));
+               }
+       }
+}
diff --git a/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ConfigFile.java b/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ConfigFile.java
deleted file mode 100644 (file)
index 167cec5..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * NetXMS - open source network management system
- * Copyright (C) 2003-2010 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.policymanager.propertypages;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-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.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.PropertyPage;
-import org.netxms.client.NXCObjectModificationData;
-import org.netxms.client.NXCSession;
-import org.netxms.client.objects.AgentPolicyConfig;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.policymanager.Activator;
-import org.netxms.ui.eclipse.policymanager.Messages;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.WidgetHelper;
-
-/**
- * Property page for agent configuration policy
- *
- */
-public class ConfigFile extends PropertyPage
-{
-       private Text textContent;
-       private String initialContent;
-       private AgentPolicyConfig object;
-       
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
-        */
-       @Override
-       protected Control createContents(Composite parent)
-       {
-               Composite dialogArea = new Composite(parent, SWT.NONE);
-               
-               object = (AgentPolicyConfig)getElement().getAdapter(AgentPolicyConfig.class);
-               if (object == null)     // Paranoid check
-                       return dialogArea;
-               
-               GridLayout layout = new GridLayout();
-               layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
-               layout.marginWidth = 0;
-               layout.marginHeight = 0;
-               //FormLayout layout = new FormLayout();
-      dialogArea.setLayout(layout);
-      
-               // File content
-      Label label = new Label(dialogArea, SWT.NONE);
-      label.setText(Messages.get().ConfigFile_File);
-      
-      initialContent = new String(object.getFileContent());
-      GridData gd = new GridData();
-      gd.grabExcessHorizontalSpace = true;
-      gd.grabExcessVerticalSpace = true;
-      gd.horizontalAlignment = GridData.FILL;
-      gd.verticalAlignment = GridData.FILL;
-      gd.heightHint = 0;
-      textContent = new Text(dialogArea, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
-      textContent.setText(object.getFileContent());
-      textContent.setLayoutData(gd);
-      
-               return dialogArea;
-       }
-       
-       
-       /**
-        * Apply changes
-        * 
-        * @param isApply true if update operation caused by "Apply" button
-        */
-       protected void applyChanges(final boolean isApply)
-       {
-               if (textContent.getText().equals(initialContent))
-                       return;         // Nothing to apply
-               
-               if (isApply)
-                       setValid(false);
-               
-               final String newContent = new String(textContent.getText());
-               new ConsoleJob(Messages.get().ConfigFile_JobName, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               if (object != null)
-                               {
-                                       NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
-                                       md.setConfigFileContent(newContent);
-                                       ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
-                               }
-                               initialContent = newContent;
-                       }
-
-                       @Override
-                       protected void jobFinalize()
-                       {
-                               if (isApply)
-                               {
-                                  runInUIThread(new Runnable() {
-                  @Override
-                  public void run()
-                  {
-                     ConfigFile.this.setValid(true);
-                  }
-               });
-                               }
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ConfigFile_JobError;
-                       }
-               }.start();
-       }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performOk()
-        */
-       @Override
-       public boolean performOk()
-       {
-               applyChanges(false);
-               return true;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performApply()
-        */
-       @Override
-       protected void performApply()
-       {
-               applyChanges(true);
-       }
-}
diff --git a/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java b/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java
deleted file mode 100644 (file)
index fb40927..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * NetXMS - open source network management system
- * Copyright (C) 2003-2010 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.policymanager.propertypages;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-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.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.PropertyPage;
-import org.netxms.client.NXCObjectModificationData;
-import org.netxms.client.NXCSession;
-import org.netxms.client.objects.AgentPolicyLogParser;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.policymanager.Activator;
-import org.netxms.ui.eclipse.policymanager.Messages;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.tools.WidgetHelper;
-
-/**
- * Property page for agent configuration policy
- *
- */
-public class ParserFile extends PropertyPage
-{
-       private Text textContent;
-       private String initialContent;
-       private AgentPolicyLogParser object;
-       
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
-        */
-       @Override
-       protected Control createContents(Composite parent)
-       {
-               Composite dialogArea = new Composite(parent, SWT.NONE);
-               
-               object = (AgentPolicyLogParser)getElement().getAdapter(AgentPolicyLogParser.class);
-               if (object == null)     // Paranoid check
-                       return dialogArea;
-               
-               GridLayout layout = new GridLayout();
-               layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
-               layout.marginWidth = 0;
-               layout.marginHeight = 0;
-               //FormLayout layout = new FormLayout();
-      dialogArea.setLayout(layout);
-      
-               // File content
-      Label label = new Label(dialogArea, SWT.NONE);
-      label.setText(Messages.get().ConfigFile_File);
-      
-      initialContent = new String(object.getFileContent());
-      GridData gd = new GridData();
-      gd.grabExcessHorizontalSpace = true;
-      gd.grabExcessVerticalSpace = true;
-      gd.horizontalAlignment = GridData.FILL;
-      gd.verticalAlignment = GridData.FILL;
-      gd.heightHint = 0;
-      textContent = new Text(dialogArea, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
-      textContent.setText(object.getFileContent());
-      textContent.setLayoutData(gd);
-      
-               return dialogArea;
-       }
-       
-       
-       /**
-        * Apply changes
-        * 
-        * @param isApply true if update operation caused by "Apply" button
-        */
-       protected void applyChanges(final boolean isApply)
-       {
-               if (textContent.getText().equals(initialContent))
-                       return;         // Nothing to apply
-               
-               if (isApply)
-                       setValid(false);
-               
-               final String newContent = new String(textContent.getText());
-               new ConsoleJob(Messages.get().ConfigFile_JobName, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               if (object != null)
-                               {
-                                       NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
-                                       md.setConfigFileContent(newContent);
-                                       ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
-                               }
-                               initialContent = newContent;
-                       }
-
-                       @Override
-                       protected void jobFinalize()
-                       {
-                               if (isApply)
-                               {
-                                  runInUIThread(new Runnable() {
-                  @Override
-                  public void run()
-                  {
-                     ParserFile.this.setValid(true);
-                  }
-               });
-                               }
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ConfigFile_JobError;
-                       }
-               }.start();
-       }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performOk()
-        */
-       @Override
-       public boolean performOk()
-       {
-               applyChanges(false);
-               return true;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performApply()
-        */
-       @Override
-       protected void performApply()
-       {
-               applyChanges(true);
-       }
-}
diff --git a/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/ConfigPolicyEditor.java b/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/ConfigPolicyEditor.java
new file mode 100644 (file)
index 0000000..cb089f7
--- /dev/null
@@ -0,0 +1,206 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2016 RadenSoutions
+ *
+ * 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.policymanager.views;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISaveablePart2;
+import org.eclipse.ui.part.ViewPart;
+import org.netxms.client.NXCObjectModificationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AgentPolicyConfig;
+import org.netxms.ui.eclipse.agentmanager.dialogs.SaveStoredConfigDialog;
+import org.netxms.ui.eclipse.agentmanager.widgets.AgentConfigEditor;
+import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+public class ConfigPolicyEditor extends ViewPart implements ISaveablePart2
+{
+   public static final String ID = "org.netxms.ui.eclipse.policymanager.views.ConfigPolicyEditor";
+   
+   private AgentConfigEditor editor;
+   private boolean modified = false;
+   private boolean dirty = false;
+   private AgentPolicyConfig configPolicy;
+   
+   private Action actionSave;
+   
+   @Override
+   public void createPartControl(Composite parent)
+   {
+      parent.setLayout(new FillLayout());
+      
+      editor = new AgentConfigEditor(parent, SWT.NONE, SWT.H_SCROLL | SWT.V_SCROLL);
+      editor.getTextWidget().addModifyListener(new ModifyListener() {
+         @Override
+         public void modifyText(ModifyEvent e)
+         {
+            if (!dirty)
+            {
+               modified = true;
+               dirty = true;
+               firePropertyChange(PROP_DIRTY);
+               actionSave.setEnabled(true);
+            }
+         }
+      });
+      
+      createActions();
+      contributeToActionBars();
+      actionSave.setEnabled(false);
+   }
+
+   @Override
+   public void setFocus()
+   {
+      editor.setFocus();      
+   }
+   
+   /**
+    * Set configuration file content
+    * 
+    * @param config
+    */
+   public void setPolicy(final AbstractObject policy)
+   {
+      configPolicy = (AgentPolicyConfig)policy;
+      editor.setText(configPolicy.getFileContent());
+      setPartName("Edit Policy \""+ configPolicy.getObjectName() +"\"");
+   }
+   
+   /**
+    * Create actions
+    */
+   private void createActions()
+   {      
+      actionSave = new Action() {
+         @Override
+         public void run()
+         {
+            doSave(null);
+            actionSave.setEnabled(false);
+            dirty=false;
+         }
+      };
+      actionSave.setText("Save");
+      actionSave.setImageDescriptor(SharedIcons.SAVE);
+   }
+   
+   /**
+    * Contribute actions to action bar
+    */
+   private void contributeToActionBars()
+   {
+      IActionBars bars = getViewSite().getActionBars();
+      fillLocalPullDown(bars.getMenuManager());
+      fillLocalToolBar(bars.getToolBarManager());
+   }
+
+   /**
+    * Fill local pull-down menu
+    * 
+    * @param manager
+    *           Menu manager for pull-down menu
+    */
+   private void fillLocalPullDown(IMenuManager manager)
+   {
+      manager.add(actionSave);
+      manager.add(new Separator());
+   }
+
+   /**
+    * Fill local tool bar
+    * 
+    * @param manager
+    *           Menu manager for local toolbar
+    */
+   private void fillLocalToolBar(IToolBarManager manager)
+   {
+      manager.add(actionSave);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+    */
+   @Override
+   public void doSave(IProgressMonitor monitor)
+   {
+      try
+      {
+         NXCObjectModificationData md = new NXCObjectModificationData(configPolicy.getObjectId());
+         md.setConfigFileContent(editor.getText());
+         ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
+      }
+      catch(Exception e)
+      {
+         MessageDialogHelper.openError(getViewSite().getShell(), "Error updating configuration agent policy object", "Error: " + e.getMessage());
+      }
+   }
+
+   @Override
+   public void doSaveAs()
+   {      
+   }
+
+   @Override
+   public boolean isDirty()
+   {
+      return dirty || modified;
+   }
+
+   @Override
+   public boolean isSaveAsAllowed()
+   {
+      return false;
+   }
+
+   @Override
+   public boolean isSaveOnCloseNeeded()
+   {
+      return modified;
+   }
+
+   @Override
+   public int promptToSaveOnClose()
+   {
+      SaveStoredConfigDialog dlg = new SaveStoredConfigDialog(getSite().getShell());
+      int rc = dlg.open();
+      if (rc == SaveStoredConfigDialog.SAVE_ID)
+      {
+         modified = false;
+         return YES;
+      }
+      if (rc == SaveStoredConfigDialog.CANCEL)
+      {
+         return CANCEL;
+      }
+      return NO;
+   }
+}
diff --git a/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/LogParserPolicyEditor.java b/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/views/LogParserPolicyEditor.java
new file mode 100644 (file)
index 0000000..2710c86
--- /dev/null
@@ -0,0 +1,284 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2016 RadenSoutions
+ *
+ * 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.policymanager.views;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISaveablePart;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.ViewPart;
+import org.netxms.client.NXCObjectModificationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.AgentPolicyLogParser;
+import org.netxms.ui.eclipse.actions.RefreshAction;
+import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.policymanager.Activator;
+import org.netxms.ui.eclipse.serverconfig.widgets.LogParserEditor;
+import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserModifyListener;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+public class LogParserPolicyEditor  extends ViewPart implements ISaveablePart
+{
+   public static final String ID = "org.netxms.ui.eclipse.policymanager.views.LogParserPolicyEditor";
+   
+   private AgentPolicyLogParser logParser;
+
+   private NXCSession session;
+   private LogParserEditor editor;
+   private boolean modified = false;
+   private String content;
+   private Action actionRefresh;
+   private Action actionSave;
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      session = (NXCSession)ConsoleSharedData.getSession();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   public void createPartControl(Composite parent)
+   {
+      editor = new LogParserEditor(parent, SWT.NONE, false);
+      editor.addModifyListener(new LogParserModifyListener() {
+         @Override
+         public void modifyParser()
+         {
+            setModified(true);
+         }
+      });
+      
+      createActions();
+      contributeToActionBars();
+      
+      refresh();
+   }
+
+   /**
+    * Create actions
+    */
+   private void createActions()
+   {
+      actionRefresh = new RefreshAction(this) {
+         @Override
+         public void run()
+         {
+            refresh();
+         }
+      };
+      
+      actionSave = new Action("Save", SharedIcons.SAVE) {
+         @Override
+         public void run()
+         {
+            save();
+         }
+      };
+   }
+   
+   /**
+    * Contribute actions to action bar
+    */
+   private void contributeToActionBars()
+   {
+      IActionBars bars = getViewSite().getActionBars();
+      fillLocalPullDown(bars.getMenuManager());
+      fillLocalToolBar(bars.getToolBarManager());
+   }
+
+   /**
+    * Fill local pull-down menu
+    * 
+    * @param manager
+    *           Menu manager for pull-down menu
+    */
+   private void fillLocalPullDown(IMenuManager manager)
+   {
+      manager.add(actionSave);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
+   }
+
+   /**
+    * Fill local tool bar
+    * 
+    * @param manager
+    *           Menu manager for local toolbar
+    */
+   private void fillLocalToolBar(IToolBarManager manager)
+   {
+      manager.add(actionSave);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+    */
+   @Override
+   public void setFocus()
+   {
+      editor.setFocus();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+    */
+   @Override
+   public void doSave(IProgressMonitor monitor)
+   {
+      editor.getDisplay().syncExec(new Runnable() {
+         @Override
+         public void run()
+         {
+            content = editor.getParserXml();
+         }
+      });
+      try
+      {
+         session.setServerConfigClob("SyslogParser", content); //$NON-NLS-1$
+      }
+      catch(Exception e)
+      {
+         MessageDialogHelper.openError(getSite().getShell(), "Error saving log parser", 
+               String.format("Error saving log parser: %s", e.getLocalizedMessage()));
+      }
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#doSaveAs()
+    */
+   @Override
+   public void doSaveAs()
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#isDirty()
+    */
+   @Override
+   public boolean isDirty()
+   {
+      return modified;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
+    */
+   @Override
+   public boolean isSaveAsAllowed()
+   {
+      return false;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
+    */
+   @Override
+   public boolean isSaveOnCloseNeeded()
+   {
+      return modified;
+   }
+
+   /**
+    * Refresh viewer
+    */
+   private void refresh()
+   {
+      if (modified)
+      {
+         if (!MessageDialogHelper.openQuestion(getSite().getShell(), "Confirm Refresh", "This will destroy all unsaved changes. Are you sure? "))
+            return;
+      }
+      
+      actionSave.setEnabled(false);
+      if(logParser != null)
+         editor.setParserXml(logParser.getFileContent());
+      setModified(false);
+   }
+   
+   /**
+    * Save config
+    */
+   private void save()
+   {
+      final String xml = editor.getParserXml();
+      actionSave.setEnabled(false);
+      new ConsoleJob("Save log parser configuration", this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            NXCObjectModificationData md = new NXCObjectModificationData(logParser.getObjectId());
+            md.setConfigFileContent(xml);
+            ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  setModified(false);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Error while saving log parser configuration";
+         }
+      }.start();
+   }
+   
+   /**
+    * Mark view as modified
+    */
+   private void setModified(boolean b)
+   {
+      if (b != modified)
+      {
+         modified = b;
+         firePropertyChange(PROP_DIRTY);
+         actionSave.setEnabled(modified);
+      }
+   }
+
+   public void setPolicy(AbstractObject policy)
+   {
+      logParser = (AgentPolicyLogParser)policy;
+      editor.setParserXml(logParser.getFileContent());    
+      setPartName("Edit Policy \""+ logParser.getObjectName() +"\"");
+   }
+   
+}
index f512088..5969c67 100644 (file)
@@ -20,3 +20,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.10.0",
  org.eclipse.rap.addons.filedialog;bundle-version="0.6.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
+Export-Package: org.netxms.ui.eclipse.serverconfig.widgets,
+ org.netxms.ui.eclipse.serverconfig.widgets.helpers
index c5e7d6f..bba11a3 100644 (file)
@@ -73,7 +73,7 @@ public class SyslogParserConfigurator extends ViewPart implements ISaveablePart
        @Override
        public void createPartControl(Composite parent)
        {
-               editor = new LogParserEditor(parent, SWT.NONE);
+               editor = new LogParserEditor(parent, SWT.NONE, true);
                editor.addModifyListener(new LogParserModifyListener() {
                        @Override
                        public void modifyParser()
index ca8e71b..1bff145 100644 (file)
@@ -34,13 +34,17 @@ import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Spinner;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
@@ -60,7 +64,9 @@ import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserModifyListene
 import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserRule;
 import org.netxms.ui.eclipse.serverconfig.widgets.helpers.LogParserRuleEditor;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.WidgetFactory;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.LabeledText;
 
 /**
  * Log parser editor
@@ -81,17 +87,25 @@ public class LogParserEditor extends Composite
        private Composite rulesArea;
        private ImageHyperlink addColumnLink;
        private TableViewer macroList;
+       private boolean isSyslogParser;
+       
+       /* General section */
+   private LabeledText labelFileName;
+   private Spinner spinerTrace;
+   private Button checkProcessAll;
 
        /**
         * @param parent
         * @param style
         */
-       public LogParserEditor(Composite parent, int style)
+       public LogParserEditor(Composite parent, int style, boolean isSyslogParser)
        {
                super(parent, style);
                
                setLayout(new FillLayout());
                
+               this.isSyslogParser = isSyslogParser;
+               
                tabFolder = new CTabFolder(this, SWT.BOTTOM | SWT.FLAT | SWT.MULTI);
                tabFolder.setUnselectedImageVisible(true);
                tabFolder.addSelectionListener(new SelectionListener() {
@@ -159,11 +173,24 @@ public class LogParserEditor extends Composite
                TableWrapLayout layout = new TableWrapLayout();
                layout.numColumns = 2;
                form.getBody().setLayout(layout);
+               
+               /* General section */
+               Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
+      section.setText("General");
+      TableWrapData td = new TableWrapData();
+      td.align = TableWrapData.FILL;
+      td.grabHorizontal = true;
+      td.colspan = 2;
+      section.setLayoutData(td);
+      
+      final Composite generalArea = toolkit.createComposite(section);
+      createGeneralArea(generalArea);      
+      section.setClient(generalArea);
 
                /* Rules section */
-               Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.COMPACT | Section.TWISTIE | Section.EXPANDED);
+               section = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.COMPACT | Section.TWISTIE | Section.EXPANDED);
                section.setText(Messages.get().LogParserEditor_Rules);
-               TableWrapData td = new TableWrapData();
+               td = new TableWrapData();
                td.align = TableWrapData.FILL;
                td.grabHorizontal = true;
                section.setLayoutData(td);
@@ -203,7 +230,70 @@ public class LogParserEditor extends Composite
                form.reflow(true);
        }
        
-       /**
+       private void createGeneralArea(Composite generalArea)
+   {
+          GridLayout layout = new GridLayout();
+          layout.makeColumnsEqualWidth = false;
+      layout.numColumns = 3;
+      generalArea.setLayout(layout);
+      
+      if(!isSyslogParser)
+      {
+         labelFileName = new LabeledText(generalArea, SWT.NONE);
+         labelFileName.setLabel("Parsing file path");
+         labelFileName.setText((parser.getFile() != null) ? parser.getFile() : ""); //$NON-NLS-1$
+         GridData gd = new GridData();
+         gd.grabExcessHorizontalSpace = true;
+         gd.horizontalAlignment = SWT.FILL;
+         labelFileName.setLayoutData(gd);
+         labelFileName.setText(parser.getFile());
+         labelFileName.getTextControl().addModifyListener(new ModifyListener() {
+            @Override
+            public void modifyText(ModifyEvent e)
+            {
+               fireModifyListeners();
+               for(LogParserRule rule : parser.getRules())
+               {                  
+                  if(rule.getEditor() != null)
+                     rule.getEditor().updateWindowsEventLogFields();
+               }
+            }
+         });
+      }
+      
+      final WidgetFactory factory = new WidgetFactory() {
+         @Override
+         public Control createControl(Composite parent, int style)
+         {
+            return new Spinner(parent, style);
+         }
+      };
+      
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      spinerTrace = (Spinner)WidgetHelper.createLabeledControl(generalArea, SWT.BORDER, factory, "Trace level", gd);
+      spinerTrace.setMinimum(0);
+      spinerTrace.setMaximum(9);
+      spinerTrace.addModifyListener(new ModifyListener() {
+         @Override
+         public void modifyText(ModifyEvent e)
+         {
+            fireModifyListeners();
+         }
+      });
+      spinerTrace.setSelection(parser.getTrace() != null ? parser.getTrace() : 0);
+      
+      checkProcessAll = toolkit.createButton(generalArea, "Process all", SWT.CHECK);
+      checkProcessAll.addSelectionListener(new SelectionAdapter() {
+         @Override
+         public void widgetSelected(SelectionEvent e)
+         {
+            fireModifyListeners();
+         }
+      });          
+   }
+
+   /**
         * Create text editor for direct XML edit
         */
        private void createTextEditor()
@@ -358,6 +448,10 @@ public class LogParserEditor extends Composite
         */
        private String buildParserXml()
        {
+          parser.setFile(labelFileName.getText());
+          parser.setProcessALL(checkProcessAll.getSelection());
+          parser.setTrace(spinerTrace.getSelection());
+          
                for(LogParserRule rule : parser.getRules())
                        rule.getEditor().save();
                try
@@ -405,6 +499,13 @@ public class LogParserEditor extends Composite
                        MessageDialogHelper.openError(getShell(), Messages.get().LogParserEditor_Error, Messages.get().LogParserEditor_InvalidDefinition);
                        parser = new LogParser();
                }
+               parser.setSyslogParser(isSyslogParser);
+               
+               /* general */
+               if(!isSyslogParser)
+                  labelFileName.setText(parser.getFile());
+               spinerTrace.setSelection(parser.getTrace() != null ? parser.getTrace() : 0);
+               checkProcessAll.setSelection(parser.getProcessALL());
                
                /* rules */
                for(LogParserRule rule : parser.getRules())
@@ -546,4 +647,22 @@ public class LogParserEditor extends Composite
                getParent().layout(true, true);
                fireModifyListeners();
        }
+
+   /**
+    * @return the isSyslogParser
+    */
+   public boolean isSyslogParser()
+   {
+      return isSyslogParser;
+   }
+   
+   /**
+    * Checks if file name starts with "*" and is not null, then it it Windows Event Log parser.
+    * 
+    * @return isWindowsEventLogParser
+    */
+   public boolean isWindowsEventLogParser()
+   {
+      return labelFileName.getText().startsWith("*");
+   }
 }
index bcc4509..8a8fc64 100644 (file)
@@ -38,8 +38,11 @@ import org.simpleframework.xml.core.Persister;
 @Root(name="parser", strict=false)
 public class LogParser
 {
+   public static int PARSER_SYSLOG = 0;
+   public static int PARSER_OTHER = 1;
+   
        @Attribute(required=false)
-       private String name = null;
+       private String processALL = null;
        
        @Attribute(required=false)
        private Integer trace = null;
@@ -52,8 +55,10 @@ public class LogParser
        
        @ElementMap(entry="macro", key="name", attribute=true, required=false)
        private HashMap<String, String> macros = new HashMap<String, String>(0);
+       
+       private boolean isSyslogParser;
 
-       /**
+   /**
         * Create log parser object from XML document
         * 
         * @param xml XML document
@@ -81,25 +86,34 @@ public class LogParser
        }
        
        /**
-        * @return
-        */
-       public String getName()
-       {
-               return name;
-       }
+    * @return the isSyslogParser
+    */
+   public boolean isSyslogParser()
+   {
+      return isSyslogParser;
+   }
 
-       /**
-        * @param name
-        */
-       public void setName(String name)
-       {
-               this.name = name;
-       }
+   /**
+    * @param isSyslogParser the isSyslogParser to set
+    */
+   public void setSyslogParser(boolean isSyslogParser)
+   {
+      this.isSyslogParser = isSyslogParser;
+      if(isSyslogParser)
+      {
+         setFile(null);
+      }
 
-       /**
+      for(LogParserRule rule : rules)
+      {
+         rule.updateFieldsCorrectly(isSyslogParser);
+      }
+   }
+
+   /**
         * @return
         */
-       public int getTrace()
+       public Integer getTrace()
        {
                return trace;
        }
@@ -107,7 +121,7 @@ public class LogParser
        /**
         * @param trace
         */
-       public void setTrace(int trace)
+       public void setTrace(Integer trace)
        {
                this.trace = trace;
        }
@@ -121,6 +135,22 @@ public class LogParser
        }
 
        /**
+    * @return the processALL
+    */
+   public boolean getProcessALL()
+   {
+      return stringToBoolean(processALL);
+   }
+
+   /**
+    * @param processALL the processALL to set
+    */
+   public void setProcessALL(boolean processALL)
+   {
+      this.processALL = booleanToString(processALL);
+   }
+
+   /**
         * @param file
         */
        public void setFile(String file)
@@ -143,4 +173,36 @@ public class LogParser
        {
                return macros;
        }
+       
+       public static boolean stringToBoolean(final String value)
+       {
+          if(value != null)
+      {
+             try
+             {
+                if(Integer.parseInt(value) > 0)
+                {
+                   return true;
+                }
+             }
+         catch(Exception ex)
+         {
+            {
+               if(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"))
+                  return true;
+            }
+         }
+      }
+      return false;
+       }
+       
+       public static String booleanToString(boolean value)
+       {
+          return value ? "true" : null;
+       }
+       
+       public static String integerToString(Integer value)
+       {
+          return value == null ? "" : Integer.toString(value);
+       }
 }
index fd1d090..b8111f0 100644 (file)
@@ -28,7 +28,7 @@ import org.simpleframework.xml.Text;
 @Root(name="context", strict=false)
 public class LogParserContext
 {
-       @Attribute
+       @Attribute(required=false)
        private String action = null;
        
        @Attribute(required=false)
@@ -23,65 +23,63 @@ import org.simpleframework.xml.Root;
 import org.simpleframework.xml.Text;
 
 /**
- * Context in log parser rule
+ * Event in log parser rule
  */
-@Root(name="context", strict=false)
-public class LogParserContext
+@Root(name="match", strict=false)
+public class LogParserMatch
 {
-       @Attribute
-       private String action = null;
-       
+       @Text
+       private String match = ".*"; //$NON-NLS-1$
+
        @Attribute(required=false)
-       private String reset = null;
+       private String invert = null;
        
-       @Text(required=false)
-       private String data = ""; //$NON-NLS-1$
-
        /**
-        * @return the action
+        * Protected constructor for XML parser
         */
-       public int getAction()
+       protected LogParserMatch()
        {
-               return (action == null) ? 0 : (action.equalsIgnoreCase("set") ? 0 : 1); //$NON-NLS-1$
        }
-
+       
        /**
-        * @param action the action to set
+        * @param event
+        * @param parameterCount
         */
-       public void setAction(int action)
+       public LogParserMatch(String match, boolean invert)
        {
-               this.action = (action == 0) ? "set" : "clear"; //$NON-NLS-1$ //$NON-NLS-2$
+               this.match = match;
+               setInvert(invert);
        }
 
-       /**
-        * @return the reset
-        */
-       public int getReset()
-       {
-               return (reset == null) ? 0 : (reset.equalsIgnoreCase("auto") ? 0 : 1); //$NON-NLS-1$
-       }
+   /**
+    * @return the match
+    */
+   public String getMatch()
+   {
+      return match;
+   }
 
-       /**
-        * @param reset the reset to set
-        */
-       public void setReset(int reset)
-       {
-               this.reset = (action.equalsIgnoreCase("clear")) ? null : ((reset == 0) ? "auto" : "manual"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-       }
+   /**
+    * @param match the match to set
+    */
+   public void setMatch(String match)
+   {
+      this.match = match;
+   }
 
-       /**
-        * @return the data
-        */
-       public String getData()
-       {
-               return data;
-       }
+   /**
+    * @return the invert
+    */
+   public boolean getInvert()
+   {
+      return LogParser.stringToBoolean(invert);
+   }
 
-       /**
-        * @param data the data to set
-        */
-       public void setData(String data)
-       {
-               this.data = data;
-       }
+   /**
+    * @param invert the invert to set
+    */
+   public void setInvert(boolean invert)
+   {
+      this.invert = LogParser.booleanToString(invert);
+   }
 }
index d4ff52e..96ccc5a 100644 (file)
@@ -32,20 +32,33 @@ public class LogParserRule
        private String context = null;
 
        @Attribute(name="break", required=false)
-       private Boolean breakProcessing = null;
+       private String breakProcessing = null;
        
-       @Element(required=false)
-       private String match = ".*"; //$NON-NLS-1$
+       @Element(required=true)
+       private LogParserMatch match = new LogParserMatch();
        
        @Element(required=false)
        private LogParserEvent event = null;
-       
+   
+   //severity == level
+   //severity in syslog\level for other logs   
        @Element(required=false)
        private Integer severity = null;
        
+   @Element(required=false)
+   private Integer level = null;
+       
+       //facility == id
+   //facility in syslog\id for other logs
        @Element(required=false)
        private Integer facility = null;
        
+       @Element(required=false)
+       private Integer id = null;
+       
+       @Element(required = false)
+       private String source = null;
+       
        @Element(required=false)
        private String tag = null;
 
@@ -78,7 +91,7 @@ public class LogParserRule
         */
        public boolean isBreakProcessing()
        {
-               return (breakProcessing != null) ? breakProcessing : false;
+               return LogParser.stringToBoolean(breakProcessing);
        }
 
        /**
@@ -86,26 +99,26 @@ public class LogParserRule
         */
        public void setBreakProcessing(boolean breakProcessing)
        {
-               this.breakProcessing = breakProcessing ? Boolean.TRUE : null;
+               this.breakProcessing = LogParser.booleanToString(breakProcessing);
        }
 
        /**
-        * @return the match
-        */
-       public String getMatch()
-       {
-               return match;
-       }
+    * @return the matcher
+    */
+   public LogParserMatch getMatch()
+   {
+      return match;
+   }
 
-       /**
-        * @param match the match to set
-        */
-       public void setMatch(String match)
-       {
-               this.match = match;
-       }
+   /**
+    * @param matcher the matcher to set
+    */
+   public void setMatch(LogParserMatch matcher)
+   {
+      this.match = matcher;
+   }
 
-       /**
+   /**
         * @return the event
         */
        public LogParserEvent getEvent()
@@ -124,49 +137,91 @@ public class LogParserRule
        /**
         * @return the severity
         */
-       public Integer getSeverity()
+       public String getSeverityOrLevel(boolean isSyslogParser)
        {
-               return severity;
+          if(isSyslogParser)
+      {
+             return LogParser.integerToString(severity);
+      }
+          else
+             return LogParser.integerToString(level);
        }
 
        /**
         * @param severity the severity to set
         */
-       public void setSeverity(Integer severity)
+       public void setSeverityOrLevel(Integer severity)
        {
-               this.severity = severity;
+      if(editor.isSyslogParser())
+      {
+         this.severity = severity;
+         this.level = null;
+      }
+      else
+      {
+         this.level = severity;
+         this.severity = null;
+      }
        }
 
        /**
         * @return the facility
         */
-       public Integer getFacility()
+       public String getFacilityOrId(boolean isSyslogParser)
        {
-               return facility;
+          if(isSyslogParser)
+          {
+             return LogParser.integerToString(facility);
+          }
+          else
+             return LogParser.integerToString(id);
        }
 
        /**
         * @param facility the facility to set
         */
-       public void setFacility(Integer facility)
+       public void setFacilityOrId(Integer facility)
        {
-               this.facility = facility;
+          if(editor.isSyslogParser())
+      {
+             this.facility = facility;
+             this.id = null;
+      }
+          else
+          {
+             this.id = facility;
+             this.facility = null;
+          }
        }
 
        /**
         * @return the tag
         */
-       public String getTag()
+       public String getTagOrSource(boolean isSyslogParser)
        {
-               return tag;
+      if(isSyslogParser)
+      {
+         return tag == null ? "" : tag;
+      }
+      else
+         return source == null ? "" : source;
        }
 
        /**
         * @param tag the tag to set
         */
-       public void setTag(String tag)
+       public void setTagOrSource(String tag)
        {
-               this.tag = tag;
+      if(editor.isSyslogParser())
+      {
+         this.tag = tag;
+         this.source = null;
+      }
+      else
+      {
+         this.tag = null;
+         this.source = tag;
+      }
        }
 
        /**
@@ -182,7 +237,7 @@ public class LogParserRule
         */
        public void setDescription(String description)
        {
-               this.description = description;
+               this.description = description == null || description.trim().isEmpty() ? null : description;
        }
 
        /**
@@ -216,4 +271,27 @@ public class LogParserRule
        {
                this.editor = editor;
        }
+
+   public void updateFieldsCorrectly(boolean isSyslogParser)
+   {
+      if(isSyslogParser)
+      {
+         if(facility == null || facility == 0)
+            facility = id;
+         if(tag == null || tag.isEmpty())
+            tag = source;
+         if(severity == null || severity == 0)
+            severity = level;         
+      }
+      else
+      {
+         if(id == null || id == 0)
+            id = facility;
+         if(source == null || source.isEmpty())
+            source = tag;
+         if(level == null || level == 0)
+            level = severity;          
+      }
+      
+   }
 }
index 32dc4b7..f8039aa 100644 (file)
@@ -21,12 +21,14 @@ package org.netxms.ui.eclipse.serverconfig.widgets.helpers;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
@@ -62,15 +64,18 @@ public class LogParserRuleEditor extends DashboardComposite
        private LogParserRule rule;
        private LogParserEditor editor;
        private LabeledText regexp;
+       private Button checkboxInvert;
        private LabeledText severity;
        private LabeledText facility;
        private LabeledText tag;
        private LabeledText activeContext;
+       private LabeledText description;
        private EventSelector event;
        private Spinner eventParamCount;
        private LabeledText context;
        private Combo contextAction;
        private Combo contextResetMode;
+       private Button checkboxBreak;
 
        /**
         * @param parent
@@ -189,20 +194,41 @@ public class LogParserRuleEditor extends DashboardComposite
                        }
                };
                
-               regexp = new LabeledText(area, SWT.NONE);
-               toolkit.adapt(regexp);
+               Composite matcher = new Composite(area, SWT.NONE);
+      toolkit.adapt(matcher);
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      matcher.setLayoutData(gd);
+      
+      layout = new GridLayout();
+      layout.numColumns = 2;
+      layout.marginWidth = 0;
+      matcher.setLayout(layout);
+               
+               regexp = new LabeledText(matcher, SWT.NONE);
                regexp.setLabel(Messages.get().LogParserRuleEditor_MatchingRegExp);
-               regexp.setText(rule.getMatch());
-               GridData gd = new GridData();
+               regexp.setText(rule.getMatch().getMatch());
+               gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
                regexp.setLayoutData(gd);
                regexp.getTextControl().addModifyListener(listener);
+               
+               checkboxInvert = toolkit.createButton(matcher, "Invert", SWT.CHECK);
+               checkboxInvert.addSelectionListener(new SelectionAdapter() {
+         @Override
+         public void widgetSelected(SelectionEvent e)
+         {
+            editor.fireModifyListeners();
+         }
+      });          
+               checkboxInvert.setSelection(rule.getMatch().getInvert());
 
                severity = new LabeledText(area, SWT.NONE);
                toolkit.adapt(severity);
-               severity.setLabel(Messages.get().LogParserRuleEditor_Severity);
-               severity.setText((rule.getSeverity() != null) ? Integer.toString(rule.getSeverity()) : ""); //$NON-NLS-1$
+               severity.setLabel(editor.isSyslogParser() ? Messages.get().LogParserRuleEditor_Severity : "Level");
+               severity.setText(rule.getSeverityOrLevel(editor.isSyslogParser())); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -211,8 +237,8 @@ public class LogParserRuleEditor extends DashboardComposite
                
                facility = new LabeledText(area, SWT.NONE);
                toolkit.adapt(facility);
-               facility.setLabel(Messages.get().LogParserRuleEditor_Facility);
-               facility.setText((rule.getFacility() != null) ? Integer.toString(rule.getFacility()) : ""); //$NON-NLS-1$
+               facility.setLabel(editor.isSyslogParser() ? Messages.get().LogParserRuleEditor_Facility : "Id");
+               facility.setText(rule.getFacilityOrId(editor.isSyslogParser())); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -221,13 +247,13 @@ public class LogParserRuleEditor extends DashboardComposite
 
                tag = new LabeledText(area, SWT.NONE);
                toolkit.adapt(tag);
-               tag.setLabel(Messages.get().LogParserRuleEditor_SyslogTag);
-               tag.setText((rule.getTag() != null) ? rule.getTag() : ""); //$NON-NLS-1$
+               tag.setLabel(editor.isSyslogParser() ? Messages.get().LogParserRuleEditor_SyslogTag : "Source");
+               tag.setText(rule.getTagOrSource(editor.isSyslogParser())); //$NON-NLS-1$
                gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
                tag.setLayoutData(gd);
-               tag.getTextControl().addModifyListener(listener);
+               tag.getTextControl().addModifyListener(listener);               
                
                activeContext = new LabeledText(area, SWT.NONE);
                toolkit.adapt(activeContext);
@@ -239,9 +265,42 @@ public class LogParserRuleEditor extends DashboardComposite
                activeContext.setLayoutData(gd);
                activeContext.getTextControl().addModifyListener(listener);
                
+               description = new LabeledText(area, SWT.NONE);
+      toolkit.adapt(description);
+      description.setLabel("Description");
+      description.setText((rule.getDescription() != null) ? rule.getDescription() : ""); //$NON-NLS-1$
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      description.setLayoutData(gd);
+      description.getTextControl().addModifyListener(listener);
+               
+               updateWindowsEventLogFields();          
                return area;
        }
        
+       /**
+        * Enables or disables Windows syslog fields depending on filename field
+        */
+       public void updateWindowsEventLogFields()
+       {
+          if(editor.isSyslogParser())
+             return;
+             
+          if(editor.isWindowsEventLogParser())
+          {
+             severity.setEnabled(true);
+             facility.setEnabled(true);
+             tag.setEnabled(true);
+          }
+          else
+          {
+         severity.setEnabled(false);
+         facility.setEnabled(false);
+         tag.setEnabled(false);              
+          }
+       }
+       
        /**
         * Create action area
         */
@@ -412,6 +471,10 @@ public class LogParserRuleEditor extends DashboardComposite
                        }
                });
                
+               checkboxBreak = toolkit.createButton(area, "Process all", SWT.CHECK);
+               checkboxBreak.setText("Break");
+               checkboxBreak.setSelection(rule.isBreakProcessing());
+               
                return area;
        }
        
@@ -420,11 +483,13 @@ public class LogParserRuleEditor extends DashboardComposite
         */
        public void save()
        {
-               rule.setMatch(regexp.getText());
-               rule.setFacility(intOrNull(facility.getText()));
-               rule.setSeverity(intOrNull(severity.getText()));
-               rule.setTag(tag.getText().trim().isEmpty() ? null : tag.getText());
+               rule.setMatch(new LogParserMatch(regexp.getText(), checkboxInvert.getSelection()));
+      rule.setFacilityOrId(intOrNull(facility.getText()));
+      rule.setSeverityOrLevel(intOrNull(severity.getText()));
+      rule.setTagOrSource(tag.getText());
                rule.setContext(activeContext.getText().trim().isEmpty() ? null : activeContext.getText());
+               rule.setBreakProcessing(checkboxBreak.getSelection());
+               rule.setDescription(description.getText());
                if (event.getEventCode() != 0)
                {
                        rule.setEvent(new LogParserEvent(Long.toString(event.getEventCode()), eventParamCount.getSelection()));
@@ -467,4 +532,9 @@ public class LogParserRuleEditor extends DashboardComposite
                        return null;
                }
        }
+
+   public boolean isSyslogParser()
+   {
+      return editor.isSyslogParser();
+   }
 }