Search in sources :

Example 1 with ScriptCompilationResult

use of org.netxms.client.ScriptCompilationResult 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 2 with ScriptCompilationResult

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

the class ScriptEditorView method compileScript.

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

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

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

                @Override
                public void run() {
                    if (result.success) {
                        editorMessageBar.showMessage(CompositeWithMessageBar.INFORMATION, Messages.get().ScriptEditorView_ScriptCompiledSuccessfully);
                    } else {
                        editorMessageBar.showMessage(CompositeWithMessageBar.WARNING, result.errorMessage);
                    }
                    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)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 PartInitException (org.eclipse.ui.PartInitException)2 ScriptCompilationResult (org.netxms.client.ScriptCompilationResult)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2