use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class RuntimeApplication method loadModel.
private void loadModel(final String display_path) {
try {
final DisplayModel model = ModelLoader.loadModel(display_path);
// Representation needs to be created in UI thread
toolkit.execute(() -> representModel(model));
} catch (final Exception ex) {
logger.log(Level.SEVERE, "Cannot load " + display_path, ex);
}
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class RuntimeViewPart method createPartControl.
@Override
public void createPartControl(final Composite parent) {
RCPHacks.hideUnrelatedUI(getSite().getPage());
parent.setLayout(new FillLayout());
// This calls createFxScene()
super.createPartControl(parent);
// The child added last should be the new FXCanvas
final Control[] children = parent.getChildren();
final Control fx_canvas = children[children.length - 1];
if (!fx_canvas.getClass().getName().contains("FXCanvas"))
throw new IllegalStateException("Expected FXCanvas, got " + fx_canvas);
JFXCursorFix.apply(scene, parent.getDisplay());
createToolbarItems();
new ContextMenuSupport(this, fx_canvas, representation);
parent.addDisposeListener(e -> onDispose());
// Load persisted DisplayInfo?
if (display_info.isPresent()) {
loadDisplayFile(display_info.get());
// This view was restored by Eclipse after a restart.
// It's not opened from an action,
// so nobody else will hook the runtime listener:
RuntimeUtil.hookRepresentationListener(representation);
}
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "org.csstudio.display.builder.editor.rcp.display_builder");
// Representation for each widget adds a context menu just for the widget.
// Add context menu to scene, tied to the model.
scene.setOnContextMenuRequested(event -> {
final DisplayModel model = active_model;
if (model != null) {
event.consume();
representation.fireContextMenu(model);
}
});
// Track when view is hidden/restored
// Only add once, so remove previous one
getSite().getPage().removePartListener(show_hide_listener);
getSite().getPage().addPartListener(show_hide_listener);
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class StandaloneAction method run.
@Override
public void run() {
final DisplayModel parent_model = view.getDisplayModel();
final DisplayInfo info = view.getDisplayInfo();
ActionUtil.handleAction(parent_model, new OpenDisplayActionInfo(Messages.OpenStandalone, info.getPath(), info.getMacros(), OpenDisplayActionInfo.Target.STANDALONE));
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class JythonScriptTest method testJythonScript.
@Test
public void testJythonScript() throws Exception {
System.setProperty("python.import.site", "false");
final DisplayModel display = ModelLoader.resolveAndLoadModel("../org.csstudio.display.builder.runtime.test/examples/dummy.opi", "script_test.opi");
final Widget widget = display.getChildren().parallelStream().filter(w -> w.getName().equals("Label 100")).findFirst().get();
System.out.println(widget);
// Set widget variable in script
final ScriptSupport scripting = new ScriptSupport();
final Script script = scripting.compile(".", "updateText.py", new FileInputStream("../org.csstudio.display.builder.runtime.test/examples/updateText.py"));
for (int run = 0; run < 10; ++run) {
widget.setPropertyValue("text", "Initial");
assertThat(widget.getPropertyValue("text"), equalTo("Initial"));
script.submit(widget).get();
assertThat(widget.getPropertyValue("text"), equalTo("Hello"));
}
scripting.close();
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class PythonScriptTest method testPythonScript.
@Test
public void testPythonScript() throws Exception {
if (!PythonGatewaySupport.isConnect2jInstalled()) {
System.err.println("Skipping PythonScriptTest because there is no python with connect2j");
return;
}
final DisplayModel display = ModelLoader.resolveAndLoadModel("../org.csstudio.display.builder.runtime.test/examples/dummy.opi", "script_test.opi");
final Widget widget = display.getChildren().parallelStream().filter(w -> w.getName().equals("Label 100")).findFirst().get();
System.out.println(widget);
// Set widget variable in script
final ScriptSupport scripting = new ScriptSupport();
final Script script = scripting.compile("../org.csstudio.display.builder.runtime.test/examples", "updateText_python.py", null);
for (int run = 0; run < 10; ++run) {
widget.setPropertyValue("text", "Initial");
assertThat(widget.getPropertyValue("text"), equalTo("Initial"));
script.submit(widget).get();
assertThat(widget.getPropertyValue("text"), equalTo("Hello"));
}
scripting.close();
}
Aggregations