use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class WidgetTransfer method installEmbeddedDisplayWidgetFromFile.
/**
* @param display_file Display file for which to create an
* {@link EmbeddedDisplayWidget}.
* @param selection_tracker Used to get the grid steps from its model to be
* used
* in offsetting multiple widgets.
* @param widgets The container of the created widgets.
* @param updates Updates to perform on widgets
*/
private static void installEmbeddedDisplayWidgetFromFile(final String display_file, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets, final List<Runnable> updates) {
logger.log(Level.FINE, "Creating EmbeddedDisplayWidget for {0}", display_file);
final DisplayModel model = selection_tracker.getModel();
final EmbeddedDisplayWidget widget = (EmbeddedDisplayWidget) EmbeddedDisplayWidget.WIDGET_DESCRIPTOR.createWidget();
widget.propFile().setValue(display_file);
// Offset multiple widgets by grid size
final int index = widgets.size();
widget.propX().setValue(model.propGridStepX().getValue() * index);
widget.propY().setValue(model.propGridStepY().getValue() * index);
widgets.add(widget);
updates.add(() -> updateEmbeddedDisplayWidget(widget));
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class WidgetTransfer method updateEmbeddedDisplayWidget.
/**
* Update an embedded widget's name and size from its input
*
* @param widget {@link EmbeddedDisplayWidget}
*/
private static void updateEmbeddedDisplayWidget(final EmbeddedDisplayWidget widget) {
final String display_file = widget.propFile().getValue();
final String resolved;
try {
resolved = ModelResourceUtil.resolveResource(widget.getTopDisplayModel(), display_file);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot resolve resource " + display_file, ex);
return;
}
try (final InputStream bis = ModelResourceUtil.openResourceStream(resolved)) {
final ModelReader reader = new ModelReader(bis);
final DisplayModel embedded_model = reader.readModel();
final String name = embedded_model.getName();
if (!name.isEmpty()) {
widget.propName().setValue(name);
}
widget.propWidth().setValue(embedded_model.propWidth().getValue());
widget.propHeight().setValue(embedded_model.propHeight().getValue());
} catch (Exception ex) {
logger.log(Level.WARNING, "Error updating embedded widget", ex);
}
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class WidgetTransfer method installPictureWidgetFromFile.
/**
* @param image_file The image file used to create and preset a {@link PictureWidget}.
* @param selection_tracker Used to get the grid steps from its model to be
* used in offsetting multiple widgets.
* @param widgets The container of the created widgets.
* @param updates Updates to perform on widgets
*/
private static void installPictureWidgetFromFile(final String image_file, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets, final List<Runnable> updates) {
logger.log(Level.FINE, "Creating PictureWidget for dropped image {0}", image_file);
final DisplayModel model = selection_tracker.getModel();
final PictureWidget widget = (PictureWidget) PictureWidget.WIDGET_DESCRIPTOR.createWidget();
widget.propFile().setValue(image_file);
final int index = widgets.size();
widget.propX().setValue(model.propGridStepX().getValue() * index);
widget.propY().setValue(model.propGridStepY().getValue() * index);
widgets.add(widget);
updates.add(() -> updatePictureWidgetSize(widget));
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class MacroHierarchyUnitTest method testMacroHierarchy.
/**
* Test Macro Hierarchy
* @throws Exception on error
*/
@Test
public void testMacroHierarchy() throws Exception {
// Macros start out empty
MacroValueProvider macros = new Macros();
System.out.println(macros);
assertThat(macros.toString(), equalTo("[]"));
// Preferences (at least in test setup where there is no preferences service)
macros = Preferences.getMacros();
System.out.println(macros);
assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Preferences"));
// Display model uses preferences
final DisplayModel model = new DisplayModel();
macros = model.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Preferences"));
// .. but display can replace this value
model.propMacros().getValue().add("EXAMPLE_MACRO", "Value from Display");
macros = model.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Display"));
// Similar, groups can replace macros
final LabelWidget child = new LabelWidget();
final GroupWidget group2 = new GroupWidget();
group2.propMacros().getValue().add("EXAMPLE_MACRO", "In Group 2");
group2.runtimeChildren().addChild(child);
final GroupWidget group1 = new GroupWidget();
group1.propMacros().getValue().add("EXAMPLE_MACRO", "In Group 1");
group1.runtimeChildren().addChild(group2);
model.runtimeChildren().addChild(group1);
macros = group1.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("In Group 1"));
macros = group2.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("In Group 2"));
macros = child.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("In Group 2"));
// Finally, the EmbeddedDisplayWidget can replace macros,
// but testing that requires the runtime to load the embedded content
// --> Leaving that to examples/macros
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class MacroHierarchyUnitTest method testPropertiesAndEnvironment.
/**
* Test access to widget properties, Java properties and environment
* @throws Exception on error
*/
@Test
public void testPropertiesAndEnvironment() throws Exception {
// Display model uses preferences
final DisplayModel model = new DisplayModel();
MacroValueProvider macros = model.getEffectiveMacros();
assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Preferences"));
// Can also fall back to widget properties
assertThat(macros.getValue("type"), nullValue());
macros = model.getMacrosOrProperties();
String value = macros.getValue("type");
assertThat(value, equalTo("display"));
// Check fall back to Java properties
value = macros.getValue("os.name");
System.out.println("Java property os.name: " + value);
assertThat(value, not(nullValue()));
// Check fall back to environment variables
value = macros.getValue("HOME");
System.out.println("Environment variable $HOME: " + value);
assertThat(value, not(nullValue()));
}
Aggregations