Search in sources :

Example 26 with DisplayModel

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);
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel)

Example 27 with DisplayModel

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);
}
Also used : Control(org.eclipse.swt.widgets.Control) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ContextMenuSupport(org.csstudio.display.builder.rcp.run.ContextMenuSupport) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 28 with DisplayModel

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));
}
Also used : DisplayInfo(org.csstudio.display.builder.rcp.DisplayInfo) DisplayModel(org.csstudio.display.builder.model.DisplayModel) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)

Example 29 with DisplayModel

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();
}
Also used : Script(org.csstudio.display.builder.runtime.script.internal.Script) DisplayModel(org.csstudio.display.builder.model.DisplayModel) Widget(org.csstudio.display.builder.model.Widget) ScriptSupport(org.csstudio.display.builder.runtime.script.internal.ScriptSupport) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 30 with DisplayModel

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();
}
Also used : Script(org.csstudio.display.builder.runtime.script.internal.Script) DisplayModel(org.csstudio.display.builder.model.DisplayModel) Widget(org.csstudio.display.builder.model.Widget) ScriptSupport(org.csstudio.display.builder.runtime.script.internal.ScriptSupport) Test(org.junit.Test)

Aggregations

DisplayModel (org.csstudio.display.builder.model.DisplayModel)73 Widget (org.csstudio.display.builder.model.Widget)15 Test (org.junit.Test)10 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)9 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)7 EmbeddedDisplayRepresentationUtil.loadDisplayModel (org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)5 Image (javafx.scene.image.Image)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Parent (javafx.scene.Parent)3 Macros (org.csstudio.display.builder.model.macros.Macros)3 PictureWidget (org.csstudio.display.builder.model.widgets.PictureWidget)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 Rectangle2D (javafx.geometry.Rectangle2D)2 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)2 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)2 ModelWriter (org.csstudio.display.builder.model.persist.ModelWriter)2