Search in sources :

Example 1 with Macros

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

the class DataBrowserWidget method defineProperties.

@Override
protected void defineProperties(final List<WidgetProperty<?>> properties) {
    super.defineProperties(properties);
    properties.add(filename = propFile.createProperty(this, ""));
    properties.add(show_toolbar = propShowToolbar.createProperty(this, true));
    properties.add(macros = propMacros.createProperty(this, new Macros()));
    properties.add(selection_value_pv = propSelectionValuePV.createProperty(this, ""));
}
Also used : CommonWidgetProperties.propMacros(org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMacros) Macros(org.csstudio.display.builder.model.macros.Macros)

Example 2 with Macros

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

the class JFXActionsDialogDemo method start.

@Override
public void start(final Stage stage) {
    final Widget widget = new Widget("demo");
    final Macros macros = new Macros();
    macros.add("S", "Test");
    macros.add("N", "17");
    final ActionInfos actions = new ActionInfos(Arrays.asList(new OpenDisplayActionInfo("Related Display", "../opi/some_file.opi", macros, Target.TAB), new WritePVActionInfo("Reset", "Test:CS:Reset", "1"), new ExecuteScriptActionInfo("Script", new ScriptInfo(ScriptInfo.EMBEDDED_PYTHON, "print 'hi'", false, Collections.emptyList()))));
    final ActionsDialog dialog = new ActionsDialog(widget, actions);
    final Optional<ActionInfos> result = dialog.showAndWait();
    if (result.isPresent()) {
        if (result.get().isExecutedAsOne())
            System.out.println("Execute all commands as one:");
        for (ActionInfo info : result.get().getActions()) {
            if (info instanceof ExecuteScriptActionInfo) {
                final ExecuteScriptActionInfo action = (ExecuteScriptActionInfo) info;
                System.out.println("Execute " + action.getDescription() + ", " + action.getInfo() + ": " + action.getInfo().getText());
            } else
                System.out.println(info);
        }
    } else
        System.out.println("Cancelled");
}
Also used : ActionsDialog(org.csstudio.display.builder.representation.javafx.ActionsDialog) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) Widget(org.csstudio.display.builder.model.Widget) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) Macros(org.csstudio.display.builder.model.macros.Macros) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)

Example 3 with Macros

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

the class JFXMacrosDialogDemo method start.

@Override
public void start(final Stage stage) {
    final Macros macros = new Macros();
    macros.add("S", "Test");
    macros.add("N", "17");
    final MacrosDialog dialog = new MacrosDialog(macros);
    System.out.println(dialog.showAndWait());
}
Also used : MacrosDialog(org.csstudio.display.builder.representation.javafx.MacrosDialog) Macros(org.csstudio.display.builder.model.macros.Macros)

Example 4 with Macros

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

the class AllWidgetsAllProperties method main.

public static void main(String[] args) throws Exception {
    final DisplayModel model = new DisplayModel();
    for (final WidgetDescriptor widget_type : WidgetFactory.getInstance().getWidgetDescriptions()) {
        Widget widget = widget_type.createWidget();
        widget.setPropertyValue("name", widget_type.getName() + " 1");
        // For some widgets, adjust default values
        if (widget_type == ActionButtonWidget.WIDGET_DESCRIPTOR) {
            ActionButtonWidget button = (ActionButtonWidget) widget;
            final Macros macros = new Macros();
            macros.add("S", "Test");
            macros.add("N", "2");
            button.propActions().setValue(new ActionInfos(Arrays.asList(new OpenDisplayActionInfo("Display", "other.opi", macros, Target.REPLACE))));
        }
        model.runtimeChildren().addChild(widget);
    }
    ModelWriter.skip_defaults = false;
    try {
        final ModelWriter writer = new ModelWriter(new FileOutputStream(EXAMPLE_FILE));
        writer.writeModel(model);
        writer.close();
    } finally {
        ModelWriter.skip_defaults = true;
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) Macros(org.csstudio.display.builder.model.macros.Macros) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) ModelWriter(org.csstudio.display.builder.model.persist.ModelWriter)

Example 5 with Macros

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

the class WidgetPropertyUnitTest method testEnum.

/* Test enumerated property read/write API */
@Test
public void testEnum() throws Exception {
    final DisplayModel widget = new DisplayModel();
    final Macros macros = new Macros();
    macros.add("ALIGN", "1");
    widget.propMacros().setValue(macros);
    final EnumWidgetProperty<Align> prop = new EnumWidgetProperty<Align>(alignHoriz, widget, Align.LEFT);
    System.out.println(prop);
    assertThat(prop.getValue(), equalTo(Align.LEFT));
    System.out.println(Arrays.toString(prop.getLabels()));
    assertThat(prop.getLabels(), equalTo(new String[] { "Left", "Center", "Right" }));
    // Set value as enum
    prop.setValue(Align.RIGHT);
    System.out.println(prop);
    assertThat(prop.getValue(), equalTo(Align.RIGHT));
    // Set value as object, using the enum
    prop.setValueFromObject(Align.LEFT);
    System.out.println(prop);
    assertThat(prop.getValue(), equalTo(Align.LEFT));
    // Set value from ordinal
    prop.setValueFromObject(2);
    System.out.println(prop);
    assertThat(prop.getValue(), equalTo(Align.RIGHT));
    // Set value from string with ordinal
    prop.setValueFromObject("1");
    System.out.println(prop);
    assertThat(prop.getValue(), equalTo(Align.CENTER));
    assertThat(prop.getSpecification(), equalTo("1"));
    // Capture invalid ordinal
    try {
        prop.setValueFromObject(20);
        fail("Allowed invalid ordinal");
    } catch (Exception ex) {
        assertThat(ex.getMessage().toLowerCase(), containsString("invalid ordinal"));
    }
    // Capture use of label or name instead of ordinal
    try {
        prop.setValueFromObject("CENTER");
        fail("Allowed name instead of ordinal");
    } catch (Exception ex) {
        assertThat(ex.getMessage().toLowerCase(), containsString("expects ordinal"));
    }
    // Check handling of specification and macros
    prop.setSpecification("0");
    System.out.println(prop);
    assertThat(prop.getValue(), equalTo(Align.LEFT));
    prop.setSpecification("$(ALIGN)");
    System.out.println(prop);
    assertThat(prop.getValue(), equalTo(Align.CENTER));
    System.out.println(prop);
    assertThat(prop.getSpecification(), equalTo("$(ALIGN)"));
}
Also used : EnumWidgetProperty(org.csstudio.display.builder.model.properties.EnumWidgetProperty) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Macros(org.csstudio.display.builder.model.macros.Macros) Test(org.junit.Test)

Aggregations

Macros (org.csstudio.display.builder.model.macros.Macros)33 CommonWidgetProperties.propMacros (org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMacros)12 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)4 Test (org.junit.Test)4 DisplayModel (org.csstudio.display.builder.model.DisplayModel)3 ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Widget (org.csstudio.display.builder.model.Widget)2 ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)2 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)2 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)2 WritePVActionInfo (org.csstudio.display.builder.model.properties.WritePVActionInfo)2 Element (org.w3c.dom.Element)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1