Search in sources :

Example 31 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class RulesJythonScriptTest method testJythonScript.

@Test
public void testJythonScript() throws Exception {
    final DisplayModel display = ModelLoader.resolveAndLoadModel("../org.csstudio.display.builder.runtime.test/examples/dummy.opi", "rules_test.opi");
    final Widget widget = display.getChildren().parallelStream().filter(w -> w.getName().equals("Rectangle")).findFirst().get();
    System.out.println(widget);
    String pv_name = "loc://test2";
    PVPool.addPVFactory(new LocalPVFactory());
    final PV pv = PVPool.getPV(pv_name);
    pv.write(1);
// Set widget variable in script
// final ScriptSupport scripting = new ScriptSupport();
// final Script script = scripting.compile("../org.csstudio.display.builder.runtime.test/examples/updateText.py");
/*
        for (int run=0; run<10; ++run)
        {
            widget.setPropertyValue("text", "Initial");
            String text = widget.getPropertyValue("text");
            assertThat(text, equalTo("Initial"));
            script.submit(widget).get();
            assertThat(widget.getPropertyValue("text"), equalTo("Hello"));

            widget.setPropertyValue("text", "Initial");
            assertThat(widget.getPropertyValue("text"), equalTo("Initial"));
            script.submit(widget).get();
            assertThat(widget.getPropertyValue("text"), equalTo("Hello"));
        }

        scripting.close();
        */
}
Also used : LocalPVFactory(org.csstudio.vtype.pv.local.LocalPVFactory) DisplayModel(org.csstudio.display.builder.model.DisplayModel) PV(org.csstudio.vtype.pv.PV) Widget(org.csstudio.display.builder.model.Widget) Test(org.junit.Test)

Example 32 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class RuntimeDemoSWT method loadModel.

private void loadModel(final Display display) {
    try {
        final DisplayModel model = ModelLoader.resolveAndLoadModel("examples/dummy.opi", Settings.display_path);
        // Representation needs to be created in UI thread
        toolkit.execute(() -> representModel(display, model));
    } catch (final Exception ex) {
        logger.log(Level.SEVERE, "Cannot start", ex);
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel)

Example 33 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class RuntimeDemoJavaFX method loadModel.

private void loadModel() {
    try {
        final DisplayModel model = ModelLoader.resolveAndLoadModel("examples/dummy.opi", Settings.display_path);
        // Representation needs to be created in UI thread
        toolkit.execute(() -> representModel(model));
    } catch (final Exception ex) {
        logger.log(Level.SEVERE, "Cannot start", ex);
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel)

Example 34 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class ActionUtil method openWebpage.

/**
 * Open a web page
 *  @param source_widget Widget from which the action is invoked.
 *                       Used to resolve the potentially relative path of the
 *                       file specified in the action
 *  @param action        Information on which URL to open
 */
private static void openWebpage(final Widget source_widget, final OpenWebpageActionInfo action) {
    if (action.getURL().isEmpty()) {
        logger.log(Level.WARNING, "Action without URL: {0}", action);
        return;
    }
    try {
        final String resolved_name = resolve(source_widget, action.getURL());
        final DisplayModel top_model = source_widget.getTopDisplayModel();
        final ToolkitRepresentation<Object, Object> toolkit = ToolkitRepresentation.getToolkit(top_model);
        toolkit.execute(() -> {
            try {
                toolkit.openWebBrowser(resolved_name);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Cannot open " + action, ex);
                toolkit.showErrorDialog(source_widget, "Cannot open " + resolved_name);
            }
        });
    } catch (final Exception ex) {
        logger.log(Level.WARNING, "Error handling " + action, ex);
        ScriptUtil.showErrorDialog(source_widget, "Cannot open " + action.getURL() + ".\n\nSee log for details.");
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel)

Example 35 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class ActionUtil method executeCommand.

/**
 * Execute external command
 *  @param source_widget Widget from which the action is invoked
 *  @param action        Command action to execute
 */
private static void executeCommand(final Widget source_widget, final ExecuteCommandActionInfo action) {
    try {
        // Path to resolve, after expanding macros
        final Macros macros = source_widget.getEffectiveMacros();
        final String command = MacroHandler.replace(macros, action.getCommand());
        logger.log(Level.FINER, "{0}, effective macros {1} ({2})", new Object[] { action, macros, command });
        // Resolve command relative to the source widget model (not 'top'!)
        final DisplayModel widget_model = source_widget.getDisplayModel();
        final String parent_file = widget_model.getUserData(DisplayModel.USER_DATA_INPUT_FILE);
        final String parent_dir = ModelResourceUtil.getDirectory(ModelResourceUtil.getLocalPath(parent_file));
        // Execute (this is already running on background thread)
        logger.log(Level.FINE, "Executing command {0} in {1}", new Object[] { command, parent_dir });
        final CommandExecutor executor = new CommandExecutor(command, new File(parent_dir));
        executor.call();
    } catch (final Throwable ex) {
        logger.log(Level.WARNING, action + " failed", ex);
        ScriptUtil.showErrorDialog(source_widget, "Cannot execute " + action + ".\n\nSee log for details.");
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) Macros(org.csstudio.display.builder.model.macros.Macros) File(java.io.File)

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