Search in sources :

Example 56 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class DashboardView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    selectionProvider = new IntermediateSelectionProvider();
    getSite().setSelectionProvider(selectionProvider);
    ConsoleJob job = new ConsoleJob(Messages.get().DashboardView_GetEffectiveRights, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            readOnly = ((dashboard.getEffectiveRights() & UserAccessRights.OBJECT_ACCESS_MODIFY) == 0);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().DashboardView_GetEffectiveRightsError;
        }
    };
    job.start();
    // FIXME: rewrite waiting
    try {
        job.join();
    } catch (InterruptedException e) {
    }
    parentComposite = parent;
    dbc = new DashboardControl(parent, SWT.NONE, dashboard, this, selectionProvider, false);
    if (!readOnly) {
        dbcModifyListener = new DashboardModifyListener() {

            @Override
            public void save() {
                actionSave.setEnabled(false);
                firePropertyChange(PROP_DIRTY);
            }

            @Override
            public void modify() {
                actionSave.setEnabled(true);
                firePropertyChange(PROP_DIRTY);
            }
        };
        dbc.setModifyListener(dbcModifyListener);
    }
    activateContext();
    createActions();
    contributeToActionBars();
    clientListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() == SessionNotification.OBJECT_CHANGED && dashboard.getObjectId() == n.getSubCode()) {
                parentComposite.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        rebuildDashboard(true);
                    }
                });
            }
        }
    };
    session.addListener(clientListener);
}
Also used : IntermediateSelectionProvider(org.netxms.ui.eclipse.tools.IntermediateSelectionProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DashboardControl(org.netxms.ui.eclipse.dashboard.widgets.DashboardControl) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DashboardModifyListener(org.netxms.ui.eclipse.dashboard.widgets.internal.DashboardModifyListener) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Example 57 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class EventMonitorElement method dispose.

@Override
public void dispose() {
    ConsoleJob job = new ConsoleJob(String.format("Unsuscribing from channel ", NXCSession.CHANNEL_EVENTS), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.unsubscribe(NXCSession.CHANNEL_EVENTS);
        }

        @Override
        protected String getErrorMessage() {
            return String.format("Cannot unsubscribe from channel ", NXCSession.CHANNEL_EVENTS);
        }
    };
    job.setUser(false);
    job.setSystem(true);
    job.start();
    super.dispose();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 58 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AlarmCategoryList method deleteCategory.

/**
 * Delete alarm category
 */
private void deleteCategory() {
    final IStructuredSelection selection = (IStructuredSelection) getSelection();
    if (selection.isEmpty())
        return;
    final String message = (selection.size() == 1) ? "Do you really wish to delete the selected category?" : "Do you really wish to delete the selected categories?";
    if (!MessageDialogHelper.openQuestion(getShell(), "Confirm category deletion", message))
        return;
    new ConsoleJob("Delete alarm category database entries", viewPart, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return "Cannot delete alarm category database entry";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 59 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob 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 60 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AgentFileManager method deleteFile.

/**
 * Delete selected file
 */
private void deleteFile() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ViewServerFile_DeleteConfirmation, Messages.get().ViewServerFile_DeletAck))
        return;
    final Object[] objects = selection.toArray();
    new ConsoleJob(Messages.get().ViewServerFile_DeletFileFromServerJob, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (int i = 0; i < objects.length; i++) {
                final AgentFile sf = (AgentFile) objects[i];
                session.deleteAgentFile(objectId, sf.getFullName());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        sf.getParent().removeChield(sf);
                        viewer.refresh(sf.getParent());
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Aggregations

ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)330 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)329 NXCSession (org.netxms.client.NXCSession)163 PartInitException (org.eclipse.ui.PartInitException)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)81 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 NXCException (org.netxms.client.NXCException)44 List (java.util.List)38 ArrayList (java.util.ArrayList)34 AbstractObject (org.netxms.client.objects.AbstractObject)33 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 IOException (java.io.IOException)27 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)16 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)13 File (java.io.File)12 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)10 Script (org.netxms.client.Script)10 Table (org.netxms.client.Table)10 CoreException (org.eclipse.core.runtime.CoreException)9 GridData (org.eclipse.swt.layout.GridData)9