Search in sources :

Example 16 with ConsoleJob

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

the class OpenAgentConfig method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    IViewReference vr = window.getActivePage().findViewReference(AgentConfigEditorView.ID, Long.toString(nodeId));
    if (vr != null) {
        AgentConfigEditorView view = (AgentConfigEditorView) vr.getView(true);
        if (view != null) {
            window.getActivePage().activate(view);
        }
    } else {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().OpenAgentConfig_GetConfig, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final String config = session.getAgentConfig(nodeId);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            AgentConfigEditorView view = (AgentConfigEditorView) window.getActivePage().showView(AgentConfigEditorView.ID, Long.toString(nodeId), IWorkbenchPage.VIEW_ACTIVATE);
                            view.setConfig(config);
                        } catch (PartInitException e) {
                            MessageDialogHelper.openError(window.getShell(), Messages.get().OpenAgentConfig_Error, Messages.get().OpenAgentConfig_OpenErrorPrefix + e.getLocalizedMessage());
                        }
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().OpenAgentConfig_OpenError;
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) IViewReference(org.eclipse.ui.IViewReference) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) AgentConfigEditorView(org.netxms.ui.eclipse.agentmanager.views.AgentConfigEditorView) PartInitException(org.eclipse.ui.PartInitException)

Example 17 with ConsoleJob

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

the class ActionSelectionDialog method createDialogArea.

/* (non-Javadoc)
    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createDialogArea(Composite parent) {
    final Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    dialogArea.setLayout(layout);
    viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ActionSelectionDialogLabelProvider());
    viewer.setComparator(new ViewerComparator() {

        /* (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) {
            return ((ServerAction) e1).getName().compareToIgnoreCase(((ServerAction) e2).getName());
        }
    });
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Get server actions", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<ServerAction> list = session.getActions();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(list.toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot get server actions";
        }
    }.start();
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 400;
    viewer.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : ActionSelectionDialogLabelProvider(org.netxms.ui.eclipse.actionmanager.dialogs.helpers.ActionSelectionDialogLabelProvider) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) ServerAction(org.netxms.client.ServerAction)

Example 18 with ConsoleJob

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

the class TunnelManager method refresh.

/**
 * Refresh view
 */
private void refresh() {
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Get list of active agent tunnels", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<AgentTunnel> tunnels = session.getAgentTunnels();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(tunnels);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot get list of active agent tunnels";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 19 with ConsoleJob

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

the class LocalCommandResults method runCommand.

/**
 * Run command (called by tool execution action)
 *
 * @param command
 */
public void runCommand(final String command) {
    synchronized (mutex) {
        if (running) {
            process.destroy();
            try {
                mutex.wait();
            } catch (InterruptedException e) {
            }
        }
        running = true;
        lastCommand = command;
        actionTerminate.setEnabled(true);
        actionRestart.setEnabled(false);
    }
    final IOConsoleOutputStream out = console.newOutputStream();
    ConsoleJob job = new ConsoleJob(Messages.get().LocalCommandResults_JobTitle, this, Activator.PLUGIN_ID, null) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            process = Runtime.getRuntime().exec(command);
            InputStream in = process.getInputStream();
            try {
                byte[] data = new byte[16384];
                boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32);
                while (true) {
                    int bytes = in.read(data);
                    if (bytes == -1)
                        break;
                    String s = new String(Arrays.copyOf(data, bytes));
                    // ending in 0x0D 0x0D 0x0A
                    if (isWindows)
                        // $NON-NLS-1$ //$NON-NLS-2$
                        out.write(s.replace("\r\r\n", " \r\n"));
                    else
                        out.write(s);
                }
                out.write(Messages.get().LocalCommandResults_Terminated);
            } catch (IOException e) {
                // $NON-NLS-1$
                Activator.logError("Exception while running local command", e);
            } finally {
                in.close();
                out.close();
            }
        }

        @Override
        protected void jobFinalize() {
            synchronized (mutex) {
                running = false;
                process = null;
                mutex.notifyAll();
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    synchronized (mutex) {
                        actionTerminate.setEnabled(running);
                        actionRestart.setEnabled(!running);
                    }
                }
            });
        }
    };
    job.setUser(false);
    job.setSystem(true);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOConsoleOutputStream(org.eclipse.ui.console.IOConsoleOutputStream) InputStream(java.io.InputStream) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException)

Example 20 with ConsoleJob

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

the class SummaryTablesDynamicMenu method queryTable.

/**
 * Query table using selected base object
 *
 * @param baseObjectId
 * @param tableId
 */
private void queryTable(final long baseObjectId, final int tableId) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SummaryTablesDynamicMenu_QueryTableJob, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Table results = session.queryDciSummaryTable(tableId, baseObjectId);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    // $NON-NLS-1$
                    String secondaryId = Integer.toString(tableId) + "&" + Long.toString(baseObjectId);
                    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    try {
                        SummaryTable view = (SummaryTable) window.getActivePage().showView(SummaryTable.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
                        view.setTable(results);
                    } catch (PartInitException e) {
                        MessageDialogHelper.openError(window.getShell(), Messages.get().SummaryTablesDynamicMenu_Error, String.format(Messages.get().SummaryTablesDynamicMenu_CannotOpenView, e.getLocalizedMessage()));
                    }
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SummaryTablesDynamicMenu_CannotReadData;
        }
    }.start();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) SummaryTable(org.netxms.ui.eclipse.datacollection.views.SummaryTable) Table(org.netxms.client.Table) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) PartInitException(org.eclipse.ui.PartInitException) SummaryTable(org.netxms.ui.eclipse.datacollection.views.SummaryTable)

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