Implemented text box element for network maps. Fixes #NX-662
authorEriks Jenkevics <eriks@netxms.org>
Tue, 7 Nov 2017 16:20:37 +0000 (18:20 +0200)
committerEriks Jenkevics <eriks@netxms.org>
Wed, 22 Nov 2017 10:51:51 +0000 (12:51 +0200)
24 files changed:
src/client/java/netxms-client/src/main/java/org/netxms/client/maps/configs/TextBoxConfig.java [new file with mode: 0644]
src/client/java/netxms-client/src/main/java/org/netxms/client/maps/elements/NetworkMapElement.java
src/client/java/netxms-client/src/main/java/org/netxms/client/maps/elements/NetworkMapTextBox.java [new file with mode: 0644]
src/java/netxms-eclipse/NetworkMaps/plugin.xml
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/propertypages/GeneralTextBox.java [new file with mode: 0644]
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/AbstractNetworkMapView.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/PredefinedMap.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/ExtendedGraphViewer.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/GraphLayoutFilter.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/MapContentProvider.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/MapLabelProvider.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java [new file with mode: 0644]
src/server/core/netmap.cpp
src/server/core/netmap_element.cpp
src/server/include/netxms_maps.h
webui/webapp/NetworkMaps/plugin.xml
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/propertypages/GeneralTextBox.java [new file with mode: 0644]
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/AbstractNetworkMapView.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/PredefinedMap.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/ExtendedGraphViewer.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/GraphLayoutFilter.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/MapContentProvider.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/MapLabelProvider.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java [new file with mode: 0644]

diff --git a/src/client/java/netxms-client/src/main/java/org/netxms/client/maps/configs/TextBoxConfig.java b/src/client/java/netxms-client/src/main/java/org/netxms/client/maps/configs/TextBoxConfig.java
new file mode 100644 (file)
index 0000000..c08a205
--- /dev/null
@@ -0,0 +1,187 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2017 Raden Solutions
+ *
+ * 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.client.maps.configs;
+
+import java.io.StringWriter;
+import java.io.Writer;
+import org.simpleframework.xml.Element;
+import org.simpleframework.xml.Root;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+
+/**
+ * Text box element config
+ */
+@Root(name="textBoxConfig")
+public class TextBoxConfig
+{
+   @Element(required=false)
+   private String text;
+   
+   @Element(required=false)
+   private int backgroundColor;
+   
+   @Element(required=false)
+   private int textColor;
+   
+   @Element(required=false)
+   private int borderColor;
+   
+   @Element(required=false)
+   private int fontSize;
+
+   @Element(required=false)
+   private long drillDownObjectId;
+   
+   @Element(required=false)
+   private boolean borderRequired;
+   
+   /**
+    * Create text box element from xml document
+    * 
+    * @param xml
+    * @return
+    * @throws Exception
+    */
+   public static TextBoxConfig createFromXml(final String xml) throws Exception
+   {
+      Serializer serializer = new Persister();
+      return serializer.read(TextBoxConfig.class, xml);
+   }
+   
+   /**
+    * Create XML from configuration
+    * 
+    * @return XML document
+    * @throws Exception if the schema for the object is not valid
+    */
+   public String createXml() throws Exception
+   {
+      Serializer serializer = new Persister();
+      Writer writer = new StringWriter();
+      serializer.write(this, writer);
+      return writer.toString();
+   }
+   
+   public String getText()
+   {
+      return text;
+   }
+   
+   public void setText(String text)
+   {
+      this.text = text;
+   }
+   
+   /**
+    * @return the backgroundColor
+    */
+   public int getBackgroundColor()
+   {
+      return backgroundColor;
+   }
+
+   /**
+    * @param backgroundColor the backgroundColor to set
+    */
+   public void setBackgroundColor(int backgroundColor)
+   {
+      this.backgroundColor = backgroundColor;
+   }
+
+   /**
+    * @return the textColor
+    */
+   public int getTextColor()
+   {
+      return textColor;
+   }
+
+   /**
+    * @param textColor the textColor to set
+    */
+   public void setTextColor(int textColor)
+   {
+      this.textColor = textColor;
+   }
+
+   /**
+    * @return the borderColor
+    */
+   public int getBorderColor()
+   {
+      return borderColor;
+   }
+
+   /**
+    * @param borderColor the borderColor to set
+    */
+   public void setBorderColor(int borderColor)
+   {
+      this.borderColor = borderColor;
+   }
+
+   /**
+    * @return the borderRequired
+    */
+   public boolean isBorderRequired()
+   {
+      return borderRequired;
+   }
+
+   /**
+    * @param borderRequired the borderRequired to set
+    */
+   public void setBorderRequired(boolean borderRequired)
+   {
+      this.borderRequired = borderRequired;
+   }
+   
+   /**
+    * @return font size
+    */
+   public int getFontSize()
+   {
+      return fontSize;
+   }
+   
+   /**
+    * @param fontSize to set
+    */
+   public void setFontSize(int fontSize)
+   {
+      this.fontSize = fontSize;
+   }
+   
+   /**
+    * @return drill down object id
+    */
+   public long getDrillDownObjectId()
+   {
+      return drillDownObjectId;
+   }
+   
+   /**
+    * @param drillDownObjectId to set
+    */
+   public void setDrillDownObjectId(long drillDownObjectId)
+   {
+      this.drillDownObjectId = drillDownObjectId;
+   }
+}
index 4490eac..fb2b6e6 100644 (file)
@@ -31,6 +31,7 @@ public class NetworkMapElement
        public static final int MAP_ELEMENT_DECORATION = 2;
        public static final int MAP_ELEMENT_DCI_CONTAINER = 3;
    public static final int MAP_ELEMENT_DCI_IMAGE = 4;
+   public static final int MAP_ELEMENT_TEXT_BOX = 5;
        
        protected long id;
        protected int type;
@@ -58,6 +59,8 @@ public class NetworkMapElement
             return new NetworkMapDCIContainer(msg, baseId);
          case MAP_ELEMENT_DCI_IMAGE:
             return new NetworkMapDCIImage(msg, baseId);
+         case MAP_ELEMENT_TEXT_BOX:
+            return new NetworkMapTextBox(msg, baseId);
                        default:
                                return new NetworkMapElement(msg, baseId);
                }
diff --git a/src/client/java/netxms-client/src/main/java/org/netxms/client/maps/elements/NetworkMapTextBox.java b/src/client/java/netxms-client/src/main/java/org/netxms/client/maps/elements/NetworkMapTextBox.java
new file mode 100644 (file)
index 0000000..196c67a
--- /dev/null
@@ -0,0 +1,227 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2017 Raden Solutions
+ *
+ * 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.client.maps.elements;
+
+import org.netxms.base.NXCPMessage;
+import org.netxms.client.maps.configs.TextBoxConfig;
+
+/**
+ * Network map element representing a text box
+ */
+public class NetworkMapTextBox extends NetworkMapElement
+{
+   private String TextBoxXml = "";
+   private String text;
+   private int backgroundColor;
+   private int textColor;
+   private int borderColor;
+   private int fontSize;
+   private long drillDownObjectId;
+   private boolean borderRequired;
+   
+   /**
+    * Create new text box from NXCPMessgae
+    * 
+    * @param msg
+    * @param baseId
+    */
+   protected NetworkMapTextBox(NXCPMessage msg, long baseId)
+   {
+      super(msg, baseId);
+      TextBoxXml = msg.getFieldAsString(baseId+10);
+      try
+      {
+         TextBoxConfig conf = TextBoxConfig.createFromXml(TextBoxXml);
+         text = conf.getText();
+         backgroundColor = conf.getBackgroundColor();
+         textColor = conf.getTextColor();
+         borderColor = conf.getBorderColor();
+         borderRequired = conf.isBorderRequired();
+         fontSize = conf.getFontSize();
+         drillDownObjectId = conf.getDrillDownObjectId();
+      }
+      catch(Exception e)
+      {
+         text = "";
+         backgroundColor = Integer.MAX_VALUE;//white
+         textColor = 0;//black
+         borderColor = 0;//black
+         borderRequired = true;
+         fontSize = 10;
+         drillDownObjectId = 0;
+      }
+      type = MAP_ELEMENT_TEXT_BOX;
+   }
+   
+   /**
+    * Create new text box element
+    * 
+    * @param id element ID
+    */
+   public NetworkMapTextBox(long id)
+   {
+      super(id);
+      text = "";
+      backgroundColor = Integer.MAX_VALUE;//white
+      textColor = 0;//black
+      borderColor = 0;//black
+      borderRequired = true;
+      type = MAP_ELEMENT_TEXT_BOX;
+   }
+   
+   /* (non-Javadoc)
+    * @see org.netxms.client.maps.elements.NetworkMapElement#fillMessage(org.netxms.base.NXCPMessage, long)
+    */
+   @Override
+   public void fillMessage(NXCPMessage msg, long baseId)
+   {
+      super.fillMessage(msg, baseId);
+      TextBoxConfig config = new TextBoxConfig();
+      config.setText(text);
+      config.setBackgroundColor(backgroundColor);
+      config.setTextColor(textColor);
+      config.setBorderColor(borderColor);
+      config.setBorderRequired(borderRequired);
+      config.setFontSize(fontSize);
+      config.setDrillDownObjectId(drillDownObjectId);
+      try
+      {
+         TextBoxXml = config.createXml();
+      }
+      catch (Exception e)
+      {
+         TextBoxXml = "";
+      }
+      msg.setField(baseId + 10, TextBoxXml);
+   }
+
+   /**
+    * @return text
+    */
+   public String getText()
+   {
+      return text;
+   }
+   
+   /**
+    * Set text
+    * 
+    * @param text to set
+    */
+   public void setText(String text)
+   {
+      this.text = text;
+   }
+   
+   /**
+    * @return the backgroundColor
+    */
+   public int getBackgroundColor()
+   {
+      return backgroundColor;
+   }
+
+   /**
+    * @param backgroundColor the backgroundColor to set
+    */
+   public void setBackgroundColor(int backgroundColor)
+   {
+      this.backgroundColor = backgroundColor;
+   }
+
+   /**
+    * @return the textColor
+    */
+   public int getTextColor()
+   {
+      return textColor;
+   }
+
+   /**
+    * @param textColor the textColor to set
+    */
+   public void setTextColor(int textColor)
+   {
+      this.textColor = textColor;
+   }
+
+   /**
+    * @return the borderColor
+    */
+   public int getBorderColor()
+   {
+      return borderColor;
+   }
+
+   /**
+    * @param borderColor the borderColor to set
+    */
+   public void setBorderColor(int borderColor)
+   {
+      this.borderColor = borderColor;
+   }
+
+   /**
+    * @return the borderRequired
+    */
+   public boolean isBorderRequired()
+   {
+      return borderRequired;
+   }
+
+   /**
+    * @param borderRequired the borderRequired to set
+    */
+   public void setBorderRequired(boolean borderRequired)
+   {
+      this.borderRequired = borderRequired;
+   }
+   
+   /**
+    * @return font size
+    */
+   public int getFontSize()
+   {
+      return fontSize;
+   }
+   
+   /**
+    * @param fontSize to set
+    */
+   public void setFontSize(int fontSize)
+   {
+      this.fontSize = fontSize;
+   }
+   
+   /**
+    * @return drill down object id
+    */
+   public long getDrillDownObjectId()
+   {
+      return drillDownObjectId;
+   }
+   
+   /**
+    * @param drillDownObjectId to set
+    */
+   public void setDrillDownObjectId(long drillDownObjectId)
+   {
+      this.drillDownObjectId = drillDownObjectId;
+   }
+}
index 41648bb..0098046 100644 (file)
             </instanceof>
          </enabledWhen>
       </page>
+      <page
+            class="org.netxms.ui.eclipse.networkmaps.propertypages.GeneralTextBox"
+            id="org.netxms.ui.eclipse.networkmaps.propertypages.GeneralTextBox#0"
+            name="General">
+         <enabledWhen>
+            <instanceof
+                  value="org.netxms.client.maps.elements.NetworkMapTextBox">
+            </instanceof>
+         </enabledWhen>
+      </page>
    </extension>
    <extension
          point="org.eclipse.ui.bindings">
diff --git a/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/propertypages/GeneralTextBox.java b/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/propertypages/GeneralTextBox.java
new file mode 100644 (file)
index 0000000..838e99a
--- /dev/null
@@ -0,0 +1,178 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2017 Raden Solutions
+ *
+ * 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.networkmaps.propertypages;
+
+import org.eclipse.jface.preference.ColorSelector;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Text;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
+import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;
+import org.netxms.ui.eclipse.tools.ColorConverter;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+
+/**
+ * Text box property page for network map element
+ */
+public class GeneralTextBox extends PropertyPage
+{
+   private Text labeledText;
+   private ColorSelector backgroundSelector;
+   private ColorSelector textSelector;
+   private ColorSelector borderSelector;
+   private Button borderCheck;
+   private Spinner fontSize;
+   private NetworkMapTextBox textBox;
+   private ObjectSelector drillDownObject;
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   protected Control createContents(Composite parent)
+   {
+      textBox = (NetworkMapTextBox)getElement().getAdapter(NetworkMapTextBox.class);
+
+      Composite dialogArea = new Composite(parent, SWT.NONE);
+      
+      GridLayout layout = new GridLayout();
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
+      layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
+      layout.numColumns = 3;
+      dialogArea.setLayout(layout);
+      
+
+      GridData gd = new GridData();
+      gd.horizontalSpan = 3;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalAlignment = SWT.FILL;
+      labeledText = WidgetHelper.createLabeledText(dialogArea, SWT.MULTI | SWT.BORDER, SWT.DEFAULT, "Text",
+            textBox.getText(), gd);
+      labeledText.setTextLimit(255);
+      
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      backgroundSelector = WidgetHelper.createLabeledColorSelector(dialogArea, "Background color", gd);
+      backgroundSelector.setColorValue(ColorConverter.rgbFromInt(textBox.getBackgroundColor()));
+      
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      textSelector = WidgetHelper.createLabeledColorSelector(dialogArea, "Text color", gd);
+      textSelector.setColorValue(ColorConverter.rgbFromInt(textBox.getTextColor()));
+
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      borderSelector = WidgetHelper.createLabeledColorSelector(dialogArea, "Border color", gd);
+      borderSelector.setColorValue(ColorConverter.rgbFromInt(textBox.getBorderColor()));
+      
+
+      borderCheck = new Button(dialogArea, SWT.CHECK);
+      borderCheck.setText("Show border");
+      borderCheck.setSelection(textBox.isBorderRequired());
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalSpan = 3;
+      borderCheck.setLayoutData(gd);
+      
+      borderCheck.addSelectionListener(new SelectionListener() {
+         /* (non-Javadoc)
+          * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+          */
+         @Override
+         public void widgetSelected(SelectionEvent e)
+         {
+            borderSelector.setEnabled(borderCheck.getSelection());
+         }
+         /* (non-Javadoc)
+          * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+          */
+         @Override
+         public void widgetDefaultSelected(SelectionEvent e)
+         {
+            widgetSelected(e);
+         }
+      });
+
+      fontSize = WidgetHelper.createLabeledSpinner(dialogArea, SWT.BORDER, "Text size", 1, 100, WidgetHelper.DEFAULT_LAYOUT_DATA);
+      fontSize.setSelection(textBox.getFontSize());
+      
+      drillDownObject = new ObjectSelector(dialogArea, SWT.NONE, true);
+      drillDownObject.setLabel("Drill-down object");
+      drillDownObject.setObjectClass(AbstractObject.class);
+      drillDownObject.setObjectId(textBox.getDrillDownObjectId());
+      drillDownObject.setClassFilter(ObjectSelectionDialog.createDashboardAndNetworkMapSelectionFilter());
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalSpan = 3;
+      drillDownObject.setLayoutData(gd);
+      
+      return dialogArea;
+   }
+
+   /**
+    * Apply changes
+    * 
+    * @param isApply true if update operation caused by "Apply" button
+    */
+   private boolean applyChanges(final boolean isApply)
+   {
+      textBox.setText(labeledText.getText());
+      textBox.setBackgroundColor(ColorConverter.rgbToInt(backgroundSelector.getColorValue()));
+      textBox.setTextColor(ColorConverter.rgbToInt(textSelector.getColorValue()));
+      textBox.setBorderRequired(borderCheck.getSelection());
+      textBox.setBorderColor(ColorConverter.rgbToInt(borderSelector.getColorValue()));
+      textBox.setFontSize(fontSize.getSelection());
+      textBox.setDrillDownObjectId(drillDownObject.getObjectId());
+      return true;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.preference.PreferencePage#performOk()
+    */
+   @Override
+   public boolean performOk()
+   {
+      return applyChanges(false);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.preference.PreferencePage#performApply()
+    */
+   @Override
+   protected void performApply()
+   {
+      applyChanges(true);
+   }
+}
index 84d3b0f..cbed359 100644 (file)
@@ -99,6 +99,7 @@ import org.netxms.client.maps.elements.NetworkMapDCIContainer;
 import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Dashboard;
 import org.netxms.client.objects.NetworkMap;
@@ -1350,37 +1351,39 @@ public abstract class AbstractNetworkMapView extends ViewPart implements ISelect
                if (currentSelection == null)
                        return;
 
+               long objectId = 0;
                Object object = currentSelection.getFirstElement();
                if (object instanceof AbstractObject)
-               {
-                       long objectId = (object instanceof NetworkMap) ? ((AbstractObject)object).getObjectId() : ((AbstractObject)object).getDrillDownObjectId();                      
-                       if (objectId != 0)
-                       {
-                          Object test = session.findObjectById(objectId);
-                if (test instanceof NetworkMap)
-                {
-               try
-               {
-                  getSite().getPage().showView(PredefinedMap.ID, Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
-               }
-               catch(PartInitException e)
-               {
-                  MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
-               }
+                       objectId = (object instanceof NetworkMap) ? ((AbstractObject)object).getObjectId() : ((AbstractObject)object).getDrillDownObjectId();
+               else if (object instanceof NetworkMapTextBox)
+                  objectId = ((NetworkMapTextBox)object).getDrillDownObjectId();
+               
+               if (objectId != 0)
+      {
+         Object test = session.findObjectById(objectId);
+         if (test instanceof NetworkMap)
+         {
+            try
+            {
+               getSite().getPage().showView(PredefinedMap.ID, Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
             }
-                if (test instanceof Dashboard)
-                {
-                               try
-                               {
-                                       getSite().getPage().showView("org.netxms.ui.eclipse.dashboard.views.DashboardView", Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
-                               }
-                               catch(PartInitException e)
-               {
-                  MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
-               }
-                }
-                       }
-               }
+            catch(PartInitException e)
+            {
+               MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
+            }
+         }
+         if (test instanceof Dashboard)
+         {
+            try
+            {
+               getSite().getPage().showView("org.netxms.ui.eclipse.dashboard.views.DashboardView", Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
+            }
+            catch(PartInitException e)
+            {
+               MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
+            }
+         }
+      }
        }
        
        /**
index 255aca8..9309d8b 100644 (file)
@@ -56,6 +56,7 @@ import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.NetworkMap;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
@@ -91,6 +92,8 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
        private Action actionMapProperties;
        private Action actionLinkProperties;
        private Action actionAddDCIImage;
+       private Action actionAddTextBox;
+       private Action actionTextBoxProperties;
        private Color defaultLinkColor = null;
        private boolean readOnly;
 
@@ -389,6 +392,22 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                                showLinkProperties();
                        }
                };
+               
+      actionAddTextBox = new Action("Text box") {
+         @Override
+         public void run()
+         {
+            addTextBoxToMap();
+         }
+      };
+      
+      actionTextBoxProperties = new Action("Text box properties") {
+         @Override
+         public void run()
+         {
+            showTextBoxProperties();
+         }
+      };
        }
 
        /**
@@ -401,6 +420,7 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                MenuManager menu = new MenuManager(Messages.get().PredefinedMap_AddDecoration);
                menu.add(actionAddGroupBox);
                menu.add(actionAddImage);
+               menu.add(actionAddTextBox);
                return menu;
        }
 
@@ -488,6 +508,8 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                   manager.add(actionDCIContainerProperties);
                if(o instanceof NetworkMapDCIImage)
             manager.add(actionDCIImageProperties);
+         if(o instanceof NetworkMapTextBox)
+            manager.add(actionTextBoxProperties);
                manager.add(new Separator());
           }
                super.fillElementContextMenu(manager);
@@ -710,6 +732,20 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
 
                saveMap();
        }
+       
+       /**
+        * Add text box element
+        */
+       private void addTextBoxToMap()
+       {
+      NetworkMapTextBox textBox = new NetworkMapTextBox(mapPage.createElementId());
+      PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, textBox);
+          if (dlg.open() != Window.OK)
+             return;
+          
+      mapPage.addElement(textBox);
+      saveMap();
+       }
 
        /**
         * Save map on server
@@ -782,7 +818,9 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
        @Override
        protected boolean isSelectableElement(Object element)
        {
-               return (element instanceof NetworkMapDecoration) || (element instanceof NetworkMapLink) || (element instanceof NetworkMapDCIContainer) || (element instanceof NetworkMapDCIImage);
+               return (element instanceof NetworkMapDecoration) || (element instanceof NetworkMapLink) ||
+                      (element instanceof NetworkMapDCIContainer) || (element instanceof NetworkMapDCIImage) ||
+                      (element instanceof NetworkMapTextBox);
        }
 
        /* (non-Javadoc)
@@ -948,4 +986,21 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                                saveMap();
                }
        }
+       
+       /**
+        * Show text box properties
+        */
+       private void showTextBoxProperties()
+       {
+      updateObjectPositions();
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+      if ((selection.size() != 1) || !(selection.getFirstElement() instanceof NetworkMapTextBox))
+         return;
+
+      PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, (NetworkMapTextBox)selection.getFirstElement());
+      if (dlg.open() != Window.OK)
+         return;
+
+      saveMap();
+       }
 }
index dd4b0ac..048cb52 100644 (file)
@@ -343,7 +343,7 @@ public class ExtendedGraphViewer extends GraphViewer
                        clearDecorationSelection(false);
                        for(Object o : l)
                        {
-                               if ((o instanceof NetworkMapDecoration) || (o instanceof NetworkMapDCIContainer) || (o instanceof NetworkMapDCIImage))
+                               if ((o instanceof NetworkMapDecoration) || (o instanceof NetworkMapDCIContainer) || (o instanceof NetworkMapDCIImage) || (o instanceof NetworkMapDCIContainer))
                                {
                                        selectedDecorations.add((NetworkMapElement)o);
                                        DecorationLayerAbstractFigure f = decorationFigures.get(((NetworkMapElement)o).getId());
index 36bd19a..0ff791b 100644 (file)
@@ -24,6 +24,7 @@ import org.eclipse.gef4.zest.core.widgets.LayoutFilter;
 import org.netxms.client.maps.elements.NetworkMapDCIContainer;
 import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapDecoration;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 
 /**
  * Custom graph layout filter which prevents decoration
@@ -55,9 +56,9 @@ public class GraphLayoutFilter implements LayoutFilter
                if (item instanceof GraphNode)
                {
                        if (filterDecoration)
-                               return (item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage);
+                               return (item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage || item.getData() instanceof NetworkMapTextBox);
                        else
-                               return !(item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage);
+                               return !(item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage || item.getData() instanceof NetworkMapTextBox);
                }
                return false;
        }
index b75bcb6..b40a516 100644 (file)
@@ -35,6 +35,7 @@ import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractNode;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
@@ -175,7 +176,7 @@ public class MapContentProvider implements IGraphEntityRelationshipContentProvid
 
                List<NetworkMapElement> elements = new ArrayList<NetworkMapElement>(((NetworkMapPage)inputElement).getElements().size());
                for(NetworkMapElement e : ((NetworkMapPage)inputElement).getElements())
-                       if (!(e instanceof NetworkMapDecoration) && !(e instanceof NetworkMapDCIContainer) && !(e instanceof NetworkMapDCIImage))
+                       if (!(e instanceof NetworkMapDecoration) && !(e instanceof NetworkMapDCIContainer) && !(e instanceof NetworkMapDCIImage) && !(e instanceof NetworkMapTextBox))
                                elements.add(e);
                return elements.toArray();
        }
@@ -247,7 +248,7 @@ public class MapContentProvider implements IGraphEntityRelationshipContentProvid
 
                List<NetworkMapElement> elements = new ArrayList<NetworkMapElement>(((NetworkMapPage)inputElement).getElements().size());
                for(NetworkMapElement e : ((NetworkMapPage)inputElement).getElements())
-                       if ((e instanceof NetworkMapDecoration) || (e instanceof NetworkMapDCIContainer) || (e instanceof NetworkMapDCIImage))
+                       if ((e instanceof NetworkMapDecoration) || (e instanceof NetworkMapDCIContainer) || (e instanceof NetworkMapDCIImage) || (e instanceof NetworkMapTextBox))
                                elements.add((NetworkMapElement)e);
                return elements;
        }
index 195ec93..355abe0 100644 (file)
@@ -58,6 +58,7 @@ import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
 import org.netxms.client.maps.elements.NetworkMapResource;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Node;
 import org.netxms.client.objects.UnknownObject;
@@ -289,6 +290,10 @@ public class MapLabelProvider extends LabelProvider implements IFigureProvider,
       {
          return new DCIImageFigure((NetworkMapDCIImage)element, this, viewer);
       }
+               if (element instanceof NetworkMapTextBox)
+               {
+                  return new TextBoxFigure((NetworkMapTextBox)element, this, viewer);
+               }
                return null;
        }
 
diff --git a/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java b/src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java
new file mode 100644 (file)
index 0000000..cd9d13f
--- /dev/null
@@ -0,0 +1,111 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2017 Raden Solutions
+ *
+ * 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.networkmaps.views.helpers;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.widgets.Display;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
+import org.netxms.ui.eclipse.tools.ColorConverter;
+
+public class TextBoxFigure extends DecorationLayerAbstractFigure
+{
+   private static final int BORDER_SIZE = 7;
+   private static final int MARGIN = 7;
+   
+   private Label text;
+   private NetworkMapTextBox textBoxElement;
+   private MapLabelProvider labelProvider;
+
+   /**
+    * Create a text box figure
+    * 
+    * @param decoration
+    * @param viewer
+    */
+   public TextBoxFigure(NetworkMapTextBox decoration, MapLabelProvider labelProvider, ExtendedGraphViewer viewer)
+   {
+      super(decoration, viewer);
+      this.textBoxElement = decoration;
+      this.labelProvider = labelProvider;
+
+      text = new Label(textBoxElement.getText());
+      text.setFont(new Font(Display.getCurrent(), "Verdana", textBoxElement.getFontSize(), SWT.NONE));
+      add(text);
+      
+      Dimension d = text.getPreferredSize();
+      text.setSize(d.width+MARGIN, d.height+MARGIN);
+      int border = 0;
+      if(textBoxElement.isBorderRequired())
+      {
+         text.setLocation(new Point(BORDER_SIZE, BORDER_SIZE));
+         border = BORDER_SIZE;
+      }
+      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);
+      
+      text.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
+      text.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));  
+   }
+   
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.networkmaps.views.helpers.DecorationLayerAbstractFigure#paintFigure(org.eclipse.draw2d.Graphics)
+    */
+   @Override
+   protected void paintFigure(Graphics gc)
+   {
+      gc.setAntialias(SWT.ON);
+      
+      if(textBoxElement.isBorderRequired())
+      {
+         Rectangle rect = new Rectangle(text.getClientArea());
+         
+         gc.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));
+         gc.setLineWidth(BORDER_SIZE);
+         gc.setLineStyle(SWT.LINE_SOLID);
+         gc.drawRoundRectangle(rect, 8, 8);         
+      }
+
+      gc.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
+      gc.fillRoundRectangle(text.getBounds(), 8, 8);
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.networkmaps.views.helpers.DecorationLayerAbstractFigure#refresh()
+    */
+   @Override
+   public void refresh()
+   {
+      //Set new label text
+      text.setText(textBoxElement.getText());
+      
+      //Recalculate figure size
+      Dimension d = text.getPreferredSize();
+      text.setSize(d.width+MARGIN, d.height+MARGIN);
+      int border = textBoxElement.isBorderRequired() ? BORDER_SIZE : 0;
+      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);    
+      
+      repaint();
+   }
+
+}
index ba7c7af..f4d161c 100644 (file)
@@ -473,6 +473,9 @@ bool NetworkMap::loadFromDatabase(DB_HANDLE hdb, UINT32 dwId)
                   case MAP_ELEMENT_DCI_IMAGE:
                      e = new NetworkMapDCIImage(id, config, flags);
                      break;
+                  case MAP_ELEMENT_TEXT_BOX:
+                     e = new NetworkMapTextBox(id, config, flags);
+                     break;
                                                default:                // Unknown type, create generic element
                                                        e = new NetworkMapElement(id, config, flags);
                                                        break;
@@ -652,6 +655,9 @@ UINT32 NetworkMap::modifyFromMessageInternal(NXCPMessage *request)
                case MAP_ELEMENT_DCI_IMAGE:
                   e = new NetworkMapDCIImage(request, varId);
                   break;
+               case MAP_ELEMENT_TEXT_BOX:
+                  e = new NetworkMapTextBox(request, varId);
+                  break;
                                        default:                // Unknown type, create generic element
                                                e = new NetworkMapElement(request, varId);
                                                break;
index 48745d6..59a6818 100644 (file)
@@ -396,3 +396,68 @@ json_t *NetworkMapDCIImage::toJson() const
    json_object_set_new(root, "config", json_string_t(m_config));
    return root;
 }
+
+/**************************
+ * Network Map Text Box
+ **************************/
+
+/**
+ * Text Box default constructor
+ */
+NetworkMapTextBox::NetworkMapTextBox(UINT32 id, TCHAR* config, UINT32 flags) : NetworkMapElement(id, flags)
+{
+   m_type = MAP_ELEMENT_TEXT_BOX;
+   m_config = _tcsdup(config);
+}
+
+/**
+ * Text Box config constructor
+ */
+NetworkMapTextBox::NetworkMapTextBox(UINT32 id, Config *config, UINT32 flags) : NetworkMapElement(id, config, flags)
+{
+   m_config = _tcsdup(config->getValue(_T("/TextBox"), _T("")));
+}
+
+/**
+ * DCI image NXCP constructor
+ */
+NetworkMapTextBox::NetworkMapTextBox(NXCPMessage *msg, UINT32 baseId) : NetworkMapElement(msg, baseId)
+{
+   m_config = msg->getFieldAsString(baseId + 10);
+}
+
+/**
+ * DCI image destructor
+ */
+NetworkMapTextBox::~NetworkMapTextBox()
+{
+   free(m_config);
+}
+
+/**
+ * Update image's persistent configuration
+ */
+void NetworkMapTextBox::updateConfig(Config *config)
+{
+   NetworkMapElement::updateConfig(config);
+   config->setValue(_T("/TextBox"), m_config);
+}
+
+/**
+ * Fill NXCP message with container's data
+ */
+void NetworkMapTextBox::fillMessage(NXCPMessage *msg, UINT32 baseId)
+{
+   NetworkMapElement::fillMessage(msg, baseId);
+   msg->setField(baseId + 10, m_config);
+}
+
+/**
+ * Serialize to JSON
+ */
+json_t *NetworkMapTextBox::toJson() const
+{
+   json_t *root = NetworkMapElement::toJson();
+   json_object_set_new(root, "config", json_string_t(m_config));
+   return root;
+}
index 4659d3e..afb6699 100644 (file)
@@ -108,6 +108,7 @@ public:
 #define MAP_ELEMENT_DECORATION      2
 #define MAP_ELEMENT_DCI_CONTAINER   3
 #define MAP_ELEMENT_DCI_IMAGE       4
+#define MAP_ELEMENT_TEXT_BOX        5
 
 /**
  * Decoration types
@@ -232,18 +233,18 @@ public:
 };
 
 /**
- * DCI map image
+ * Network map text box
  */
-class NetworkMapDCIImage : public NetworkMapElement
+class NetworkMapTextBox : public NetworkMapElement
 {
 protected:
        TCHAR *m_config;
 
 public:
-       NetworkMapDCIImage(UINT32 id, TCHAR* objectDCIList, UINT32 flags = 0);
-       NetworkMapDCIImage(UINT32 id, Config *config, UINT32 flags = 0);
-       NetworkMapDCIImage(NXCPMessage *msg, UINT32 baseId);
-       virtual ~NetworkMapDCIImage();
+       NetworkMapTextBox(UINT32 id, TCHAR* objectDCIList, UINT32 flags = 0);
+       NetworkMapTextBox(UINT32 id, Config *config, UINT32 flags = 0);
+       NetworkMapTextBox(NXCPMessage *msg, UINT32 baseId);
+       virtual ~NetworkMapTextBox();
 
        virtual void updateConfig(Config *config);
        virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
@@ -253,6 +254,27 @@ public:
 };
 
 /**
+ * DCI map image
+ */
+class NetworkMapDCIImage : public NetworkMapElement
+{
+protected:
+   TCHAR *m_config;
+
+public:
+   NetworkMapDCIImage(UINT32 id, TCHAR* objectDCIList, UINT32 flags = 0);
+   NetworkMapDCIImage(UINT32 id, Config *config, UINT32 flags = 0);
+   NetworkMapDCIImage(NXCPMessage *msg, UINT32 baseId);
+   virtual ~NetworkMapDCIImage();
+
+   virtual void updateConfig(Config *config);
+   virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
+   virtual json_t *toJson() const;
+
+   TCHAR *getObjectDCIList() const { return m_config; }
+};
+
+/**
  * Link on map
  */
 class NetworkMapLink
index 41648bb..0098046 100644 (file)
             </instanceof>
          </enabledWhen>
       </page>
+      <page
+            class="org.netxms.ui.eclipse.networkmaps.propertypages.GeneralTextBox"
+            id="org.netxms.ui.eclipse.networkmaps.propertypages.GeneralTextBox#0"
+            name="General">
+         <enabledWhen>
+            <instanceof
+                  value="org.netxms.client.maps.elements.NetworkMapTextBox">
+            </instanceof>
+         </enabledWhen>
+      </page>
    </extension>
    <extension
          point="org.eclipse.ui.bindings">
diff --git a/webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/propertypages/GeneralTextBox.java b/webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/propertypages/GeneralTextBox.java
new file mode 100644 (file)
index 0000000..838e99a
--- /dev/null
@@ -0,0 +1,178 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2017 Raden Solutions
+ *
+ * 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.networkmaps.propertypages;
+
+import org.eclipse.jface.preference.ColorSelector;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Text;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
+import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;
+import org.netxms.ui.eclipse.tools.ColorConverter;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+
+/**
+ * Text box property page for network map element
+ */
+public class GeneralTextBox extends PropertyPage
+{
+   private Text labeledText;
+   private ColorSelector backgroundSelector;
+   private ColorSelector textSelector;
+   private ColorSelector borderSelector;
+   private Button borderCheck;
+   private Spinner fontSize;
+   private NetworkMapTextBox textBox;
+   private ObjectSelector drillDownObject;
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   protected Control createContents(Composite parent)
+   {
+      textBox = (NetworkMapTextBox)getElement().getAdapter(NetworkMapTextBox.class);
+
+      Composite dialogArea = new Composite(parent, SWT.NONE);
+      
+      GridLayout layout = new GridLayout();
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
+      layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
+      layout.numColumns = 3;
+      dialogArea.setLayout(layout);
+      
+
+      GridData gd = new GridData();
+      gd.horizontalSpan = 3;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalAlignment = SWT.FILL;
+      labeledText = WidgetHelper.createLabeledText(dialogArea, SWT.MULTI | SWT.BORDER, SWT.DEFAULT, "Text",
+            textBox.getText(), gd);
+      labeledText.setTextLimit(255);
+      
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      backgroundSelector = WidgetHelper.createLabeledColorSelector(dialogArea, "Background color", gd);
+      backgroundSelector.setColorValue(ColorConverter.rgbFromInt(textBox.getBackgroundColor()));
+      
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      textSelector = WidgetHelper.createLabeledColorSelector(dialogArea, "Text color", gd);
+      textSelector.setColorValue(ColorConverter.rgbFromInt(textBox.getTextColor()));
+
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      borderSelector = WidgetHelper.createLabeledColorSelector(dialogArea, "Border color", gd);
+      borderSelector.setColorValue(ColorConverter.rgbFromInt(textBox.getBorderColor()));
+      
+
+      borderCheck = new Button(dialogArea, SWT.CHECK);
+      borderCheck.setText("Show border");
+      borderCheck.setSelection(textBox.isBorderRequired());
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalSpan = 3;
+      borderCheck.setLayoutData(gd);
+      
+      borderCheck.addSelectionListener(new SelectionListener() {
+         /* (non-Javadoc)
+          * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+          */
+         @Override
+         public void widgetSelected(SelectionEvent e)
+         {
+            borderSelector.setEnabled(borderCheck.getSelection());
+         }
+         /* (non-Javadoc)
+          * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+          */
+         @Override
+         public void widgetDefaultSelected(SelectionEvent e)
+         {
+            widgetSelected(e);
+         }
+      });
+
+      fontSize = WidgetHelper.createLabeledSpinner(dialogArea, SWT.BORDER, "Text size", 1, 100, WidgetHelper.DEFAULT_LAYOUT_DATA);
+      fontSize.setSelection(textBox.getFontSize());
+      
+      drillDownObject = new ObjectSelector(dialogArea, SWT.NONE, true);
+      drillDownObject.setLabel("Drill-down object");
+      drillDownObject.setObjectClass(AbstractObject.class);
+      drillDownObject.setObjectId(textBox.getDrillDownObjectId());
+      drillDownObject.setClassFilter(ObjectSelectionDialog.createDashboardAndNetworkMapSelectionFilter());
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalSpan = 3;
+      drillDownObject.setLayoutData(gd);
+      
+      return dialogArea;
+   }
+
+   /**
+    * Apply changes
+    * 
+    * @param isApply true if update operation caused by "Apply" button
+    */
+   private boolean applyChanges(final boolean isApply)
+   {
+      textBox.setText(labeledText.getText());
+      textBox.setBackgroundColor(ColorConverter.rgbToInt(backgroundSelector.getColorValue()));
+      textBox.setTextColor(ColorConverter.rgbToInt(textSelector.getColorValue()));
+      textBox.setBorderRequired(borderCheck.getSelection());
+      textBox.setBorderColor(ColorConverter.rgbToInt(borderSelector.getColorValue()));
+      textBox.setFontSize(fontSize.getSelection());
+      textBox.setDrillDownObjectId(drillDownObject.getObjectId());
+      return true;
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.preference.PreferencePage#performOk()
+    */
+   @Override
+   public boolean performOk()
+   {
+      return applyChanges(false);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.preference.PreferencePage#performApply()
+    */
+   @Override
+   protected void performApply()
+   {
+      applyChanges(true);
+   }
+}
index 122c580..6d40ccc 100644 (file)
@@ -95,6 +95,7 @@ import org.netxms.client.maps.elements.NetworkMapDCIContainer;
 import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Dashboard;
 import org.netxms.client.objects.NetworkMap;
@@ -1331,37 +1332,39 @@ public abstract class AbstractNetworkMapView extends ViewPart implements ISelect
                if (currentSelection == null)
                        return;
 
+               long objectId = 0;
                Object object = currentSelection.getFirstElement();
                if (object instanceof AbstractObject)
-               {
-                       long objectId = (object instanceof NetworkMap) ? ((AbstractObject)object).getObjectId() : ((AbstractObject)object).getDrillDownObjectId();                      
-                       if (objectId != 0)
-                       {
-                          Object test = session.findObjectById(objectId);
-                if (test instanceof NetworkMap)
-                {
-               try
-               {
-                  getSite().getPage().showView(PredefinedMap.ID, Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
-               }
-               catch(PartInitException e)
-               {
-                  MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
-               }
+                       objectId = (object instanceof NetworkMap) ? ((AbstractObject)object).getObjectId() : ((AbstractObject)object).getDrillDownObjectId();
+               else if (object instanceof NetworkMapTextBox)
+                  objectId = ((NetworkMapTextBox)object).getDrillDownObjectId();
+               
+               if (objectId != 0)
+      {
+         Object test = session.findObjectById(objectId);
+         if (test instanceof NetworkMap)
+         {
+            try
+            {
+               getSite().getPage().showView(PredefinedMap.ID, Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
             }
-                if (test instanceof Dashboard)
-                {
-                               try
-                               {
-                                       getSite().getPage().showView("org.netxms.ui.eclipse.dashboard.views.DashboardView", Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
-                               }
-                               catch(PartInitException e)
-               {
-                  MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
-               }
-                }
-                       }
-               }
+            catch(PartInitException e)
+            {
+               MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
+            }
+         }
+         if (test instanceof Dashboard)
+         {
+            try
+            {
+               getSite().getPage().showView("org.netxms.ui.eclipse.dashboard.views.DashboardView", Long.toString(objectId), IWorkbenchPage.VIEW_ACTIVATE);
+            }
+            catch(PartInitException e)
+            {
+               MessageDialogHelper.openError(getSite().getShell(), Messages.get().AbstractNetworkMapView_Error, String.format("Cannot open drill-down object view: %s", e.getMessage()));
+            }
+         }
+      }
        }
        
        /**
index 28c69c8..147e08e 100644 (file)
@@ -57,6 +57,7 @@ import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.NetworkMap;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
@@ -92,6 +93,8 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
        private Action actionMapProperties;
        private Action actionLinkProperties;
        private Action actionAddDCIImage;
+       private Action actionAddTextBox;
+       private Action actionTextBoxProperties;
        private Color defaultLinkColor = null;
        private boolean readOnly;
        private Display display;
@@ -393,6 +396,22 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                                showLinkProperties();
                        }
                };
+               
+      actionAddTextBox = new Action("Text box") {
+         @Override
+         public void run()
+         {
+            addTextBoxToMap();
+         }
+      };
+      
+      actionTextBoxProperties = new Action("Text box properties") {
+         @Override
+         public void run()
+         {
+            showTextBoxProperties();
+         }
+      };
        }
 
        /**
@@ -405,6 +424,7 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                MenuManager menu = new MenuManager(Messages.get().PredefinedMap_AddDecoration);
                menu.add(actionAddGroupBox);
                menu.add(actionAddImage);
+               menu.add(actionAddTextBox);
                return menu;
        }
 
@@ -492,6 +512,8 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                   manager.add(actionDCIContainerProperties);
                if(o instanceof NetworkMapDCIImage)
             manager.add(actionDCIImageProperties);
+         if(o instanceof NetworkMapTextBox)
+            manager.add(actionTextBoxProperties);
                manager.add(new Separator());
           }
                super.fillElementContextMenu(manager);
@@ -714,6 +736,20 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
 
                saveMap();
        }
+       
+       /**
+        * Add text box element
+        */
+       private void addTextBoxToMap()
+       {
+      NetworkMapTextBox textBox = new NetworkMapTextBox(mapPage.createElementId());
+      PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, textBox);
+          if (dlg.open() != Window.OK)
+             return;
+          
+      mapPage.addElement(textBox);
+      saveMap();
+       }
 
        /**
         * Save map on server
@@ -786,7 +822,9 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
        @Override
        protected boolean isSelectableElement(Object element)
        {
-               return (element instanceof NetworkMapDecoration) || (element instanceof NetworkMapLink) || (element instanceof NetworkMapDCIContainer) || (element instanceof NetworkMapDCIImage);
+               return (element instanceof NetworkMapDecoration) || (element instanceof NetworkMapLink) ||
+                      (element instanceof NetworkMapDCIContainer) || (element instanceof NetworkMapDCIImage) ||
+                      (element instanceof NetworkMapTextBox);
        }
 
        /* (non-Javadoc)
@@ -954,4 +992,21 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
                                saveMap();
                }
        }
+       
+       /**
+        * Show text box properties
+        */
+       private void showTextBoxProperties()
+       {
+      updateObjectPositions();
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+      if ((selection.size() != 1) || !(selection.getFirstElement() instanceof NetworkMapTextBox))
+         return;
+
+      PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, (NetworkMapTextBox)selection.getFirstElement());
+      if (dlg.open() != Window.OK)
+         return;
+
+      saveMap();
+       }
 }
index 6d25d92..0b0a534 100644 (file)
@@ -342,7 +342,7 @@ public class ExtendedGraphViewer extends GraphViewer
                        clearDecorationSelection(false);
                        for(Object o : l)
                        {
-                               if ((o instanceof NetworkMapDecoration) || (o instanceof NetworkMapDCIContainer) || (o instanceof NetworkMapDCIImage))
+                               if ((o instanceof NetworkMapDecoration) || (o instanceof NetworkMapDCIContainer) || (o instanceof NetworkMapDCIImage) || (o instanceof NetworkMapDCIContainer))
                                {
                                        selectedDecorations.add((NetworkMapElement)o);
                                        DecorationLayerAbstractFigure f = decorationFigures.get(((NetworkMapElement)o).getId());
index 36bd19a..0ff791b 100644 (file)
@@ -24,6 +24,7 @@ import org.eclipse.gef4.zest.core.widgets.LayoutFilter;
 import org.netxms.client.maps.elements.NetworkMapDCIContainer;
 import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapDecoration;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 
 /**
  * Custom graph layout filter which prevents decoration
@@ -55,9 +56,9 @@ public class GraphLayoutFilter implements LayoutFilter
                if (item instanceof GraphNode)
                {
                        if (filterDecoration)
-                               return (item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage);
+                               return (item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage || item.getData() instanceof NetworkMapTextBox);
                        else
-                               return !(item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage);
+                               return !(item.getData() instanceof NetworkMapDecoration || item.getData() instanceof NetworkMapDCIContainer || item.getData() instanceof NetworkMapDCIImage || item.getData() instanceof NetworkMapTextBox);
                }
                return false;
        }
index b75bcb6..b40a516 100644 (file)
@@ -35,6 +35,7 @@ import org.netxms.client.maps.elements.NetworkMapDCIImage;
 import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractNode;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
@@ -175,7 +176,7 @@ public class MapContentProvider implements IGraphEntityRelationshipContentProvid
 
                List<NetworkMapElement> elements = new ArrayList<NetworkMapElement>(((NetworkMapPage)inputElement).getElements().size());
                for(NetworkMapElement e : ((NetworkMapPage)inputElement).getElements())
-                       if (!(e instanceof NetworkMapDecoration) && !(e instanceof NetworkMapDCIContainer) && !(e instanceof NetworkMapDCIImage))
+                       if (!(e instanceof NetworkMapDecoration) && !(e instanceof NetworkMapDCIContainer) && !(e instanceof NetworkMapDCIImage) && !(e instanceof NetworkMapTextBox))
                                elements.add(e);
                return elements.toArray();
        }
@@ -247,7 +248,7 @@ public class MapContentProvider implements IGraphEntityRelationshipContentProvid
 
                List<NetworkMapElement> elements = new ArrayList<NetworkMapElement>(((NetworkMapPage)inputElement).getElements().size());
                for(NetworkMapElement e : ((NetworkMapPage)inputElement).getElements())
-                       if ((e instanceof NetworkMapDecoration) || (e instanceof NetworkMapDCIContainer) || (e instanceof NetworkMapDCIImage))
+                       if ((e instanceof NetworkMapDecoration) || (e instanceof NetworkMapDCIContainer) || (e instanceof NetworkMapDCIImage) || (e instanceof NetworkMapTextBox))
                                elements.add((NetworkMapElement)e);
                return elements;
        }
index 38e1d03..b1c4dbb 100644 (file)
@@ -59,6 +59,7 @@ import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
 import org.netxms.client.maps.elements.NetworkMapResource;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Node;
 import org.netxms.client.objects.UnknownObject;
@@ -290,6 +291,10 @@ public class MapLabelProvider extends LabelProvider implements IFigureProvider,
       {
          return new DCIImageFigure((NetworkMapDCIImage)element, this, viewer);
       }
+               if (element instanceof NetworkMapTextBox)
+               {
+                  return new TextBoxFigure((NetworkMapTextBox)element, this, viewer);
+               }
                return null;
        }
 
diff --git a/webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java b/webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java
new file mode 100644 (file)
index 0000000..331f515
--- /dev/null
@@ -0,0 +1,111 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2017 Raden Solutions
+ *
+ * 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.networkmaps.views.helpers;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.widgets.Display;
+import org.netxms.client.maps.elements.NetworkMapTextBox;
+import org.netxms.ui.eclipse.tools.ColorConverter;
+
+public class TextBoxFigure extends DecorationLayerAbstractFigure
+{
+   private static final int BORDER_SIZE = 7;
+   private static final int MARGIN = 7;
+   
+   private Label text;
+   private NetworkMapTextBox textBoxElement;
+   private MapLabelProvider labelProvider;
+
+   /**
+    * Create a text box figure
+    * 
+    * @param decoration
+    * @param viewer
+    */
+   public TextBoxFigure(NetworkMapTextBox decoration, MapLabelProvider labelProvider, ExtendedGraphViewer viewer)
+   {
+      super(decoration, viewer);
+      this.textBoxElement = decoration;
+      this.labelProvider = labelProvider;
+
+      text = new Label(textBoxElement.getText());
+      text.setFont(new Font(Display.getCurrent(), "Verdana", textBoxElement.getFontSize(), SWT.NONE));
+      add(text);
+      
+      Dimension d = text.getPreferredSize();
+      text.setSize(d.width+MARGIN, d.height+MARGIN);
+      int border = 0;
+      if(textBoxElement.isBorderRequired())
+      {
+         text.setLocation(new Point(BORDER_SIZE, BORDER_SIZE));
+         border = BORDER_SIZE;
+      }
+      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);
+      
+      text.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
+      text.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));  
+   }
+   
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.networkmaps.views.helpers.DecorationLayerAbstractFigure#paintFigure(org.eclipse.draw2d.Graphics)
+    */
+   @Override
+   protected void paintFigure(Graphics gc)
+   {
+      gc.setAntialias(SWT.ON);
+      
+      if(textBoxElement.isBorderRequired())
+      {
+         Rectangle rect = new Rectangle(text.getClientArea());
+         
+         gc.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));
+         gc.setLineWidth(BORDER_SIZE);
+         //gc.setLineStyle(SWT.LINE);
+         gc.drawRoundRectangle(rect, 8, 8);         
+      }
+
+      gc.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
+      gc.fillRoundRectangle(text.getBounds(), 8, 8);
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.ui.eclipse.networkmaps.views.helpers.DecorationLayerAbstractFigure#refresh()
+    */
+   @Override
+   public void refresh()
+   {
+      //Set new label text
+      text.setText(textBoxElement.getText());
+      
+      //Recalculate figure size
+      Dimension d = text.getPreferredSize();
+      text.setSize(d.width+MARGIN, d.height+MARGIN);
+      int border = textBoxElement.isBorderRequired() ? BORDER_SIZE : 0;
+      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);    
+      
+      repaint();
+   }
+
+}