use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class PersistenceUnitTest method testWidgetReading.
/**
* Read widgets from XML
* @throws Exception on error
*/
@Test
public void testWidgetReading() throws Exception {
final String xml = getExampleFile();
final InputStream stream = new ByteArrayInputStream(xml.getBytes());
final ModelReader reader = new ModelReader(stream);
final DisplayModel model = reader.readModel();
final List<Widget> widgets = model.getChildren();
for (final Widget widget : widgets) {
System.out.println(widget);
System.out.println(widget.getProperties().stream().map(Object::toString).collect(Collectors.joining("\n")));
}
assertThat(widgets.size(), equalTo(2));
final List<String> names = widgets.stream().map(Widget::getName).collect(Collectors.toList());
assertThat(names, equalTo(Arrays.asList("Demo", "My Group")));
assertThat(widgets.get(1), instanceOf(GroupWidget.class));
assertThat(((GroupWidget) widgets.get(1)).runtimeChildren().getValue().get(0).getName(), equalTo("Jänner"));
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class PersistenceUnitTest method testClassSupportPersistence.
@Test
public void testClassSupportPersistence() throws Exception {
// By default, Label font does not use class
final DisplayModel model = new DisplayModel();
final LabelWidget label = new LabelWidget();
assertThat(label.propFont().isUsingWidgetClass(), equalTo(false));
label.propFont().setValue(new NamedWidgetFont("TEST", "Sans", WidgetFontStyle.REGULAR, 10.0));
model.runtimeChildren().addChild(label);
String xml = toXML(model);
System.out.println(xml);
assertThat(xml, containsString("display version=\"2"));
assertThat(xml, containsString("font>"));
DisplayModel readback = ModelReader.parseXML(xml);
assertThat(readback.getChildren().get(0).getProperty("font").isUsingWidgetClass(), equalTo(false));
// "use_class" is persisted in XML and read back
label.propFont().useWidgetClass(true);
xml = toXML(model);
System.out.println(xml);
assertThat(xml, containsString("font use_class=\"true\""));
readback = ModelReader.parseXML(xml);
assertThat(readback.getChildren().get(0).getProperty("font").isUsingWidgetClass(), equalTo(true));
}
use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.
the class ModelLoader method loadModel.
/**
* Load model, with classes applied (except for *.bcf itself)
*
* @param display_file Model file
* @return {@link DisplayModel}
* @throws Exception on error
*/
public static DisplayModel loadModel(final InputStream stream, final String display_path) throws Exception {
final ModelReader reader = new ModelReader(stream);
final DisplayModel model = reader.readModel();
model.setUserData(DisplayModel.USER_DATA_INPUT_FILE, display_path);
// Models from version 2 on support classes
if (reader.getVersion().getMajor() >= 2 && !display_path.endsWith(WidgetClassSupport.FILE_EXTENSION)) {
WidgetClassesService.getWidgetClasses().apply(model);
}
return model;
}
Aggregations