Search in sources :

Example 1 with AgentActionResults

use of org.netxms.ui.eclipse.objecttools.views.AgentActionResults in project netxms by netxms.

the class ObjectToolExecutor method executeAgentAction.

/**
 * @param node
 * @param tool
 * @param inputValues
 */
private static void executeAgentAction(final ObjectContext node, final ObjectTool tool, final Map<String, String> inputValues) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    if ((tool.getFlags() & ObjectTool.GENERATES_OUTPUT) == 0) {
        new ConsoleJob(String.format(Messages.get().ObjectToolsDynamicMenu_ExecuteOnNode, node.object.getObjectName()), null, Activator.PLUGIN_ID, null) {

            @Override
            protected String getErrorMessage() {
                return String.format(Messages.get().ObjectToolsDynamicMenu_CannotExecuteOnNode, node.object.getObjectName());
            }

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final String action = session.executeActionWithExpansion(node.object.getObjectId(), node.getAlarmId(), tool.getData(), inputValues);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_ToolExecution, String.format(Messages.get().ObjectToolsDynamicMenu_ExecSuccess, action, node.object.getObjectName()));
                    }
                });
            }
        }.start();
    } else {
        // $NON-NLS-1$
        final String secondaryId = Long.toString(node.object.getObjectId()) + "&" + Long.toString(tool.getId());
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        try {
            AgentActionResults view = (AgentActionResults) window.getActivePage().showView(AgentActionResults.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
            view.executeAction(tool.getData(), node.getAlarmId(), inputValues);
        } catch (Exception e) {
            MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AgentActionResults(org.netxms.ui.eclipse.objecttools.views.AgentActionResults) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PartInitException (org.eclipse.ui.PartInitException)1 NXCSession (org.netxms.client.NXCSession)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 AgentActionResults (org.netxms.ui.eclipse.objecttools.views.AgentActionResults)1