Search in sources :

Example 1 with CreateScriptDialog

use of org.netxms.ui.eclipse.nxsl.dialogs.CreateScriptDialog 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 2 with CreateScriptDialog

use of org.netxms.ui.eclipse.nxsl.dialogs.CreateScriptDialog in project netxms by netxms.

the class ScriptLibrary method createNewScript.

/**
 * Create new script
 */
private void createNewScript() {
    final CreateScriptDialog dlg = new CreateScriptDialog(getSite().getShell(), null);
    if (dlg.open() == Window.OK) {
        new ConsoleJob(Messages.get().ScriptLibrary_CreateJobTitle, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                // $NON-NLS-1$
                final long id = session.modifyScript(0, 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) list.add((Script) o);
                        // $NON-NLS-1$
                        final Script script = new Script(id, dlg.getName(), "");
                        list.add(script);
                        viewer.setInput(list.toArray());
                        viewer.setSelection(new StructuredSelection(script));
                        actionEdit.run();
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().ScriptLibrary_CreateJobError;
            }
        }.start();
    }
}
Also used : Script(org.netxms.client.Script) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) 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 3 with CreateScriptDialog

use of org.netxms.ui.eclipse.nxsl.dialogs.CreateScriptDialog in project netxms by netxms.

the class ScriptExecutor method createNewScript.

/**
 * Create new script
 */
private void createNewScript(final boolean saveOnSelectionChange) {
    final CreateScriptDialog dlg = new CreateScriptDialog(getSite().getShell(), null);
    if (dlg.open() == Window.OK) {
        final String scriptSource = scriptEditor.getText();
        new ConsoleJob(Messages.get().ScriptExecutor_JobName_Create, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.modifyScript(0, dlg.getName(), scriptSource);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        Runnable run = new Runnable() {

                            @Override
                            public void run() {
                                scriptCombo.select(scriptCombo.indexOf(dlg.getName()));
                            }
                        };
                        updateScriptList(saveOnSelectionChange ? null : run);
                        clearDirtyFlags();
                    }
                });
            }

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

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 PartInitException (org.eclipse.ui.PartInitException)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 CreateScriptDialog (org.netxms.ui.eclipse.nxsl.dialogs.CreateScriptDialog)3 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Script (org.netxms.client.Script)2 IOException (java.io.IOException)1