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