Search in sources :

Example 1 with ModelReader

use of org.csstudio.display.builder.model.persist.ModelReader 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);
    }
}
Also used : ModelReader(org.csstudio.display.builder.model.persist.ModelReader) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 2 with ModelReader

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

the class WidgetClassSupport method loadClasses.

/**
 * Load widget classes
 *  @param stream Stream for a widget class file
 *  @throws Exception on error
 */
public void loadClasses(final InputStream stream) throws Exception {
    final DisplayModel model = new ModelReader(stream).readModel();
    model.propName().setValue(DEFAULT);
    registerClass(model);
    for (Widget widget : model.getChildren()) registerClass(widget);
}
Also used : ModelReader(org.csstudio.display.builder.model.persist.ModelReader)

Aggregations

ModelReader (org.csstudio.display.builder.model.persist.ModelReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1