Added option to rerun schedule
authorzev <zev@radensolutions.com>
Thu, 15 Oct 2015 14:40:51 +0000 (17:40 +0300)
committerzev <zev@radensolutions.com>
Thu, 15 Oct 2015 14:40:51 +0000 (17:40 +0300)
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/MaintanenceScheduleDialog.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/RerunTimeDialog.java [new file with mode: 0644]
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ScheduledTaskView.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryComparator.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryLabelProvider.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/RerunTimeDialog.java [new file with mode: 0644]
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ScheduledTaskView.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryComparator.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryLabelProvider.java

index 6bc188b..10febe1 100644 (file)
@@ -3,17 +3,14 @@ package org.netxms.ui.eclipse.objectmanager.dialogs;
 import java.util.Date;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
-import org.netxms.ui.eclipse.objectmanager.Messages;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 import org.netxms.ui.eclipse.widgets.DateTimeSelector;
-import org.netxms.ui.eclipse.widgets.LabeledText;
 
 public class MaintanenceScheduleDialog extends Dialog
 {
diff --git a/src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/RerunTimeDialog.java b/src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/RerunTimeDialog.java
new file mode 100644 (file)
index 0000000..2a99394
--- /dev/null
@@ -0,0 +1,82 @@
+package org.netxms.ui.eclipse.serverconfig.dialogs;
+
+import java.util.Date;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.netxms.ui.eclipse.tools.WidgetFactory;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.DateTimeSelector;
+
+public class RerunTimeDialog extends Dialog
+{
+   private Date rerunDate;
+   private DateTimeSelector dateSelector;
+
+   public RerunTimeDialog(Shell shell, Date currentlySelectedDate)
+   {
+      super(shell);
+      rerunDate = currentlySelectedDate;
+   }
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   protected Control createDialogArea(Composite parent)
+   {
+      final Composite dialogArea = (Composite)super.createDialogArea(parent);
+      
+      GridLayout layout = new GridLayout();
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
+      layout.numColumns = 2;
+      dialogArea.setLayout(layout);  
+
+      final WidgetFactory factory = new WidgetFactory() {
+         @Override
+         public Control createControl(Composite parent, int style)
+         {
+            return new DateTimeSelector(parent, style);
+         }
+      };
+      
+      dateSelector = (DateTimeSelector)WidgetHelper.createLabeledControl(dialogArea, SWT.NONE, factory, "", WidgetHelper.DEFAULT_LAYOUT_DATA);
+      dateSelector.setValue(new Date());
+
+      return dialogArea;
+   }
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+    */
+   @Override
+   protected void configureShell(Shell newShell)
+   {
+      super.configureShell(newShell);
+      newShell.setText("Execution date");
+   }
+
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+    */
+   @Override
+   protected void okPressed()
+   {
+      rerunDate = dateSelector.getValue();
+      super.okPressed();
+   }
+
+   /**
+    * Date selected by user
+    * @return rerun date
+    */
+   public Date getRerunDate()
+   {
+      return rerunDate;      
+   }
+}
index a4134d9..01d0446 100644 (file)
@@ -28,6 +28,7 @@ import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.serverconfig.Activator;
 import org.netxms.ui.eclipse.serverconfig.Messages;
+import org.netxms.ui.eclipse.serverconfig.dialogs.RerunTimeDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.ScheduledTaskEditor;
 import org.netxms.ui.eclipse.serverconfig.views.helpers.ScheduleTableEntryComparator;
 import org.netxms.ui.eclipse.serverconfig.views.helpers.ScheduleTableEntryLabelProvider;
@@ -57,6 +58,7 @@ public class ScheduledTaskView extends ViewPart
    private Action actionDeleteScheduledTask;
    private Action actionDisbaleScheduledTask;
    private Action actionEnableScheduledTask;
+   private Action actionReRun;
    
    
    
@@ -154,8 +156,48 @@ public class ScheduledTaskView extends ViewPart
             setScheduledTaskEnabled(true);
          }
       };
+      
+      actionReRun = new Action("Rerun", SharedIcons.EXECUTE) 
+      {
+         @Override
+         public void run()
+         {
+            rerun();
+         }
+      };
    }
 
+   protected void rerun()
+   {
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();      
+      if (selection.size() != 1)
+         return;
+      
+      final ScheduledTask origin = (ScheduledTask)selection.toList().get(0);
+      
+      final RerunTimeDialog dialog = new RerunTimeDialog(getSite().getShell(), origin.getExecutionTime());
+      
+      if (dialog.open() != Window.OK)
+         return;
+      
+      new ConsoleJob("Delete scheduled task", null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            origin.setExecutionTime(dialog.getRerunDate());
+            origin.setFlags(origin.getFlags() & ~ScheduledTask.EXECUTED);
+            session.updateSchedule(origin);            
+         }
+
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot update scheduled tasks";
+         }
+      }.start();
+      
+}
+
    protected void deleteScheduledTask()
    {
       final IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
@@ -341,8 +383,11 @@ public class ScheduledTaskView extends ViewPart
       IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
       mgr.add(actionNewScheduledTask);
       
-      if (selection.size() == 1)
+      if (selection.size() == 1) 
+      {         
          mgr.add(actionEditScheduledTask);
+         mgr.add(actionReRun);
+      }
 
       if (selection.size() > 0)
          mgr.add(actionDeleteScheduledTask);
index fe7abac..044eedf 100644 (file)
@@ -70,9 +70,19 @@ public class ScheduleTableEntryComparator extends ViewerComparator
             result = task1.getStatus().compareToIgnoreCase(task2.getStatus());
             break;
          case ScheduledTaskView.OWNER:
-            AbstractUserObject user1 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner());
-            AbstractUserObject user2 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner());
-            result = user1.getName().compareTo(user2.getName());
+            String user1 = "";
+            String user2 = "";
+            if((task1.getFlags() & ScheduledTask.INTERNAL)>0)
+               user1= "Internal";
+            else
+               user1 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner()).getName();
+            
+            if((task2.getFlags() & ScheduledTask.INTERNAL)>0)
+               user2= "Internal";
+            else
+               user2 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner()).getName();
+            
+            result = user1.compareTo(user2);
             break;
          default:
             result = 0;
index eb1e20b..dd3aa80 100644 (file)
@@ -64,6 +64,8 @@ public class ScheduleTableEntryLabelProvider extends LabelProvider implements IT
          case ScheduledTaskView.STATUS:
             return task.getStatus();
          case ScheduledTaskView.OWNER:
+            if((task.getFlags() & ScheduledTask.INTERNAL)>0)
+               return "Internal";
             AbstractUserObject user = session.findUserDBObjectById(task.getOwner());
             return (user != null) ? user.getName() : ("[" + Long.toString(task.getOwner()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
       }
diff --git a/webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/RerunTimeDialog.java b/webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/RerunTimeDialog.java
new file mode 100644 (file)
index 0000000..2a99394
--- /dev/null
@@ -0,0 +1,82 @@
+package org.netxms.ui.eclipse.serverconfig.dialogs;
+
+import java.util.Date;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.netxms.ui.eclipse.tools.WidgetFactory;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.DateTimeSelector;
+
+public class RerunTimeDialog extends Dialog
+{
+   private Date rerunDate;
+   private DateTimeSelector dateSelector;
+
+   public RerunTimeDialog(Shell shell, Date currentlySelectedDate)
+   {
+      super(shell);
+      rerunDate = currentlySelectedDate;
+   }
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+    */
+   @Override
+   protected Control createDialogArea(Composite parent)
+   {
+      final Composite dialogArea = (Composite)super.createDialogArea(parent);
+      
+      GridLayout layout = new GridLayout();
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
+      layout.numColumns = 2;
+      dialogArea.setLayout(layout);  
+
+      final WidgetFactory factory = new WidgetFactory() {
+         @Override
+         public Control createControl(Composite parent, int style)
+         {
+            return new DateTimeSelector(parent, style);
+         }
+      };
+      
+      dateSelector = (DateTimeSelector)WidgetHelper.createLabeledControl(dialogArea, SWT.NONE, factory, "", WidgetHelper.DEFAULT_LAYOUT_DATA);
+      dateSelector.setValue(new Date());
+
+      return dialogArea;
+   }
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+    */
+   @Override
+   protected void configureShell(Shell newShell)
+   {
+      super.configureShell(newShell);
+      newShell.setText("Execution date");
+   }
+
+   
+   /* (non-Javadoc)
+    * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+    */
+   @Override
+   protected void okPressed()
+   {
+      rerunDate = dateSelector.getValue();
+      super.okPressed();
+   }
+
+   /**
+    * Date selected by user
+    * @return rerun date
+    */
+   public Date getRerunDate()
+   {
+      return rerunDate;      
+   }
+}
index a4134d9..01d0446 100644 (file)
@@ -28,6 +28,7 @@ import org.netxms.ui.eclipse.console.resources.SharedIcons;
 import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.serverconfig.Activator;
 import org.netxms.ui.eclipse.serverconfig.Messages;
+import org.netxms.ui.eclipse.serverconfig.dialogs.RerunTimeDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.ScheduledTaskEditor;
 import org.netxms.ui.eclipse.serverconfig.views.helpers.ScheduleTableEntryComparator;
 import org.netxms.ui.eclipse.serverconfig.views.helpers.ScheduleTableEntryLabelProvider;
@@ -57,6 +58,7 @@ public class ScheduledTaskView extends ViewPart
    private Action actionDeleteScheduledTask;
    private Action actionDisbaleScheduledTask;
    private Action actionEnableScheduledTask;
+   private Action actionReRun;
    
    
    
@@ -154,8 +156,48 @@ public class ScheduledTaskView extends ViewPart
             setScheduledTaskEnabled(true);
          }
       };
+      
+      actionReRun = new Action("Rerun", SharedIcons.EXECUTE) 
+      {
+         @Override
+         public void run()
+         {
+            rerun();
+         }
+      };
    }
 
+   protected void rerun()
+   {
+      IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();      
+      if (selection.size() != 1)
+         return;
+      
+      final ScheduledTask origin = (ScheduledTask)selection.toList().get(0);
+      
+      final RerunTimeDialog dialog = new RerunTimeDialog(getSite().getShell(), origin.getExecutionTime());
+      
+      if (dialog.open() != Window.OK)
+         return;
+      
+      new ConsoleJob("Delete scheduled task", null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            origin.setExecutionTime(dialog.getRerunDate());
+            origin.setFlags(origin.getFlags() & ~ScheduledTask.EXECUTED);
+            session.updateSchedule(origin);            
+         }
+
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot update scheduled tasks";
+         }
+      }.start();
+      
+}
+
    protected void deleteScheduledTask()
    {
       final IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
@@ -341,8 +383,11 @@ public class ScheduledTaskView extends ViewPart
       IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
       mgr.add(actionNewScheduledTask);
       
-      if (selection.size() == 1)
+      if (selection.size() == 1) 
+      {         
          mgr.add(actionEditScheduledTask);
+         mgr.add(actionReRun);
+      }
 
       if (selection.size() > 0)
          mgr.add(actionDeleteScheduledTask);
index fe7abac..044eedf 100644 (file)
@@ -70,9 +70,19 @@ public class ScheduleTableEntryComparator extends ViewerComparator
             result = task1.getStatus().compareToIgnoreCase(task2.getStatus());
             break;
          case ScheduledTaskView.OWNER:
-            AbstractUserObject user1 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner());
-            AbstractUserObject user2 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner());
-            result = user1.getName().compareTo(user2.getName());
+            String user1 = "";
+            String user2 = "";
+            if((task1.getFlags() & ScheduledTask.INTERNAL)>0)
+               user1= "Internal";
+            else
+               user1 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner()).getName();
+            
+            if((task2.getFlags() & ScheduledTask.INTERNAL)>0)
+               user2= "Internal";
+            else
+               user2 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner()).getName();
+            
+            result = user1.compareTo(user2);
             break;
          default:
             result = 0;
index eb1e20b..dd3aa80 100644 (file)
@@ -64,6 +64,8 @@ public class ScheduleTableEntryLabelProvider extends LabelProvider implements IT
          case ScheduledTaskView.STATUS:
             return task.getStatus();
          case ScheduledTaskView.OWNER:
+            if((task.getFlags() & ScheduledTask.INTERNAL)>0)
+               return "Internal";
             AbstractUserObject user = session.findUserDBObjectById(task.getOwner());
             return (user != null) ? user.getName() : ("[" + Long.toString(task.getOwner()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
       }