Search in sources :

Example 6 with ScheduledTask

use of org.netxms.client.ScheduledTask in project netxms by netxms.

the class ScheduleTableEntryComparator method compare.

/* (non-Javadoc)
    * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
    */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    int result;
    ScheduledTask task1 = (ScheduledTask) e1;
    ScheduledTask task2 = (ScheduledTask) e2;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case ScheduledTaskView.SCHEDULE_ID:
            result = (int) (task1.getId() - task2.getId());
            break;
        case ScheduledTaskView.CALLBACK_ID:
            result = task1.getScheduledTaskId().compareToIgnoreCase(task2.getScheduledTaskId());
            break;
        case ScheduledTaskView.OBJECT:
            AbstractObject obj1 = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(task1.getObjectId());
            AbstractObject obj2 = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(task2.getObjectId());
            String name1 = (obj1 != null) ? obj1.getObjectName() : "Unknown";
            String name2 = (obj2 != null) ? obj2.getObjectName() : "Unknown";
            result = name1.compareToIgnoreCase(name2);
            break;
        case ScheduledTaskView.PARAMETERS:
            result = task1.getParameters().compareToIgnoreCase(task2.getParameters());
            break;
        case ScheduledTaskView.EXECUTION_TIME:
            if (task1.getSchedule().isEmpty()) {
                if (task2.getSchedule().isEmpty()) {
                    result = task1.getExecutionTime().compareTo(task2.getExecutionTime());
                    break;
                } else {
                    result = 1;
                    break;
                }
            }
            if (task2.getSchedule().isEmpty()) {
                result = -1;
            }
            result = task1.getSchedule().compareToIgnoreCase(task2.getSchedule());
            break;
        case ScheduledTaskView.LAST_EXECUTION_TIME:
            result = task1.getLastExecutionTime().compareTo(task2.getLastExecutionTime());
            break;
        case ScheduledTaskView.STATUS:
            result = task1.getStatus().compareToIgnoreCase(task2.getStatus());
            break;
        case ScheduledTaskView.OWNER:
            String user1 = "";
            String user2 = "";
            if ((task1.getFlags() & ScheduledTask.SYSTEM) > 0)
                user1 = "Internal";
            else
                user1 = ((NXCSession) ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner()).getName();
            if ((task2.getFlags() & ScheduledTask.SYSTEM) > 0)
                user2 = "Internal";
            else
                user2 = ((NXCSession) ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner()).getName();
            result = user1.compareTo(user2);
            break;
        case ScheduledTaskView.COMMENTS:
            result = task1.getComments().compareToIgnoreCase(task2.getComments());
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) ScheduledTask(org.netxms.client.ScheduledTask)

Example 7 with ScheduledTask

use of org.netxms.client.ScheduledTask in project netxms by netxms.

the class ScheduledTaskView method editTask.

/**
 * Edit selected task
 */
protected void editTask() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final ScheduledTask origin = (ScheduledTask) selection.toList().get(0);
    new ConsoleJob("Update scheduled task", null, Activator.PLUGIN_ID, null) {

        private ScheduledTask task = null;

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<String> taskList = session.listScheduleCallbacks();
            getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {
                    ScheduledTaskEditor dialog = new ScheduledTaskEditor(getSite().getShell(), origin, taskList);
                    if (dialog.open() == Window.OK) {
                        task = dialog.getScheduledTask();
                    }
                }
            });
            if (task != null)
                session.updateSchedule(task);
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot update scheduled tasks";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ScheduledTaskEditor(org.netxms.ui.eclipse.serverconfig.dialogs.ScheduledTaskEditor) ScheduledTask(org.netxms.client.ScheduledTask) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 8 with ScheduledTask

use of org.netxms.client.ScheduledTask in project netxms by netxms.

the class ScheduledTaskView method rescheduleTask.

/**
 * Reschedule task
 */
protected void rescheduleTask() {
    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("Reschedule 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 reschedule tasks";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RerunTimeDialog(org.netxms.ui.eclipse.serverconfig.dialogs.RerunTimeDialog) ScheduledTask(org.netxms.client.ScheduledTask) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 9 with ScheduledTask

use of org.netxms.client.ScheduledTask in project netxms by netxms.

the class ScheduledTaskView method refresh.

/**
 * Refresh list
 */
private void refresh() {
    new ConsoleJob("Reloading scheduled task list", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<ScheduledTask> schedules = session.listScheduleTasks();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                    viewer.setInput(schedules.toArray());
                    if (!selection.isEmpty()) {
                        List<ScheduledTask> newSelection = new ArrayList<ScheduledTask>();
                        for (Object o : selection.toList()) {
                            long id = ((ScheduledTask) o).getId();
                            for (ScheduledTask s : schedules) {
                                if (s.getId() == id) {
                                    newSelection.add(s);
                                    break;
                                }
                            }
                        }
                        if (!newSelection.isEmpty())
                            viewer.setSelection(new StructuredSelection(newSelection));
                    }
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot get list of scheduled tasks";
        }
    }.start();
}
Also used : ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ScheduledTask(org.netxms.client.ScheduledTask) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 10 with ScheduledTask

use of org.netxms.client.ScheduledTask in project netxms by netxms.

the class ScheduledTaskEditor method okPressed.

/* (non-Javadoc)
    * @see org.eclipse.jface.dialogs.Dialog#okPressed()
    */
@Override
protected void okPressed() {
    ScheduledTask task = scheduleSelector.getSchedule();
    scheduledTask.setSchedule(task.getSchedule());
    scheduledTask.setExecutionTime(task.getExecutionTime());
    scheduledTask.setComments(textComments.getText());
    if ((scheduledTask.getFlags() & ScheduledTask.SYSTEM) == 0) {
        scheduledTask.setScheduledTaskId(scheduleTypeList.get(scheduleType.getSelectionIndex()));
        scheduledTask.setParameters(textParameters.getText());
        scheduledTask.setObjectId(selector.getObjectId());
    }
    super.okPressed();
}
Also used : ScheduledTask(org.netxms.client.ScheduledTask)

Aggregations

ScheduledTask (org.netxms.client.ScheduledTask)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)7 PartInitException (org.eclipse.ui.PartInitException)5 NXCSession (org.netxms.client.NXCSession)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 Separator (org.eclipse.jface.action.Separator)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 ServerFile (org.netxms.client.server.ServerFile)1 StartServerToAgentFileUploadDialog (org.netxms.ui.eclipse.filemanager.dialogs.StartServerToAgentFileUploadDialog)1 MaintanenceScheduleDialog (org.netxms.ui.eclipse.objectmanager.dialogs.MaintanenceScheduleDialog)1 RerunTimeDialog (org.netxms.ui.eclipse.serverconfig.dialogs.RerunTimeDialog)1 ScheduledTaskEditor (org.netxms.ui.eclipse.serverconfig.dialogs.ScheduledTaskEditor)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1