Search in sources :

Example 1 with MaintanenceScheduleDialog

use of org.netxms.ui.eclipse.objectmanager.dialogs.MaintanenceScheduleDialog in project netxms by netxms.

the class ScheduleMaintenance method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    ISelection selection = window.getActivePage().getSelection();
    if ((selection == null) || !(selection instanceof IStructuredSelection) || selection.isEmpty())
        return null;
    final MaintanenceScheduleDialog dialog = new MaintanenceScheduleDialog(window.getShell());
    if (dialog.open() != Window.OK)
        return null;
    final Object[] objects = ((IStructuredSelection) selection).toArray();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SetObjectManagementState_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Object o : objects) {
                if (o instanceof AbstractObject) {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", "", dialog.getStartDate(), ScheduledTask.SYSTEM, ((AbstractObject) o).getObjectId());
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", "", dialog.getEndDate(), ScheduledTask.SYSTEM, ((AbstractObject) o).getObjectId());
                    session.addSchedule(taskStart);
                    session.addSchedule(taskEnd);
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SetObjectManagementState_JobError;
        }
    }.start();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NXCSession(org.netxms.client.NXCSession) ScheduledTask(org.netxms.client.ScheduledTask) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) ISelection(org.eclipse.jface.viewers.ISelection) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) MaintanenceScheduleDialog(org.netxms.ui.eclipse.objectmanager.dialogs.MaintanenceScheduleDialog)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 NXCSession (org.netxms.client.NXCSession)1 ScheduledTask (org.netxms.client.ScheduledTask)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 MaintanenceScheduleDialog (org.netxms.ui.eclipse.objectmanager.dialogs.MaintanenceScheduleDialog)1