Search in sources :

Example 91 with NXCSession

use of org.netxms.client.NXCSession 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 92 with NXCSession

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

the class SetObjectManagementState method execute.

/* (non-Javadoc)
    * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
    */
@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 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)
                    session.setObjectManaged(((AbstractObject) o).getObjectId(), managed);
                else if (o instanceof ObjectWrapper)
                    session.setObjectManaged(((ObjectWrapper) o).getObjectId(), managed);
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SetObjectManagementState_JobError;
        }
    }.start();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NXCSession(org.netxms.client.NXCSession) 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) ObjectWrapper(org.netxms.ui.eclipse.objects.ObjectWrapper) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 93 with NXCSession

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

the class MultipleObjectAction method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@SuppressWarnings("unchecked")
@Override
public final void run(IAction action) {
    if (selection == null)
        return;
    if (!confirm())
        return;
    Iterator<AbstractObject> it = selection.iterator();
    while (it.hasNext()) {
        final AbstractObject object = it.next();
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(formatJobDescription(object), part, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                runObjectAction(session, object);
            }

            @Override
            protected String getErrorMessage() {
                return formatErrorMessage(object, getDisplay());
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 94 with NXCSession

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

the class SetObjectMaintenanceState method execute.

/* (non-Javadoc)
    * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
    */
@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 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)
                    session.setObjectMaintenance(((AbstractObject) o).getObjectId(), maintained);
                else if (o instanceof ObjectWrapper)
                    session.setObjectMaintenance(((ObjectWrapper) o).getObjectId(), maintained);
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SetObjectManagementState_JobError;
        }
    }.start();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NXCSession(org.netxms.client.NXCSession) 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) ObjectWrapper(org.netxms.ui.eclipse.objects.ObjectWrapper) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 95 with NXCSession

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

the class ComponentsTab method objectChanged.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab#objectChanged(org.netxms.client.objects.AbstractObject)
	 */
@Override
public void objectChanged(final AbstractObject object) {
    viewer.setInput(new Object[0]);
    if (object == null)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().ComponentsTab_JobName, getViewPart(), Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                final PhysicalComponent root = session.getNodePhysicalComponents(object.getObjectId());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        if (viewer.getTree().isDisposed())
                            return;
                        if ((ComponentsTab.this.getObject() != null) && (ComponentsTab.this.getObject().getObjectId() == object.getObjectId())) {
                            viewer.setInput(new Object[] { root });
                            viewer.expandAll();
                        }
                    }
                });
            } catch (NXCException e) {
                if (e.getErrorCode() != RCC.NO_COMPONENT_DATA)
                    throw e;
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        if (viewer.getTree().isDisposed())
                            return;
                        if ((ComponentsTab.this.getObject() != null) && (ComponentsTab.this.getObject().getObjectId() == object.getObjectId())) {
                            viewer.setInput(new Object[0]);
                        }
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().ComponentsTab_JobError, object.getObjectName());
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) PhysicalComponent(org.netxms.client.PhysicalComponent) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10