Search in sources :

Example 21 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class ExecuteJavaScriptJdkAction method run.

@Override
public void run() {
    if (scriptEngine == null) {
        try {
            scriptEngine = ScriptStoreFactory.getJavaScriptEngine();
        } catch (Exception exception) {
            ErrorHandlerUtil.handleError("Failed to get Script Context", exception);
            return;
        }
        scriptScope = scriptEngine.createBindings();
        GraphicalViewer viewer = getWidgetModel().getRootDisplayModel().getViewer();
        if (viewer != null) {
            Object obj = viewer.getEditPartRegistry().get(getWidgetModel());
            if (obj != null && obj instanceof AbstractBaseEditPart) {
                scriptScope.put(ScriptService.DISPLAY, viewer.getContents());
                scriptScope.put(ScriptService.WIDGET, obj);
            }
        }
    }
    Job job = new Job("Execute JavaScript") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String taskName = isEmbedded() ? "Execute JavaScript" : "Connecting to " + getAbsolutePath();
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            runTask();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphicalViewer(org.eclipse.gef.GraphicalViewer) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Job(org.eclipse.core.runtime.jobs.Job)

Example 22 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class ExecuteJavaScriptRhinoAction method run.

@Override
public void run() {
    if (scriptContext == null) {
        try {
            scriptContext = ScriptStoreFactory.getRhinoContext();
        } catch (Exception exception) {
            ErrorHandlerUtil.handleError("Failed to get Script Context", exception);
            return;
        }
        scriptScope = new ImporterTopLevel(scriptContext);
        GraphicalViewer viewer = getWidgetModel().getRootDisplayModel().getViewer();
        if (viewer != null) {
            Object obj = viewer.getEditPartRegistry().get(getWidgetModel());
            if (obj != null && obj instanceof AbstractBaseEditPart) {
                Object displayObject = Context.javaToJS(viewer.getContents(), scriptScope);
                Object widgetObject = Context.javaToJS(obj, scriptScope);
                ScriptableObject.putProperty(scriptScope, ScriptService.DISPLAY, displayObject);
                ScriptableObject.putProperty(scriptScope, ScriptService.WIDGET, widgetObject);
            }
        }
    }
    Job job = new Job("Execute JavaScript") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String taskName = isEmbedded() ? "Execute JavaScript" : "Connecting to " + getAbsolutePath();
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            runTask();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : ImporterTopLevel(org.mozilla.javascript.ImporterTopLevel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphicalViewer(org.eclipse.gef.GraphicalViewer) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ScriptableObject(org.mozilla.javascript.ScriptableObject) Job(org.eclipse.core.runtime.jobs.Job)

Example 23 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class ExecutePythonScriptAction method run.

@Override
public void run() {
    if (code == null) {
        try {
            ScriptStoreFactory.initPythonInterpreter();
        } catch (Exception e) {
            final String message = "Failed to initialize PythonInterpreter";
            OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
            // $NON-NLS-1$
            ConsoleService.getInstance().writeError(message + "\n" + e);
        }
        // read file
        IPath absolutePath = getAbsolutePath();
        state = new PySystemState();
        // Add the path of script to python module search path
        if (!isEmbedded() && absolutePath != null && !absolutePath.isEmpty()) {
            // If it is a workspace file.
            if (ResourceUtil.isExistingWorkspaceFile(absolutePath)) {
                IPath folderPath = absolutePath.removeLastSegments(1);
                String sysLocation = ResourceUtil.workspacePathToSysPath(folderPath).toOSString();
                state.path.append(new PyString(sysLocation));
            } else if (ResourceUtil.isExistingLocalFile(absolutePath)) {
                IPath folderPath = absolutePath.removeLastSegments(1);
                state.path.append(new PyString(folderPath.toOSString()));
            }
        }
        interpreter = new PythonInterpreter(null, state);
        GraphicalViewer viewer = getWidgetModel().getRootDisplayModel().getViewer();
        if (viewer != null) {
            Object obj = viewer.getEditPartRegistry().get(getWidgetModel());
            if (obj != null && obj instanceof AbstractBaseEditPart) {
                displayEditpart = (DisplayEditpart) (viewer.getContents());
                widgetEditPart = (AbstractBaseEditPart) obj;
            }
        }
    }
    Job job = new Job("Execute Python Script") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String taskName = isEmbedded() ? "Execute Python Script" : "Connecting to " + getAbsolutePath();
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            runTask();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : PySystemState(org.python.core.PySystemState) PyString(org.python.core.PyString) PythonInterpreter(org.python.util.PythonInterpreter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IPath(org.eclipse.core.runtime.IPath) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PyObject(org.python.core.PyObject) PyString(org.python.core.PyString) Job(org.eclipse.core.runtime.jobs.Job)

Example 24 with AbstractBaseEditPart

use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.

the class PVUtil method createPV.

/**
 * Create a PV and start it. PVListener can be added to the PV to monitor its value change, but please note that the
 * listener is executed in non-UI thread. If the code need be executed in UI thread, please use
 * {@link ScriptUtil#execInUI(Runnable, AbstractBaseEditPart)}. The monitor's maximum update rate is 50hz. If the PV
 * updates faster than this rate, some updates will be discarded.
 *
 * @param name
 *            name of the PV.
 * @param widget
 *            the reference widget. The PV will stop when the widget is deactivated, so it is not needed to stop the
 *            pv in script.
 * @return the PV.
 * @throws Exception
 *             the exception that might happen while creating the pv.
 */
public static final IPV createPV(String name, AbstractBaseEditPart widget) throws Exception {
    final IPV pv = BOYPVFactory.createPV(name, false, 20);
    pv.start();
    widget.addEditPartListener(new EditPartListener.Stub() {

        @Override
        public void partDeactivated(EditPart arg0) {
            pv.stop();
        }
    });
    return pv;
}
Also used : EditPartListener(org.eclipse.gef.EditPartListener) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) EditPart(org.eclipse.gef.EditPart) IPV(org.csstudio.simplepv.IPV)

Aggregations

AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)24 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)16 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)8 ArrayList (java.util.ArrayList)6 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 GraphicalViewer (org.eclipse.gef.GraphicalViewer)4 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 PointList (org.eclipse.draw2d.geometry.PointList)3 EditPart (org.eclipse.gef.EditPart)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 EventObject (java.util.EventObject)2 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)2 SetBoundsCommand (org.csstudio.opibuilder.commands.SetBoundsCommand)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)2