first (unfinished) implementation of market plugin
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 12 May 2016 21:15:41 +0000 (00:15 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 12 May 2016 21:15:41 +0000 (00:15 +0300)
21 files changed:
src/java/netxms-eclipse/Market/.classpath [new file with mode: 0644]
src/java/netxms-eclipse/Market/.project [new file with mode: 0644]
src/java/netxms-eclipse/Market/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
src/java/netxms-eclipse/Market/META-INF/MANIFEST.MF [new file with mode: 0644]
src/java/netxms-eclipse/Market/build.properties [new file with mode: 0644]
src/java/netxms-eclipse/Market/lib/json-20160212.jar [new file with mode: 0644]
src/java/netxms-eclipse/Market/plugin.xml [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/Activator.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/actions/OpenRepositoryManager.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/dialogs/RepositoryPropertiesDlg.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/Category.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/EventReference.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/LoadingPlaceholder.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/MarketObject.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/RepositoryElement.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/RepositoryRuntimeInfo.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/TemplateReference.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/RepositoryManager.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryContentProvider.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryFilter.java [new file with mode: 0644]
src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryLabelProvider.java [new file with mode: 0644]

diff --git a/src/java/netxms-eclipse/Market/.classpath b/src/java/netxms-eclipse/Market/.classpath
new file mode 100644 (file)
index 0000000..bf074cd
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry exported="true" kind="lib" path="lib/json-20160212.jar"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/src/java/netxms-eclipse/Market/.project b/src/java/netxms-eclipse/Market/.project
new file mode 100644 (file)
index 0000000..7e03ac7
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>Market</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/src/java/netxms-eclipse/Market/.settings/org.eclipse.jdt.core.prefs b/src/java/netxms-eclipse/Market/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..c537b63
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/src/java/netxms-eclipse/Market/META-INF/MANIFEST.MF b/src/java/netxms-eclipse/Market/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..629ad37
--- /dev/null
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: NetXMS Market
+Bundle-SymbolicName: org.netxms.ui.eclipse.market;singleton:=true
+Bundle-Version: 2.1.0
+Bundle-Activator: org.netxms.ui.eclipse.market.Activator
+Bundle-Vendor: Raden Solutions
+Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
+ org.eclipse.core.runtime;bundle-version="3.8.0",
+ org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.10",
+ org.netxms.ui.eclipse.console;bundle-version="2.0.10"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: .,
+ lib/json-20160212.jar
diff --git a/src/java/netxms-eclipse/Market/build.properties b/src/java/netxms-eclipse/Market/build.properties
new file mode 100644 (file)
index 0000000..3179734
--- /dev/null
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml,\
+               lib/
diff --git a/src/java/netxms-eclipse/Market/lib/json-20160212.jar b/src/java/netxms-eclipse/Market/lib/json-20160212.jar
new file mode 100644 (file)
index 0000000..21e09db
Binary files /dev/null and b/src/java/netxms-eclipse/Market/lib/json-20160212.jar differ
diff --git a/src/java/netxms-eclipse/Market/plugin.xml b/src/java/netxms-eclipse/Market/plugin.xml
new file mode 100644 (file)
index 0000000..69dce01
--- /dev/null
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.eclipse.ui.views">
+      <view
+            class="org.netxms.ui.eclipse.market.views.RepositoryManager"
+            id="org.netxms.ui.eclipse.market.views.RepositoryManager"
+            name="Repository Manager"
+            restorable="true">
+      </view>
+   </extension>
+   <extension
+         point="org.eclipse.ui.contexts">
+      <context
+            id="org.netxms.ui.eclipse.market.context.RepositoryManager"
+            name="Repository Manager"
+            parentId="org.eclipse.ui.contexts.window">
+      </context>
+   </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <command
+            id="org.netxms.ui.eclipse.market.commands.showFilter"
+            name="Show filter">
+      </command>
+      <command
+            id="org.netxms.ui.eclipse.market.commands.openRepositoryManager"
+            name="Repository Manager">
+      </command>
+   </extension>
+   <extension
+         point="org.eclipse.ui.bindings">
+      <key
+            commandId="org.netxms.ui.eclipse.market.commands.showFilter"
+            contextId="org.netxms.ui.eclipse.market.context.RepositoryManager"
+            schemeId="org.netxms.ui.eclipse.defaultKeyBinding"
+            sequence="M1+F2">
+      </key>
+   </extension>
+   <extension
+         point="org.eclipse.ui.actionSets">
+      <actionSet
+            id="org.netxms.ui.eclipse.market.actionSet"
+            label="Market"
+            visible="true">
+         <action
+               class="org.netxms.ui.eclipse.market.actions.OpenRepositoryManager"
+               definitionId="org.netxms.ui.eclipse.market.commands.openRepositoryManager"
+               id="org.netxms.ui.eclipse.market.actions.OpenRepositoryManager"
+               label="Market"
+               menubarPath="config/additions"
+               style="push">
+         </action>
+      </actionSet>
+   </extension>
+
+</plugin>
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/Activator.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/Activator.java
new file mode 100644 (file)
index 0000000..c5daa42
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin
+{
+   // The plug-in ID
+   public static final String PLUGIN_ID = "org.netxms.ui.eclipse.market"; //$NON-NLS-1$
+
+   // The shared instance
+   private static Activator plugin;
+
+   /**
+    * The constructor
+    */
+   public Activator()
+   {
+   }
+
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+    */
+   public void start(BundleContext context) throws Exception
+   {
+      super.start(context);
+      plugin = this;
+   }
+
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+    */
+   public void stop(BundleContext context) throws Exception
+   {
+      plugin = null;
+      super.stop(context);
+   }
+
+   /**
+    * Returns the shared instance
+    * 
+    * @return the shared instance
+    */
+   public static Activator getDefault()
+   {
+      return plugin;
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/actions/OpenRepositoryManager.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/actions/OpenRepositoryManager.java
new file mode 100644 (file)
index 0000000..21ecb1a
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2013 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.market.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PartInitException;
+import org.netxms.ui.eclipse.market.views.RepositoryManager;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+
+public class OpenRepositoryManager implements IWorkbenchWindowActionDelegate
+{
+       private IWorkbenchWindow window;
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+        */
+       @Override
+       public void dispose()
+       {
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+        */
+       @Override
+       public void init(IWorkbenchWindow window)
+       {
+               this.window = window;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+        */
+       @Override
+       public void run(IAction action)
+       {
+               if(window != null)
+               {       
+                       try 
+                       {
+                               window.getActivePage().showView(RepositoryManager.ID);
+                       } 
+                       catch (PartInitException e) 
+                       {
+                               MessageDialogHelper.openError(window.getShell(), "Error", String.format("Cannot open repository manager: %s", e.getLocalizedMessage()));
+                       }
+               }
+       }
+
+       /* (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)
+       {
+       }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/dialogs/RepositoryPropertiesDlg.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/dialogs/RepositoryPropertiesDlg.java
new file mode 100644 (file)
index 0000000..decf661
--- /dev/null
@@ -0,0 +1,136 @@
+/**
+ * 
+ */
+package org.netxms.ui.eclipse.market.dialogs;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.netxms.client.market.Repository;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.LabeledText;
+
+/**
+ * "Add Repository"/"Edit Repository" dialog
+ */
+public class RepositoryPropertiesDlg extends Dialog
+{
+   private LabeledText textUrl;
+   private LabeledText textToken;
+   private LabeledText textDescription;
+   private String url = "";
+   private String token = "";
+   private String description = "";
+   boolean isAdd;
+   
+   /**
+    * @param parentShell
+    */
+   public RepositoryPropertiesDlg(Shell parentShell, Repository repository)
+   {
+      super(parentShell);
+      if (repository != null)
+      {
+         isAdd = false;
+         url = repository.getUrl();
+         token = repository.getAuthToken();
+         description = repository.getDescription();
+      }
+      else
+      {
+         isAdd = true;
+      }
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+    */
+   @Override
+   protected void configureShell(Shell newShell)
+   {
+      super.configureShell(newShell);
+      newShell.setText(isAdd ? "Add Repository" : "Edit Repository");
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   protected Control createDialogArea(Composite parent)
+   {
+      Composite dialogArea = (Composite)super.createDialogArea(parent);
+      
+      GridLayout layout = new GridLayout();
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
+      layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
+      dialogArea.setLayout(layout);
+      
+      textUrl = new LabeledText(dialogArea, SWT.NONE);
+      textUrl.setLabel("URL");
+      textUrl.setText(url);
+      GridData gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.widthHint = 400;
+      textUrl.setLayoutData(gd);
+      
+      textToken = new LabeledText(dialogArea, SWT.NONE);
+      textToken.setLabel("Authentication token");
+      textToken.setText(token);
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      textToken.setLayoutData(gd);
+      
+      textDescription = new LabeledText(dialogArea, SWT.NONE);
+      textDescription.setLabel("Description");
+      textDescription.setText(description);
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      textDescription.setLayoutData(gd);
+      
+      return dialogArea;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+    */
+   @Override
+   protected void okPressed()
+   {
+      url = textUrl.getText().trim();
+      token = textToken.getText().trim();
+      description = textDescription.getText().trim();
+      super.okPressed();
+   }
+
+   /**
+    * @return the url
+    */
+   public String getUrl()
+   {
+      return url;
+   }
+
+   /**
+    * @return the token
+    */
+   public String getToken()
+   {
+      return token;
+   }
+
+   /**
+    * @return the description
+    */
+   public String getDescription()
+   {
+      return description;
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/Category.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/Category.java
new file mode 100644 (file)
index 0000000..aa177d5
--- /dev/null
@@ -0,0 +1,84 @@
+package org.netxms.ui.eclipse.market.objects;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Objects category (events, templates, etc.)
+ */
+public class Category implements MarketObject
+{
+   private String name;
+   private MarketObject parent;
+   private List<MarketObject> objects = new ArrayList<MarketObject>();
+
+   /**
+    * @param name
+    */
+   public Category(String name, MarketObject parent)
+   {
+      this.name = name;
+      this.parent = parent;
+   }
+   
+   /**
+    * Add object to category
+    * 
+    * @param object
+    */
+   public void add(RepositoryElement object)
+   {
+      objects.add(object);
+   }
+   
+   /**
+    * Clear objects
+    */
+   public void clear()
+   {
+      objects.clear();
+   }
+   
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getName()
+    */
+   @Override
+   public String getName()
+   {
+      return name;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getGuid()
+    */
+   @Override
+   public UUID getGuid()
+   {
+      return null;
+   }
+
+   @Override
+   public MarketObject getParent()
+   {
+      return parent;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getChildren()
+    */
+   @Override
+   public MarketObject[] getChildren()
+   {
+      return objects.toArray(new MarketObject[objects.size()]);
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#hasChildren()
+    */
+   @Override
+   public boolean hasChildren()
+   {
+      return !objects.isEmpty();
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/EventReference.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/EventReference.java
new file mode 100644 (file)
index 0000000..6c0fbab
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.objects;
+
+import java.util.UUID;
+import org.json.JSONObject;
+
+/**
+ * Event reference
+ */
+public class EventReference extends RepositoryElement
+{
+   /**
+    * Create event reference from JSON
+    * 
+    * @param guid
+    * @param json
+    */
+   public EventReference(UUID guid, JSONObject json)
+   {
+      super(guid, json);
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/LoadingPlaceholder.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/LoadingPlaceholder.java
new file mode 100644 (file)
index 0000000..3f9f496
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * 
+ */
+package org.netxms.ui.eclipse.market.objects;
+
+import java.util.UUID;
+
+/**
+ * Repository loading placeholder
+ */
+public class LoadingPlaceholder implements MarketObject
+{
+   private MarketObject parent;
+
+   /**
+    * @param parent
+    */
+   public LoadingPlaceholder(MarketObject parent)
+   {
+      this.parent = parent;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getName()
+    */
+   @Override
+   public String getName()
+   {
+      return "Loading...";
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getGuid()
+    */
+   @Override
+   public UUID getGuid()
+   {
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getParent()
+    */
+   @Override
+   public MarketObject getParent()
+   {
+      return parent;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getChildren()
+    */
+   @Override
+   public MarketObject[] getChildren()
+   {
+      return new MarketObject[0];
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#hasChildren()
+    */
+   @Override
+   public boolean hasChildren()
+   {
+      return false;
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/MarketObject.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/MarketObject.java
new file mode 100644 (file)
index 0000000..049c697
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.objects;
+
+import java.util.UUID;
+
+/**
+ * Common interface for all market objects
+ */
+public interface MarketObject
+{
+   /**
+    * Get object name
+    * 
+    * @return
+    */
+   public String getName();
+   
+   /**
+    * Get GUID
+    * 
+    * @return
+    */
+   public UUID getGuid();
+   
+   /**
+    * Get parent object (null for top level objects)
+    * 
+    * @return
+    */
+   public MarketObject getParent();
+   
+   /**
+    * Get underlying objects
+    * 
+    * @return
+    */
+   public MarketObject[] getChildren();
+   
+   /**
+    * Check if object has underlying objects
+    * 
+    * @return true if there is underlying objects
+    */
+   public boolean hasChildren();
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/RepositoryElement.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/RepositoryElement.java
new file mode 100644 (file)
index 0000000..5f5be62
--- /dev/null
@@ -0,0 +1,100 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.objects;
+
+import java.util.UUID;
+import org.json.JSONObject;
+
+/**
+ * Common interface for repository elements (templates, events, etc.)
+ */
+public abstract class RepositoryElement implements MarketObject
+{
+   private UUID guid;
+   private String name;
+   private MarketObject parent; 
+   
+   /**
+    * Create element from JSON object
+    * 
+    * @param guid
+    * @param json
+    */
+   public RepositoryElement(UUID guid, JSONObject json)
+   {
+      this.guid = guid;
+      name = json.getString("name");
+      parent = null;
+   }   
+   
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getName()
+    */
+   @Override
+   public String getName()
+   {
+      return name;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getGuid()
+    */
+   @Override
+   public UUID getGuid()
+   {
+      return guid;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getParent()
+    */
+   @Override
+   public MarketObject getParent()
+   {
+      return parent;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getChildren()
+    */
+   @Override
+   public MarketObject[] getChildren()
+   {
+      return new MarketObject[0];
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#hasChildren()
+    */
+   @Override
+   public boolean hasChildren()
+   {
+      return false;
+   }
+
+   /**
+    * Change parent for repository element
+    * 
+    * @param parent
+    */
+   public void setParent(Category parent)
+   {
+      this.parent = parent;
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/RepositoryRuntimeInfo.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/RepositoryRuntimeInfo.java
new file mode 100644 (file)
index 0000000..0292506
--- /dev/null
@@ -0,0 +1,231 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.objects;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.ui.IViewPart;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.netxms.client.market.Repository;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.market.Activator;
+
+/**
+ * Repository runtime information
+ */
+public class RepositoryRuntimeInfo implements MarketObject
+{
+   private Repository repository;
+   private Category events;
+   private Category templates;
+   private Category snmpTraps;
+   private LoadingPlaceholder loadingPlaceholder;
+   private boolean loaded;
+   
+   /**
+    * Create repository info
+    * 
+    * @param repository
+    */
+   public RepositoryRuntimeInfo(Repository repository)
+   {
+      this.repository = repository;
+      events = new Category("Events", this);
+      templates = new Category("Templates", this);
+      snmpTraps = new Category("SNMP Traps", this);
+      loadingPlaceholder = new LoadingPlaceholder(this);
+      loaded = false;
+   }
+   
+   /**
+    * Load repository objects
+    * 
+    * @param viewPart
+    * @param completionHandler
+    * @throws Exception
+    */
+   public void load(IViewPart viewPart, final Runnable completionHandler)
+   {
+      loaded = false;
+      events.clear();
+      templates.clear();
+      snmpTraps.clear();
+      
+      ConsoleJob job = new ConsoleJob("Load repository objects", viewPart, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final Set<RepositoryElement> objects = loadRepositoryObjects();
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  for(RepositoryElement e : objects)
+                  {
+                     if (e instanceof TemplateReference)
+                        templates.add(e);
+                     else if (e instanceof EventReference)
+                        events.add(e);
+                  }
+                  
+                  loaded = true;
+                  completionHandler.run();
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot load repository objects";
+         }
+      };
+      job.setUser(false);
+      job.start();
+   }
+   
+   /**
+    * Load repository objects
+    * 
+    * @return
+    * @throws Exception
+    */
+   private Set<RepositoryElement> loadRepositoryObjects() throws Exception
+   {
+      Set<RepositoryElement> objects = new HashSet<RepositoryElement>();
+      URL url = new URL(repository.getUrl() + "/rest-api/get-available-items?accessToken=" + repository.getAuthToken());
+      InputStream in = url.openStream();
+      try
+      {
+         JSONTokener t = new JSONTokener(in);
+         JSONObject root = new JSONObject(t);
+         loadEvents(root, objects);
+         loadTemplates(root, objects);
+      }
+      finally
+      {
+         in.close();
+      }
+      return objects;
+   }
+   
+   /**
+    * Load templates from JSON
+    * 
+    * @param root
+    * @param objects
+    * @throws Exception
+    */
+   private void loadTemplates(JSONObject root, Set<RepositoryElement> objects) throws Exception
+   {
+      if (root.isNull("templates"))
+         return;
+      JSONObject templates = root.getJSONObject("templates");
+      for(String k : templates.keySet())
+      {
+         objects.add(new TemplateReference(UUID.fromString(k), templates.getJSONObject(k)));
+      }
+   }
+   
+   /**
+    * Load events from JSON
+    * 
+    * @param root
+    * @param objects
+    * @throws Exception
+    */
+   private void loadEvents(JSONObject root, Set<RepositoryElement> objects) throws Exception
+   {
+      if (root.isNull("events"))
+         return;
+      JSONObject events = root.getJSONObject("events");
+      for(String k : events.keySet())
+      {
+         objects.add(new EventReference(UUID.fromString(k), events.getJSONObject(k)));
+      }
+   }
+   
+   /**
+    * @return
+    */
+   public boolean isLoaded()
+   {
+      return loaded;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getName()
+    */
+   @Override
+   public String getName()
+   {
+      return repository.getDescription();
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getGuid()
+    */
+   @Override
+   public UUID getGuid()
+   {
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getParent()
+    */
+   @Override
+   public MarketObject getParent()
+   {
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#getChildren()
+    */
+   @Override
+   public MarketObject[] getChildren()
+   {
+      return loaded ? new MarketObject[] { events, templates, snmpTraps } : new MarketObject[] { loadingPlaceholder };
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.market.objects.MarketObject#hasChildren()
+    */
+   @Override
+   public boolean hasChildren()
+   {
+      return true;
+   }
+
+   /**
+    * Get repository ID
+    * 
+    * @return
+    */
+   public int getRepositoryId()
+   {
+      return repository.getId();
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/TemplateReference.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/objects/TemplateReference.java
new file mode 100644 (file)
index 0000000..b15edcb
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.objects;
+
+import java.util.UUID;
+import org.json.JSONObject;
+
+/**
+ * Template reference
+ */
+public class TemplateReference extends RepositoryElement
+{
+   /**
+    * Create template reference from JSON object
+    * 
+    * @param guid
+    * @param json
+    */
+   public TemplateReference(UUID guid, JSONObject json)
+   {
+      super(guid, json);
+   }   
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/RepositoryManager.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/RepositoryManager.java
new file mode 100644 (file)
index 0000000..ac0922d
--- /dev/null
@@ -0,0 +1,449 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.views;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+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.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.part.ViewPart;
+import org.netxms.client.NXCSession;
+import org.netxms.client.market.Repository;
+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.market.Activator;
+import org.netxms.ui.eclipse.market.dialogs.RepositoryPropertiesDlg;
+import org.netxms.ui.eclipse.market.objects.RepositoryRuntimeInfo;
+import org.netxms.ui.eclipse.market.views.helpers.RepositoryContentProvider;
+import org.netxms.ui.eclipse.market.views.helpers.RepositoryFilter;
+import org.netxms.ui.eclipse.market.views.helpers.RepositoryLabelProvider;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.MessageDialogHelper;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.FilterText;
+import org.netxms.ui.eclipse.widgets.SortableTableViewer;
+import org.netxms.ui.eclipse.widgets.SortableTreeViewer;
+
+/**
+ * Repository manager view
+ */
+public class RepositoryManager extends ViewPart
+{
+   public static final String ID = "org.netxms.ui.eclipse.market.views.RepositoryManager";
+   
+   private static final String TABLE_CONFIG_PREFIX = "RepositoryManager";
+   
+   private NXCSession session = ConsoleSharedData.getSession();
+   private boolean filterEnabled = false;
+   private RepositoryFilter filter;
+   private Composite content;
+   private FilterText filterText;
+   private SortableTreeViewer viewer;
+   private Action actionRefresh;
+   private Action actionShowFilter;
+   private Action actionAddRepository;
+   private Action actionDelete;
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   public void createPartControl(Composite parent)
+   {
+      content = new Composite(parent, SWT.NONE);
+      content.setLayout(new FormLayout());
+
+      // Create filter area
+      filterText = new FilterText(content, SWT.NONE);
+      filterText.addModifyListener(new ModifyListener() {
+         @Override
+         public void modifyText(ModifyEvent e)
+         {
+            onFilterModify();
+         }
+      });
+      filterText.setCloseAction(new Action() {
+         @Override
+         public void run()
+         {
+            enableFilter(false);
+         }
+      });
+      
+      final String[] columnNames = { "Name", "Version", "GUID" };
+      final int[] columnWidths = { 300, 120, 150 };         
+      viewer = new SortableTreeViewer(content, columnNames, columnWidths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
+      
+      WidgetHelper.restoreTreeViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
+      viewer.setContentProvider(new RepositoryContentProvider(this));
+      viewer.setLabelProvider(new RepositoryLabelProvider());
+      //viewer.setComparator(new AgentFileComparator());
+      filter = new RepositoryFilter();
+      viewer.addFilter(filter);
+      viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+         @Override
+         public void selectionChanged(SelectionChangedEvent event)
+         {
+            IStructuredSelection selection = (IStructuredSelection)event.getSelection();
+            if (selection != null)
+            {
+               actionDelete.setEnabled(selection.size() > 0);
+            }
+         }
+      });
+      viewer.getTree().addDisposeListener(new DisposeListener() {
+         @Override
+         public void widgetDisposed(DisposeEvent e)
+         {
+            WidgetHelper.saveTreeViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
+         }
+      });
+
+      // Setup layout
+      FormData fd = new FormData();
+      fd.left = new FormAttachment(0, 0);
+      fd.top = new FormAttachment(filterText);
+      fd.right = new FormAttachment(100, 0);
+      fd.bottom = new FormAttachment(100, 0);
+      viewer.getTree().setLayoutData(fd);
+
+      fd = new FormData();
+      fd.left = new FormAttachment(0, 0);
+      fd.top = new FormAttachment(0, 0);
+      fd.right = new FormAttachment(100, 0);
+      filterText.setLayoutData(fd);
+
+      createActions();
+      contributeToActionBars();
+      createPopupMenu();
+      activateContext();
+
+      filterText.setCloseAction(actionShowFilter);
+
+      // Set initial focus to filter input line
+      if (filterEnabled)
+         filterText.setFocus();
+      else
+         enableFilter(false); // Will hide filter area correctly
+      
+      refreshRepositoryList();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+    */
+   @Override
+   public void setFocus()
+   {
+      viewer.getControl().setFocus();
+   }
+
+   /**
+    * Activate context
+    */
+   private void activateContext()
+   {
+      IContextService contextService = (IContextService)getSite().getService(IContextService.class);
+      if (contextService != null)
+      {
+         contextService.activateContext("org.netxms.ui.eclipse.market.context.RepositoryManager"); //$NON-NLS-1$
+      }
+   }
+
+   /**
+    * Create actions
+    */
+   private void createActions()
+   {
+      final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
+
+      actionRefresh = new RefreshAction(this) {
+         @Override
+         public void run()
+         {
+            refreshRepositoryList();
+         }
+      };
+      
+      actionShowFilter = new Action("Show &filter", Action.AS_CHECK_BOX) {
+         @Override
+         public void run()
+         {
+            enableFilter(!filterEnabled);
+            actionShowFilter.setChecked(filterEnabled);
+         }
+      };
+      actionShowFilter.setChecked(filterEnabled);
+      actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.market.commands.showFilter"); //$NON-NLS-1$
+      handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), new ActionHandler(actionShowFilter));
+      
+      actionAddRepository = new Action("&Add repository...", SharedIcons.ADD_OBJECT) {
+         @Override
+         public void run()
+         {
+            addRepository();
+         }
+      };
+      
+      actionDelete = new Action("&Delete", SharedIcons.DELETE_OBJECT) {
+         @Override
+         public void run()
+         {
+            deleteRepository();
+         }
+      };
+   }
+   
+   /**
+    * 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(actionAddRepository);
+      manager.add(new Separator());
+      manager.add(actionShowFilter);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
+   }
+
+   /**
+    * Fill local tool bar
+    * 
+    * @param manager Menu manager for local tool bar
+    */
+   private void fillLocalToolBar(IToolBarManager manager)
+   {
+      manager.add(actionAddRepository);
+      manager.add(new Separator());
+      manager.add(actionRefresh);
+   }
+
+   /**
+    * Create pop-up menu for user list
+    */
+   private void createPopupMenu()
+   {
+      // Create menu manager
+      MenuManager menuMgr = new MenuManager();
+      menuMgr.setRemoveAllWhenShown(true);
+      menuMgr.addMenuListener(new IMenuListener() {
+         public void menuAboutToShow(IMenuManager mgr)
+         {
+            fillContextMenu(mgr);
+         }
+      });
+
+      // Create menu
+      Menu menu = menuMgr.createContextMenu(viewer.getControl());
+      viewer.getControl().setMenu(menu);
+
+      // Register menu for extension.
+      getSite().registerContextMenu(menuMgr, viewer);
+   }
+
+   /**
+    * Fill context menu
+    * 
+    * @param mgr Menu manager
+    */
+   protected void fillContextMenu(final IMenuManager mgr)
+   {
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+      if (selection.isEmpty())
+         return;
+      
+      if ((selection.size() == 1) && (selection.getFirstElement() instanceof RepositoryRuntimeInfo))
+      {
+         mgr.add(actionDelete);
+      }
+   }
+   
+   /**
+    * Enable or disable filter
+    * 
+    * @param enable New filter state
+    */
+   private void enableFilter(boolean enable)
+   {
+      filterEnabled = enable;
+      filterText.setVisible(filterEnabled);
+      FormData fd = (FormData)viewer.getTree().getLayoutData();
+      fd.top = enable ? new FormAttachment(filterText) : new FormAttachment(0, 0);
+      content.layout();
+      if (enable)
+      {
+         filterText.setFocus();
+      }
+      else
+      {
+         filterText.setText(""); //$NON-NLS-1$
+         onFilterModify();
+      }
+   }
+
+   /**
+    * Handler for filter modification
+    */
+   private void onFilterModify()
+   {
+      final String text = filterText.getText();
+      filter.setFilterString(text);
+      viewer.refresh(false);
+   }
+   
+   /**
+    * Refresh repository list
+    */
+   private void refreshRepositoryList()
+   {
+      new ConsoleJob("Get list of configured repositories", this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final List<Repository> repositories = session.getRepositories();
+            final List<RepositoryRuntimeInfo> repositoryInfo = new ArrayList<RepositoryRuntimeInfo>(repositories.size());
+            for(Repository r : repositories)
+               repositoryInfo.add(new RepositoryRuntimeInfo(r));
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  viewer.setInput(repositoryInfo);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot get list of configured repositories";
+         }
+      }.start();
+   }
+   
+   /**
+    * Add repository
+    */
+   private void addRepository()
+   {
+      RepositoryPropertiesDlg dlg = new RepositoryPropertiesDlg(getSite().getShell(), null);
+      if (dlg.open() != Window.OK)
+         return;
+      
+      final Repository repository = new Repository(dlg.getUrl(), dlg.getToken(), dlg.getDescription());
+      new ConsoleJob("Add repository", this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.addRepository(repository);
+            runInUIThread(new Runnable() {
+               @SuppressWarnings("unchecked")
+               @Override
+               public void run()
+               {
+                  ArrayList<RepositoryRuntimeInfo> repositories = (ArrayList<RepositoryRuntimeInfo>)viewer.getInput();
+                  repositories.add(new RepositoryRuntimeInfo(repository));
+                  viewer.refresh();
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot add repository";
+         }
+      }.start();
+   }
+   
+   /**
+    * Delete repository
+    */
+   private void deleteRepository()
+   {
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+      if ((selection.size() != 1) || !(selection.getFirstElement() instanceof RepositoryRuntimeInfo))
+         return;
+      
+      final RepositoryRuntimeInfo repository = (RepositoryRuntimeInfo)selection.getFirstElement();
+      if (!MessageDialogHelper.openQuestion(getSite().getShell(), "Confirm Delete", 
+            String.format("Repository %s will be deleted. Are you sure?", repository.getName())))
+         return;
+      
+      new ConsoleJob("Delete repository", this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.deleteRepository(repository.getRepositoryId());
+            runInUIThread(new Runnable() {
+               @SuppressWarnings("unchecked")
+               @Override
+               public void run()
+               {
+                  ArrayList<RepositoryRuntimeInfo> repositories = (ArrayList<RepositoryRuntimeInfo>)viewer.getInput();
+                  repositories.remove(repository);
+                  viewer.refresh();
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot delete repository";
+         }
+      }.start();
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryContentProvider.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryContentProvider.java
new file mode 100644 (file)
index 0000000..cf9342b
--- /dev/null
@@ -0,0 +1,106 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.views.helpers;
+
+import java.util.List;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.IViewPart;
+import org.netxms.ui.eclipse.market.objects.MarketObject;
+import org.netxms.ui.eclipse.market.objects.RepositoryRuntimeInfo;
+
+/**
+ * Content provider
+ */
+public class RepositoryContentProvider implements ITreeContentProvider
+{
+   private IViewPart viewPart;
+   private Viewer viewer;
+   
+   /**
+    * @param viewPart
+    */
+   public RepositoryContentProvider(IViewPart viewPart)
+   {
+      this.viewPart = viewPart;
+   }
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+    */
+   @Override
+   public void dispose()
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+    */
+   @Override
+   public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+   {
+      this.viewer = viewer;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+    */
+   @Override
+   public Object[] getElements(Object inputElement)
+   {
+      return ((List<?>)inputElement).toArray();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+    */
+   @Override
+   public Object[] getChildren(Object parentElement)
+   {
+      if ((parentElement instanceof RepositoryRuntimeInfo) && !((RepositoryRuntimeInfo)parentElement).isLoaded())
+      {
+         ((RepositoryRuntimeInfo)parentElement).load(viewPart, new Runnable() {
+            @Override
+            public void run()
+            {
+               viewer.refresh();
+            }
+         });
+      }
+      return ((MarketObject)parentElement).getChildren();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+    */
+   @Override
+   public Object getParent(Object element)
+   {
+      return ((MarketObject)element).getParent();
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+    */
+   @Override
+   public boolean hasChildren(Object element)
+   {
+      return ((MarketObject)element).hasChildren();
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryFilter.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryFilter.java
new file mode 100644 (file)
index 0000000..ace28fa
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.views.helpers;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+/**
+ * Filter for repository tree
+ */
+public class RepositoryFilter extends ViewerFilter
+{
+   private String filterString = null;
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+    */
+   @Override
+   public boolean select(Viewer viewer, Object parentElement, Object element)
+   {
+      return true;
+   }
+
+   /**
+    * @return the filterString
+    */
+   public String getFilterString()
+   {
+      return filterString;
+   }
+
+   /**
+    * @param filterString the filterString to set
+    */
+   public void setFilterString(String filterString)
+   {
+      this.filterString = filterString.toLowerCase();
+   }
+}
diff --git a/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryLabelProvider.java b/src/java/netxms-eclipse/Market/src/org/netxms/ui/eclipse/market/views/helpers/RepositoryLabelProvider.java
new file mode 100644 (file)
index 0000000..9bccfe1
--- /dev/null
@@ -0,0 +1,58 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 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.market.views.helpers;
+
+import java.util.UUID;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.netxms.ui.eclipse.market.objects.MarketObject;
+
+/**
+ * Label provider for repository manager
+ */
+public class RepositoryLabelProvider extends LabelProvider implements ITableLabelProvider
+{
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+    */
+   @Override
+   public Image getColumnImage(Object element, int columnIndex)
+   {
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+    */
+   @Override
+   public String getColumnText(Object element, int columnIndex)
+   {
+      MarketObject object = (MarketObject)element;
+      switch(columnIndex)
+      {
+         case 0:
+            return object.getName();
+         case 2:
+            UUID guid = object.getGuid();
+            return (guid != null) ? guid.toString() : ""; 
+      }
+      return null;
+   }
+}