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();
}
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();
}
}
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();
}
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()));
}
}
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();
}
Aggregations