Search in sources :

Example 1 with ScheduledTask

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

the class UploadFileToAgent method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    boolean canScheduleFileUpload = (session.getUserSystemRights() & UserAccessRights.SYSTEM_ACCESS_SCHEDULE_FILE_UPLOAD) > 0;
    final StartServerToAgentFileUploadDialog dlg = new StartServerToAgentFileUploadDialog(shell, canScheduleFileUpload);
    if (dlg.open() == Window.OK) {
        final Long[] nodeIdList = nodes.toArray(new Long[nodes.size()]);
        new ConsoleJob(Messages.get().UploadFileToAgent_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

            @Override
            protected String getErrorMessage() {
                return Messages.get().UploadFileToAgent_JobError;
            }

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                boolean multipleFiles = dlg.getServerFiles().size() > 1;
                for (ServerFile sf : dlg.getServerFiles()) {
                    String remoteFileName = dlg.getRemoteFileName();
                    if (!remoteFileName.isEmpty()) {
                        if (// $NON-NLS-1$ //$NON-NLS-2$
                        remoteFileName.endsWith("/") || remoteFileName.endsWith("\\")) {
                            remoteFileName += sf.getName();
                        } else if (multipleFiles) {
                            remoteFileName += "/" + sf.getName();
                        }
                    } else {
                        if (!dlg.isScheduled())
                            remoteFileName = null;
                    }
                    for (int i = 0; i < nodeIdList.length; i++) {
                        if (dlg.isScheduled()) {
                            ScheduledTask task = dlg.getScheduledTask();
                            // $NON-NLS-1$
                            String parameters = sf.getName() + "," + remoteFileName;
                            task.setParameters(parameters);
                            task.setObjectId(nodeIdList[i]);
                            session.addSchedule(task);
                        } else {
                            session.uploadFileToAgent(nodeIdList[i], sf.getName(), remoteFileName, dlg.isCreateJobOnHold());
                        }
                    }
                }
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) StartServerToAgentFileUploadDialog(org.netxms.ui.eclipse.filemanager.dialogs.StartServerToAgentFileUploadDialog) ServerFile(org.netxms.client.server.ServerFile) ScheduledTask(org.netxms.client.ScheduledTask) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 2 with ScheduledTask

use of org.netxms.client.ScheduledTask 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)

Example 3 with ScheduledTask

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

the class ScheduledTaskView method deleteTask.

/**
 * Delete task
 */
protected void deleteTask() {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() == 0)
        return;
    if (!MessageDialogHelper.openQuestion(getSite().getShell(), "Confirm Task Delete", (selection.size() == 1) ? "Selected task will be deleted. Are you sure?" : "Selected tasks will be deleted. Are you sure?"))
        return;
    new ConsoleJob("Delete scheduled task", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Object o : selection.toList()) {
                session.removeSchedule(((ScheduledTask) o).getId());
            }
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot delete scheduled tasks";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ScheduledTask(org.netxms.client.ScheduledTask) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 4 with ScheduledTask

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

the class ScheduledTaskView method setScheduledTaskEnabled.

/**
 * @param enabled
 */
protected void setScheduledTaskEnabled(final boolean enabled) {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() < 0)
        return;
    new ConsoleJob("Update scheduled task", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Object o : selection.toList()) {
                ScheduledTask task = (ScheduledTask) o;
                task.setEnabed(enabled);
                session.updateSchedule(task);
            }
        }

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

Example 5 with ScheduledTask

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

the class ScheduledTaskView method fillContextMenu.

/**
 * Fill context menu
 * @param mgr Menu manager
 */
protected void fillContextMenu(IMenuManager mgr) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() == 1) {
        mgr.add(actionEdit);
        ScheduledTask origin = (ScheduledTask) selection.toList().get(0);
        if (origin.getSchedule().isEmpty())
            mgr.add(actionReschedule);
    }
    boolean containDisabled = false;
    boolean containEnabled = false;
    for (Object o : selection.toList()) {
        if (((ScheduledTask) o).isDisbaled())
            containDisabled = true;
        else
            containEnabled = true;
        if (containDisabled && containEnabled)
            break;
    }
    if (containDisabled)
        mgr.add(actionEnable);
    if (containEnabled)
        mgr.add(actionDisable);
    if (selection.size() > 0)
        mgr.add(actionDelete);
    mgr.add(new Separator());
    mgr.add(actionCreate);
}
Also used : ScheduledTask(org.netxms.client.ScheduledTask) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Separator(org.eclipse.jface.action.Separator)

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