Implemented group box decoration edit in network maps. Fixes #NX-1366
authorEriks Jenkevics <eriks@netxms.org>
Tue, 5 Dec 2017 15:53:51 +0000 (17:53 +0200)
committerEriks Jenkevics <eriks@netxms.org>
Wed, 6 Dec 2017 17:01:38 +0000 (19:01 +0200)
src/client/java/netxms-client/src/main/java/org/netxms/client/maps/elements/NetworkMapDecoration.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/dialogs/EditGroupBoxDialog.java [moved from src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/dialogs/AddGroupBoxDialog.java with 85% similarity]
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/PredefinedMap.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/dialogs/EditGroupBoxDialog.java [moved from webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/dialogs/AddGroupBoxDialog.java with 85% similarity]
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/PredefinedMap.java

index 0f04750..009dcf8 100644 (file)
@@ -61,8 +61,8 @@ public class NetworkMapDecoration extends NetworkMapElement
                type = MAP_ELEMENT_DECORATION;
                this.decorationType = decorationType;
                title = "";
-               width = 50;
-               height = 20;
+               width = 250;
+               height = 100;
                color = 0;
        }
 
@@ -28,7 +28,9 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Spinner;
+import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.ui.eclipse.networkmaps.Messages;
+import org.netxms.ui.eclipse.tools.ColorConverter;
 import org.netxms.ui.eclipse.tools.WidgetFactory;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 import org.netxms.ui.eclipse.widgets.LabeledText;
@@ -37,27 +39,24 @@ import org.netxms.ui.eclipse.widgets.LabeledText;
  * Dialog for adding group box decoration
  *
  */
-public class AddGroupBoxDialog extends Dialog
+public class EditGroupBoxDialog extends Dialog
 {
        private static final RGB DEFAULT_COLOR = new RGB(64, 105, 156);
        
-       private String title;
-       private int width;
-       private int height;
-       private RGB color;
-       
        private LabeledText textTitle;
        private Spinner spinnerWidth;
        private Spinner spinnerHeight;
        private ColorSelector colorSelector;
+       private NetworkMapDecoration groupBox;
        
        /**
         * 
         * @param parentShell
         */
-       public AddGroupBoxDialog(Shell parentShell)
+       public EditGroupBoxDialog(Shell parentShell, NetworkMapDecoration groupBox)
        {
-               super(parentShell);
+      super(parentShell);
+          this.groupBox = groupBox;
        }
 
        /* (non-Javadoc)
@@ -87,6 +86,7 @@ public class AddGroupBoxDialog extends Dialog
                /* title */
                textTitle = new LabeledText(dialogArea, SWT.NONE);
                textTitle.setLabel(Messages.get().AddGroupBoxDialog_Title);
+               textTitle.setText(groupBox.getTitle());
                GridData gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -117,9 +117,9 @@ public class AddGroupBoxDialog extends Dialog
                        }
                };
                spinnerWidth = (Spinner)WidgetHelper.createLabeledControl(attrArea, SWT.NONE, factory, Messages.get().AddGroupBoxDialog_Width, WidgetHelper.DEFAULT_LAYOUT_DATA);
-               spinnerWidth.setSelection(250);
+               spinnerWidth.setSelection(groupBox.getWidth());
                spinnerHeight = (Spinner)WidgetHelper.createLabeledControl(attrArea, SWT.NONE, factory, Messages.get().AddGroupBoxDialog_Height, WidgetHelper.DEFAULT_LAYOUT_DATA);
-               spinnerHeight.setSelection(100);
+               spinnerHeight.setSelection(groupBox.getHeight());
                
                colorSelector = WidgetHelper.createLabeledColorSelector(attrArea, Messages.get().AddGroupBoxDialog_Color, WidgetHelper.DEFAULT_LAYOUT_DATA);
                colorSelector.setColorValue(DEFAULT_COLOR);
@@ -133,42 +133,9 @@ public class AddGroupBoxDialog extends Dialog
        @Override
        protected void okPressed()
        {
-               title = textTitle.getText();
-               width = spinnerWidth.getSelection();
-               height = spinnerHeight.getSelection();
-               color = colorSelector.getColorValue();
+               groupBox.setTitle(textTitle.getText());
+               groupBox.setSize(spinnerWidth.getSelection(), spinnerHeight.getSelection());
+               groupBox.setColor(ColorConverter.rgbToInt(colorSelector.getColorValue()));
                super.okPressed();
        }
-
-       /**
-        * @return the title
-        */
-       public String getTitle()
-       {
-               return title;
-       }
-
-       /**
-        * @return the width
-        */
-       public int getWidth()
-       {
-               return width;
-       }
-
-       /**
-        * @return the height
-        */
-       public int getHeight()
-       {
-               return height;
-       }
-
-       /**
-        * @return the color
-        */
-       public RGB getColor()
-       {
-               return color;
-       }
 }
index 9309d8b..eb0526d 100644 (file)
@@ -66,7 +66,7 @@ import org.netxms.ui.eclipse.imagelibrary.shared.ImageUpdateListener;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.networkmaps.Activator;
 import org.netxms.ui.eclipse.networkmaps.Messages;
-import org.netxms.ui.eclipse.networkmaps.dialogs.AddGroupBoxDialog;
+import org.netxms.ui.eclipse.networkmaps.dialogs.EditGroupBoxDialog;
 import org.netxms.ui.eclipse.networkmaps.views.helpers.LinkEditor;
 import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
 import org.netxms.ui.eclipse.tools.ColorConverter;
@@ -94,6 +94,7 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
        private Action actionAddDCIImage;
        private Action actionAddTextBox;
        private Action actionTextBoxProperties;
+       private Action actionGroupBoxEdit;
        private Color defaultLinkColor = null;
        private boolean readOnly;
 
@@ -408,6 +409,14 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
             showTextBoxProperties();
          }
       };
+      
+      actionGroupBoxEdit = new Action("Group box properties") {
+         @Override
+         public void run()
+         {
+            editGroupBox();
+         }
+      };
        }
 
        /**
@@ -510,6 +519,8 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
             manager.add(actionDCIImageProperties);
          if(o instanceof NetworkMapTextBox)
             manager.add(actionTextBoxProperties);
+         if(o instanceof NetworkMapDecoration)
+            manager.add(actionGroupBoxEdit);
                manager.add(new Separator());
           }
                super.fillElementContextMenu(manager);
@@ -700,14 +711,11 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
         */
        private void addGroupBoxDecoration()
        {
-               AddGroupBoxDialog dlg = new AddGroupBoxDialog(getSite().getShell());
+      NetworkMapDecoration element = new NetworkMapDecoration(mapPage.createElementId(), NetworkMapDecoration.GROUP_BOX);
+               EditGroupBoxDialog dlg = new EditGroupBoxDialog(getSite().getShell(), element);
                if (dlg.open() != Window.OK)
                        return;
-
-               NetworkMapDecoration element = new NetworkMapDecoration(mapPage.createElementId(), NetworkMapDecoration.GROUP_BOX);
-               element.setSize(dlg.getWidth(), dlg.getHeight());
-               element.setTitle(dlg.getTitle());
-               element.setColor(ColorConverter.rgbToInt(dlg.getColor()));
+               
                mapPage.addElement(element);
 
                saveMap();
@@ -1003,4 +1011,22 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
 
       saveMap();
        }
+       
+       /**
+        * Edit group box
+        */
+       private void editGroupBox()
+       {
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+      if ((selection.size() != 1) || !(selection.getFirstElement() instanceof NetworkMapDecoration))
+         return;
+      
+      NetworkMapDecoration groupBox = (NetworkMapDecoration)selection.getFirstElement();
+      EditGroupBoxDialog dlg = new EditGroupBoxDialog(getSite().getShell(), groupBox);
+      if (dlg.open() == Window.OK)
+      {
+         mapPage.addElement(groupBox);
+         saveMap();
+      }
+       }
 }
@@ -28,7 +28,9 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Spinner;
+import org.netxms.client.maps.elements.NetworkMapDecoration;
 import org.netxms.ui.eclipse.networkmaps.Messages;
+import org.netxms.ui.eclipse.tools.ColorConverter;
 import org.netxms.ui.eclipse.tools.WidgetFactory;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 import org.netxms.ui.eclipse.widgets.LabeledText;
@@ -37,27 +39,24 @@ import org.netxms.ui.eclipse.widgets.LabeledText;
  * Dialog for adding group box decoration
  *
  */
-public class AddGroupBoxDialog extends Dialog
+public class EditGroupBoxDialog extends Dialog
 {
        private static final RGB DEFAULT_COLOR = new RGB(64, 105, 156);
        
-       private String title;
-       private int width;
-       private int height;
-       private RGB color;
-       
        private LabeledText textTitle;
        private Spinner spinnerWidth;
        private Spinner spinnerHeight;
        private ColorSelector colorSelector;
+       private NetworkMapDecoration groupBox;
        
        /**
         * 
         * @param parentShell
         */
-       public AddGroupBoxDialog(Shell parentShell)
+       public EditGroupBoxDialog(Shell parentShell, NetworkMapDecoration groupBox)
        {
-               super(parentShell);
+      super(parentShell);
+          this.groupBox = groupBox;
        }
 
        /* (non-Javadoc)
@@ -87,6 +86,7 @@ public class AddGroupBoxDialog extends Dialog
                /* title */
                textTitle = new LabeledText(dialogArea, SWT.NONE);
                textTitle.setLabel(Messages.get().AddGroupBoxDialog_Title);
+               textTitle.setText(groupBox.getTitle());
                GridData gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
@@ -117,9 +117,9 @@ public class AddGroupBoxDialog extends Dialog
                        }
                };
                spinnerWidth = (Spinner)WidgetHelper.createLabeledControl(attrArea, SWT.NONE, factory, Messages.get().AddGroupBoxDialog_Width, WidgetHelper.DEFAULT_LAYOUT_DATA);
-               spinnerWidth.setSelection(250);
+               spinnerWidth.setSelection(groupBox.getWidth());
                spinnerHeight = (Spinner)WidgetHelper.createLabeledControl(attrArea, SWT.NONE, factory, Messages.get().AddGroupBoxDialog_Height, WidgetHelper.DEFAULT_LAYOUT_DATA);
-               spinnerHeight.setSelection(100);
+               spinnerHeight.setSelection(groupBox.getHeight());
                
                colorSelector = WidgetHelper.createLabeledColorSelector(attrArea, Messages.get().AddGroupBoxDialog_Color, WidgetHelper.DEFAULT_LAYOUT_DATA);
                colorSelector.setColorValue(DEFAULT_COLOR);
@@ -133,42 +133,9 @@ public class AddGroupBoxDialog extends Dialog
        @Override
        protected void okPressed()
        {
-               title = textTitle.getText();
-               width = spinnerWidth.getSelection();
-               height = spinnerHeight.getSelection();
-               color = colorSelector.getColorValue();
+               groupBox.setTitle(textTitle.getText());
+               groupBox.setSize(spinnerWidth.getSelection(), spinnerHeight.getSelection());
+               groupBox.setColor(ColorConverter.rgbToInt(colorSelector.getColorValue()));
                super.okPressed();
        }
-
-       /**
-        * @return the title
-        */
-       public String getTitle()
-       {
-               return title;
-       }
-
-       /**
-        * @return the width
-        */
-       public int getWidth()
-       {
-               return width;
-       }
-
-       /**
-        * @return the height
-        */
-       public int getHeight()
-       {
-               return height;
-       }
-
-       /**
-        * @return the color
-        */
-       public RGB getColor()
-       {
-               return color;
-       }
 }
index 147e08e..9fb0528 100644 (file)
@@ -67,7 +67,7 @@ import org.netxms.ui.eclipse.imagelibrary.shared.ImageUpdateListener;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.networkmaps.Activator;
 import org.netxms.ui.eclipse.networkmaps.Messages;
-import org.netxms.ui.eclipse.networkmaps.dialogs.AddGroupBoxDialog;
+import org.netxms.ui.eclipse.networkmaps.dialogs.EditGroupBoxDialog;
 import org.netxms.ui.eclipse.networkmaps.views.helpers.LinkEditor;
 import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
 import org.netxms.ui.eclipse.tools.ColorConverter;
@@ -95,6 +95,7 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
        private Action actionAddDCIImage;
        private Action actionAddTextBox;
        private Action actionTextBoxProperties;
+       private Action actionGroupBoxEdit;
        private Color defaultLinkColor = null;
        private boolean readOnly;
        private Display display;
@@ -412,6 +413,14 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
             showTextBoxProperties();
          }
       };
+      
+      actionGroupBoxEdit = new Action("Group box properties") {
+         @Override
+         public void run()
+         {
+            editGroupBox();
+         }
+      };
        }
 
        /**
@@ -514,6 +523,8 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
             manager.add(actionDCIImageProperties);
          if(o instanceof NetworkMapTextBox)
             manager.add(actionTextBoxProperties);
+         if(o instanceof NetworkMapDecoration)
+            manager.add(actionGroupBoxEdit);
                manager.add(new Separator());
           }
                super.fillElementContextMenu(manager);
@@ -704,14 +715,11 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
         */
        private void addGroupBoxDecoration()
        {
-               AddGroupBoxDialog dlg = new AddGroupBoxDialog(getSite().getShell());
+      NetworkMapDecoration element = new NetworkMapDecoration(mapPage.createElementId(), NetworkMapDecoration.GROUP_BOX);
+               EditGroupBoxDialog dlg = new EditGroupBoxDialog(getSite().getShell(), element);
                if (dlg.open() != Window.OK)
                        return;
-
-               NetworkMapDecoration element = new NetworkMapDecoration(mapPage.createElementId(), NetworkMapDecoration.GROUP_BOX);
-               element.setSize(dlg.getWidth(), dlg.getHeight());
-               element.setTitle(dlg.getTitle());
-               element.setColor(ColorConverter.rgbToInt(dlg.getColor()));
+               
                mapPage.addElement(element);
 
                saveMap();
@@ -1009,4 +1017,22 @@ public class PredefinedMap extends AbstractNetworkMapView implements ImageUpdate
 
       saveMap();
        }
+       
+       /**
+        * Edit group box
+        */
+       private void editGroupBox()
+       {
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+      if ((selection.size() != 1) || !(selection.getFirstElement() instanceof NetworkMapDecoration))
+         return;
+      
+      NetworkMapDecoration groupBox = (NetworkMapDecoration)selection.getFirstElement();
+      EditGroupBoxDialog dlg = new EditGroupBoxDialog(getSite().getShell(), groupBox);
+      if (dlg.open() == Window.OK)
+      {
+         mapPage.addElement(groupBox);
+         saveMap();
+      }
+       }
 }