Search in sources :

Example 11 with Script

use of org.netxms.client.Script in project netxms by netxms.

the class ScriptEditorView method reloadScript.

/**
 * Reload script from server
 */
private void reloadScript() {
    new ConsoleJob(String.format(Messages.get().ScriptEditorView_LoadJobTitle, scriptId), this, Activator.PLUGIN_ID, null) {

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().ScriptEditorView_LoadJobError, scriptId);
        }

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

                @Override
                public void run() {
                    scriptName = script.getName();
                    setPartName(String.format(Messages.get().ScriptEditorView_PartName, scriptName));
                    editor.setText(script.getSource());
                    actionSave.setEnabled(false);
                    modified = false;
                    firePropertyChange(PROP_DIRTY);
                }
            });
        }
    }.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)

Example 12 with Script

use of org.netxms.client.Script 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 13 with Script

use of org.netxms.client.Script in project netxms by netxms.

the class ScriptLibrary method deleteScript.

/**
 * Delete selected script(s)
 */
@SuppressWarnings("rawtypes")
private void deleteScript() {
    if (!MessageDialogHelper.openQuestion(getSite().getShell(), Messages.get().ScriptLibrary_Confirmation, Messages.get().ScriptLibrary_ConfirmationText))
        return;
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    new ConsoleJob(Messages.get().ScriptLibrary_DeleteJobTitle, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            Iterator it = selection.iterator();
            while (it.hasNext()) {
                Script script = (Script) it.next();
                session.deleteScript(script.getId());
            }
        }

        /* (non-Javadoc)
			 * @see org.netxms.ui.eclipse.jobs.ConsoleJob#jobFinalize()
			 */
        @Override
        protected void jobFinalize() {
            refreshScriptList();
        }

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

Example 14 with Script

use of org.netxms.client.Script in project netxms by netxms.

the class ScriptLibrary method editScript.

/**
 * Edit script
 */
private void editScript() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Script script = (Script) selection.getFirstElement();
    try {
        getSite().getPage().showView(ScriptEditorView.ID, Long.toString(script.getId()), IWorkbenchPage.VIEW_ACTIVATE);
    } catch (PartInitException e) {
        MessageDialogHelper.openError(getSite().getWorkbenchWindow().getShell(), Messages.get().ScriptLibrary_Error, String.format(Messages.get().ScriptLibrary_EditScriptError, e.getMessage()));
    }
}
Also used : Script(org.netxms.client.Script) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Example 15 with Script

use of org.netxms.client.Script in project netxms by netxms.

the class ScriptExecutor method updateScriptList.

/**
 * Populates list of scripts with scripts
 */
private void updateScriptList(final Runnable postProcessor) {
    final String selection = (scriptCombo.getSelectionIndex() != -1) ? scriptCombo.getItem(scriptCombo.getSelectionIndex()) : null;
    new ConsoleJob(Messages.get().ScriptExecutor_JobName_ReadList, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            library = session.getScriptLibrary();
            Collections.sort(library, new Comparator<Script>() {

                @Override
                public int compare(Script lhs, Script rhs) {
                    return lhs.getName().compareTo(rhs.getName());
                }
            });
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    scriptCombo.removeAll();
                    for (Script s : library) {
                        scriptCombo.add(s.getName());
                    }
                    if (postProcessor != null) {
                        postProcessor.run();
                    } else {
                        if (selection != null) {
                            scriptCombo.select(scriptCombo.indexOf(selection));
                        }
                    }
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ScriptExecutor_JobError_ReadList;
        }
    }.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) Comparator(java.util.Comparator)

Aggregations

Script (org.netxms.client.Script)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)10 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)10 PartInitException (org.eclipse.ui.PartInitException)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 EventObject (org.netxms.client.events.EventObject)2 EventTemplate (org.netxms.client.events.EventTemplate)2 Template (org.netxms.client.objects.Template)2 CreateScriptDialog (org.netxms.ui.eclipse.nxsl.dialogs.CreateScriptDialog)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1