Search in sources :

Example 81 with ConsoleJob

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

the class ScriptExecutor method getScriptContent.

/**
 * Updates content of script editor to selected by user script
 */
protected void getScriptContent() {
    final int index = scriptCombo.getSelectionIndex();
    if (index == -1)
        return;
    new ConsoleJob(Messages.get().ScriptExecutor_JobName_Update, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Script script = session.getScript(library.get(index).getId());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    scriptEditor.setText(script.getSource());
                    clearDirtyFlags();
                    form.setText(script.getName());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ScriptExecutor_JobError_Update;
        }
    }.start();
}
Also used : Script(org.netxms.client.Script) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException)

Example 82 with ConsoleJob

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

the class ScriptEditorView method saveScript.

/**
 * Save script
 */
private void saveScript() {
    final String source = editor.getText();
    editor.getTextWidget().setEditable(false);
    new ConsoleJob(Messages.get().ScriptEditorView_SaveJobTitle, this, Activator.PLUGIN_ID, null) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final ScriptCompilationResult result = session.compileScript(source, false);
            if (result.success) {
                getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        editorMessageBar.hideMessage();
                    }
                });
            } else {
                getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (MessageDialogHelper.openQuestion(getSite().getShell(), Messages.get().ScriptEditorView_CompilationErrors, String.format(Messages.get().ScriptEditorView_ScriptCompilationFailed, result.errorMessage)))
                            result.success = true;
                        editorMessageBar.showMessage(CompositeWithMessageBar.WARNING, result.errorMessage);
                    }
                });
            }
            if (result.success) {
                doScriptSave(source, monitor);
            } else {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        editor.getTextWidget().setEditable(true);
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) ScriptCompilationResult(org.netxms.client.ScriptCompilationResult)

Example 83 with ConsoleJob

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

the class ScriptLibrary method renameScript.

/**
 * Edit script
 */
private void renameScript() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    final Script script = (Script) selection.getFirstElement();
    final CreateScriptDialog dlg = new CreateScriptDialog(getSite().getShell(), script.getName());
    if (dlg.open() == Window.OK) {
        new ConsoleJob(Messages.get().ScriptLibrary_RenameJobTitle, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.renameScript(script.getId(), dlg.getName());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        Object[] input = (Object[]) viewer.getInput();
                        List<Script> list = new ArrayList<Script>(input.length);
                        for (Object o : input) {
                            if (((Script) o).getId() != script.getId())
                                list.add((Script) o);
                        }
                        final Script newScript = new Script(script.getId(), dlg.getName(), script.getSource());
                        list.add(newScript);
                        viewer.setInput(list.toArray());
                        viewer.setSelection(new StructuredSelection(newScript));
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().ScriptLibrary_RenameJobError;
            }
        }.start();
    }
}
Also used : Script(org.netxms.client.Script) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateScriptDialog(org.netxms.ui.eclipse.nxsl.dialogs.CreateScriptDialog) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 84 with ConsoleJob

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

the class PredefinedMap method saveMap.

/**
 * Save map on server
 */
private void saveMap() {
    updateObjectPositions();
    final NXCObjectModificationData md = new NXCObjectModificationData(rootObject.getObjectId());
    md.setMapContent(mapPage.getElements(), mapPage.getLinks());
    md.setMapLayout(automaticLayoutEnabled ? layoutAlgorithm : MapLayoutAlgorithm.MANUAL);
    md.setConnectionRouting(routingAlgorithm);
    md.setMapObjectDisplayMode(labelProvider.getObjectFigureType());
    int flags = mapObject.getFlags();
    if (labelProvider.isShowStatusIcons())
        flags |= NetworkMap.MF_SHOW_STATUS_ICON;
    else
        flags &= ~NetworkMap.MF_SHOW_STATUS_ICON;
    if (labelProvider.isShowStatusFrame())
        flags |= NetworkMap.MF_SHOW_STATUS_FRAME;
    else
        flags &= ~NetworkMap.MF_SHOW_STATUS_FRAME;
    if (labelProvider.isShowStatusBackground())
        flags |= NetworkMap.MF_SHOW_STATUS_BKGND;
    else
        flags &= ~NetworkMap.MF_SHOW_STATUS_BKGND;
    if (labelProvider.isShowLinkDirection())
        flags |= NetworkMap.MF_SHOW_LINK_DIRECTION;
    else
        flags &= ~NetworkMap.MF_SHOW_LINK_DIRECTION;
    md.setObjectFlags(flags);
    new ConsoleJob(String.format(Messages.get().PredefinedMap_SaveJobTitle, rootObject.getObjectName()), this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
            runInUIThread(new Runnable() {

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().PredefinedMap_SaveJobError;
        }
    }.start();
    addDciToRequestList();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException)

Example 85 with ConsoleJob

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

the class MapOptions method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    int flags = 0;
    if ((checkIncludeEndNodes != null) && checkIncludeEndNodes.getSelection())
        flags |= NetworkMap.MF_SHOW_END_NODES;
    if (checkShowStatusIcon.getSelection())
        flags |= NetworkMap.MF_SHOW_STATUS_ICON;
    if (checkShowStatusFrame.getSelection())
        flags |= NetworkMap.MF_SHOW_STATUS_FRAME;
    if (checkShowStatusBkgnd.getSelection())
        flags |= NetworkMap.MF_SHOW_STATUS_BKGND;
    if (checkCalculateStatus.getSelection())
        flags |= NetworkMap.MF_CALCULATE_STATUS;
    if (checkShowLinkDirection.getSelection())
        flags |= NetworkMap.MF_SHOW_LINK_DIRECTION;
    md.setObjectFlags(flags, 0x5F);
    md.setMapObjectDisplayMode(MapObjectDisplayMode.getByValue(objectDisplayMode.getSelectionIndex()));
    md.setConnectionRouting(routingAlgorithm.getSelectionIndex() + 1);
    if (radioColorCustom.getSelection()) {
        md.setLinkColor(ColorConverter.rgbToInt(linkColor.getColorValue()));
    } else {
        md.setLinkColor(-1);
    }
    if (checkCustomRadius != null) {
        if (checkCustomRadius.getSelection())
            md.setDiscoveryRadius(topologyRadius.getSelection());
        else
            md.setDiscoveryRadius(-1);
    }
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().MapOptions_JobTitle + object.getObjectName(), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().MapOptions_JobError + object.getObjectName();
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        MapOptions.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

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