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