DCI is not added if Cancel button is prest on DCI add. Fixes #1237
authorzev <zev@radensolutions.com>
Tue, 14 Jun 2016 16:53:01 +0000 (19:53 +0300)
committerzev <zev@radensolutions.com>
Tue, 14 Jun 2016 16:53:59 +0000 (19:53 +0300)
src/java/client/netxms-client/src/main/java/org/netxms/client/datacollection/DataCollectionConfiguration.java
src/java/client/netxms-client/src/main/java/org/netxms/client/datacollection/DataCollectionItem.java
src/java/client/netxms-client/src/main/java/org/netxms/client/datacollection/DataCollectionObject.java
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/actions/CreateInterfraceDci.java
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/actions/CreateSnmpDci.java
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/api/DataCollectionObjectEditor.java
src/java/netxms-eclipse/DataCollection/src/org/netxms/ui/eclipse/datacollection/views/DataCollectionEditor.java
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/actions/CreateInterfraceDci.java
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/actions/CreateSnmpDci.java
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/api/DataCollectionObjectEditor.java
webui/webapp/DataCollection/src/org/netxms/ui/eclipse/datacollection/views/DataCollectionEditor.java

index c912d85..1e9b793 100644 (file)
@@ -146,7 +146,7 @@ public class DataCollectionConfiguration
         * @throws IOException if socket I/O error occurs
         * @throws NXCException if NetXMS server returns an error or operation was timed out
         */
-       public long createItem() throws IOException, NXCException
+       public long createItem(DataCollectionObject object) throws IOException, NXCException
        {
                NXCPMessage msg = session.newMessage(NXCPCodes.CMD_CREATE_NEW_DCI);
                msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int)nodeId);
@@ -154,7 +154,15 @@ public class DataCollectionConfiguration
                session.sendMessage(msg);
                final NXCPMessage response = session.waitForRCC(msg.getMessageId());
                long id = response.getFieldAsInt64(NXCPCodes.VID_DCI_ID);
-               items.put(id, new DataCollectionItem(this, id));
+               if(object == null)
+               {
+                  items.put(id, new DataCollectionItem(this, id));
+               }
+               else
+               {                  
+             object.setId(id);
+                  items.put(id, object);
+               }
                return id;
        }
        
@@ -165,7 +173,7 @@ public class DataCollectionConfiguration
         * @throws IOException if socket I/O error occurs
         * @throws NXCException if NetXMS server returns an error or operation was timed out
         */
-       public long createTable() throws IOException, NXCException
+       public long createTable(DataCollectionObject object) throws IOException, NXCException
        {
                NXCPMessage msg = session.newMessage(NXCPCodes.CMD_CREATE_NEW_DCI);
                msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int)nodeId);
@@ -173,7 +181,15 @@ public class DataCollectionConfiguration
                session.sendMessage(msg);
                final NXCPMessage response = session.waitForRCC(msg.getMessageId());
                long id = response.getFieldAsInt64(NXCPCodes.VID_DCI_ID);
-               items.put(id, new DataCollectionTable(this, id));
+      if(object == null)
+      {
+         items.put(id, new DataCollectionTable(this, id));
+      }
+      else
+      {        
+         object.setId(id);
+         items.put(id, object);
+      }
                return id;
        }
        
index e2c15b5..b093ac1 100644 (file)
@@ -116,7 +116,7 @@ public class DataCollectionItem extends DataCollectionObject
         * @param owner Owning configuration object
         * @param id Identifier assigned to new item
         */
-       protected DataCollectionItem(final DataCollectionConfiguration owner, long id)
+       public DataCollectionItem(final DataCollectionConfiguration owner, long id)
        {
                super(owner, id);
                
index 5b2c521..4383032 100644 (file)
@@ -616,4 +616,14 @@ public abstract class DataCollectionObject
    {
       flags = (flags & ~DCF_CACHE_MODE_MASK) | ((mode.getValue() & 0x03) << 12);
    }
+   
+   public boolean isNewItem()
+   {
+      return id == 0;
+   }
+   
+   public void setId(long id)
+   {
+      this.id = id;
+   }
 }
index 7631dfb..4dea68b 100644 (file)
@@ -163,7 +163,7 @@ public class CreateInterfraceDci implements IObjectActionDelegate
                        dcc = new DataCollectionConfiguration(session, node.getObjectId());
                }
 
-               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(), DataCollectionItem.class);
+               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
                dci.setPollingInterval(pollingInterval);
                dci.setRetentionTime(retentionTime);
                if (node.hasAgent())
index e5862b5..226cc43 100644 (file)
@@ -162,7 +162,7 @@ public class CreateSnmpDci implements IObjectActionDelegate
                        dcc = new DataCollectionConfiguration(session, node.getObjectId());
                }
 
-               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(), DataCollectionItem.class);
+               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
                dci.setPollingInterval(pollingInterval);
                dci.setRetentionTime(retentionTime);
                dci.setOrigin(DataCollectionItem.SNMP);
index 6816bba..93bce21 100644 (file)
@@ -65,8 +65,16 @@ public class DataCollectionObjectEditor
                        @Override
                        protected void runInternal(IProgressMonitor monitor) throws Exception
                        {
+                               final boolean isNewObj = object.isNewItem();
                                synchronized(DataCollectionObjectEditor.this)
                                {
+                                  if(isNewObj)
+                                  {
+                                     if(object instanceof DataCollectionItem)
+                                        object.getOwner().createItem(object);
+                                     if(object instanceof DataCollectionTable)
+                                        object.getOwner().createTable(object);
+                                  }
                                        object.getOwner().modifyObject(object);
                                }
                                runInUIThread(new Runnable() {
@@ -75,7 +83,13 @@ public class DataCollectionObjectEditor
                                        {
                                                Object data = object.getOwner().getUserData();
                                                if ((data != null) && (data instanceof TableViewer))
+                                               {
+                         if(isNewObj)
+                         {
+                            ((TableViewer)data).setInput(object.getOwner().getItems());
+                         }
                                                        ((TableViewer)data).update(object, null);
+                                               }
                                        }
                                });
                        }
index a3abda3..213bd09 100644 (file)
@@ -641,59 +641,21 @@ public class DataCollectionEditor extends ViewPart
         */
        private void createItem()
        {
-               new ConsoleJob(Messages.get().DataCollectionEditor_CreateJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               final long id = dciConfig.createItem();
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               viewer.setInput(dciConfig.getItems());
-                                               DataCollectionItem dci = (DataCollectionItem)dciConfig.findItem(id, DataCollectionItem.class);
-                                               viewer.setSelection(new StructuredSelection(dci), true);
-                                               actionEdit.run();
-                                       }
-                               });
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().DataCollectionEditor_CreateJob_Error + object.getObjectName();
-                       }
-               }.start();
+      DataCollectionItem dci = new DataCollectionItem(dciConfig, 0);
+      viewer.add(dci);
+      viewer.setSelection(new StructuredSelection(dci), true);
+      actionEdit.run();
        }
        
        /**
         * Create new data collection table
         */
        private void createTable()
-       {
-               new ConsoleJob(Messages.get().DataCollectionEditor_TableCreateJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               final long id = dciConfig.createTable();
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               viewer.setInput(dciConfig.getItems());
-                                               DataCollectionTable dci = (DataCollectionTable)dciConfig.findItem(id, DataCollectionTable.class);
-                                               viewer.setSelection(new StructuredSelection(dci), true);
-                                               actionEdit.run();
-                                       }
-                               });
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().DataCollectionEditor_TableCreateJob_Error + object.getObjectName();
-                       }
-               }.start();
+       {               
+               DataCollectionTable dci = new DataCollectionTable(dciConfig, 0);
+      viewer.add(dci);
+               viewer.setSelection(new StructuredSelection(dci), true);
+               actionEdit.run();
        }
        
        /**
@@ -707,7 +669,11 @@ public class DataCollectionEditor extends ViewPart
                
                ExtendedPropertyDialog dlg = ExtendedPropertyDialog.createDialogOn(getSite().getShell(), null, selection.getFirstElement(), ""); //$NON-NLS-1$
                dlg.createAllPages();
-               dlg.open();
+               int result = dlg.open();
+          if(((DataCollectionObject)selection.getFirstElement()).isNewItem() && result != SWT.OK)
+          {
+         viewer.remove(selection.getFirstElement());
+          }            
        }
        
        /**
index 36a880e..8aa6416 100644 (file)
@@ -163,7 +163,7 @@ public class CreateInterfraceDci implements IObjectActionDelegate
                        dcc = new DataCollectionConfiguration(session, node.getObjectId());
                }
 
-               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(), DataCollectionItem.class);
+               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
                dci.setPollingInterval(pollingInterval);
                dci.setRetentionTime(retentionTime);
                if (node.hasAgent())
index 7146101..7266f9e 100644 (file)
@@ -162,7 +162,7 @@ public class CreateSnmpDci implements IObjectActionDelegate
                        dcc = new DataCollectionConfiguration(session, node.getObjectId());
                }
 
-               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(), DataCollectionItem.class);
+               final DataCollectionItem dci = (DataCollectionItem)dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
                dci.setPollingInterval(pollingInterval);
                dci.setRetentionTime(retentionTime);
                dci.setOrigin(DataCollectionItem.SNMP);
index 6816bba..93bce21 100644 (file)
@@ -65,8 +65,16 @@ public class DataCollectionObjectEditor
                        @Override
                        protected void runInternal(IProgressMonitor monitor) throws Exception
                        {
+                               final boolean isNewObj = object.isNewItem();
                                synchronized(DataCollectionObjectEditor.this)
                                {
+                                  if(isNewObj)
+                                  {
+                                     if(object instanceof DataCollectionItem)
+                                        object.getOwner().createItem(object);
+                                     if(object instanceof DataCollectionTable)
+                                        object.getOwner().createTable(object);
+                                  }
                                        object.getOwner().modifyObject(object);
                                }
                                runInUIThread(new Runnable() {
@@ -75,7 +83,13 @@ public class DataCollectionObjectEditor
                                        {
                                                Object data = object.getOwner().getUserData();
                                                if ((data != null) && (data instanceof TableViewer))
+                                               {
+                         if(isNewObj)
+                         {
+                            ((TableViewer)data).setInput(object.getOwner().getItems());
+                         }
                                                        ((TableViewer)data).update(object, null);
+                                               }
                                        }
                                });
                        }
index ca9d78d..a0b510a 100644 (file)
@@ -641,59 +641,21 @@ public class DataCollectionEditor extends ViewPart
         */
        private void createItem()
        {
-               new ConsoleJob(Messages.get().DataCollectionEditor_CreateJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               final long id = dciConfig.createItem();
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               viewer.setInput(dciConfig.getItems());
-                                               DataCollectionItem dci = (DataCollectionItem)dciConfig.findItem(id, DataCollectionItem.class);
-                                               viewer.setSelection(new StructuredSelection(dci), true);
-                                               actionEdit.run();
-                                       }
-                               });
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().DataCollectionEditor_CreateJob_Error + object.getObjectName();
-                       }
-               }.start();
+      DataCollectionItem dci = new DataCollectionItem(dciConfig, 0);
+      viewer.add(dci);
+      viewer.setSelection(new StructuredSelection(dci), true);
+      actionEdit.run();
        }
        
        /**
         * Create new data collection table
         */
        private void createTable()
-       {
-               new ConsoleJob(Messages.get().DataCollectionEditor_TableCreateJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               final long id = dciConfig.createTable();
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               viewer.setInput(dciConfig.getItems());
-                                               DataCollectionTable dci = (DataCollectionTable)dciConfig.findItem(id, DataCollectionTable.class);
-                                               viewer.setSelection(new StructuredSelection(dci), true);
-                                               actionEdit.run();
-                                       }
-                               });
-                       }
-
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().DataCollectionEditor_TableCreateJob_Error + object.getObjectName();
-                       }
-               }.start();
+       {               
+               DataCollectionTable dci = new DataCollectionTable(dciConfig, 0);
+      viewer.add(dci);
+               viewer.setSelection(new StructuredSelection(dci), true);
+               actionEdit.run();
        }
        
        /**
@@ -707,7 +669,11 @@ public class DataCollectionEditor extends ViewPart
                
                ExtendedPropertyDialog dlg = ExtendedPropertyDialog.createDialogOn(getSite().getShell(), null, selection.getFirstElement(), ""); //$NON-NLS-1$
                dlg.createAllPages();
-               dlg.open();
+               int result = dlg.open();
+          if(((DataCollectionObject)selection.getFirstElement()).isNewItem() && result != SWT.OK)
+          {
+         viewer.remove(selection.getFirstElement());
+          }            
        }
        
        /**