Search in sources :

Example 66 with DisplayModel

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

the class RuntimeViewPart method disposeModel.

/**
 * Invoke close_handler for model
 */
private void disposeModel() {
    final DisplayModel model = active_model;
    active_model = null;
    if (model != null && close_handler != null)
        close_handler.accept(model);
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel)

Example 67 with DisplayModel

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

the class RuntimeViewPart method loadModel.

/**
 * Load display model, schedule representation
 *  @param info Display to load
 */
private void loadModel(final DisplayInfo info) {
    try {
        final DisplayModel model = info.shouldResolve() ? ModelLoader.resolveAndLoadModel(null, info.getPath()) : ModelLoader.loadModel(info.getPath());
        // This code is called
        // 1) From OpenDisplayAction
        // No macros in info.
        // 2) On application restart with DisplayInfo from memento
        // info contains snapshot of macros from last run
        // Could simply use info's macros if they are non-empty,
        // but merging macros with those loaded from model file
        // allows for newly added macros in the display file.
        final Macros macros = Macros.merge(model.propMacros().getValue(), info.getMacros());
        model.propMacros().setValue(macros);
        // For runtime, expand macros
        if (!representation.isEditMode())
            DisplayMacroExpander.expandDisplayMacros(model);
        // Schedule representation on UI thread
        representation.execute(() -> representModel(model));
    } catch (Exception ex) {
        final String message = "Cannot load " + info;
        logger.log(Level.SEVERE, message, ex);
        showMessage(message, ex);
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) Macros(org.csstudio.display.builder.model.macros.Macros) WorkbenchException(org.eclipse.ui.WorkbenchException) PartInitException(org.eclipse.ui.PartInitException)

Example 68 with DisplayModel

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

the class EmbeddedDisplayRepresentation method sizesChanged.

private void sizesChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    if (resizing)
        return;
    final int widget_width = model_widget.propWidth().getValue();
    final int widget_height = model_widget.propHeight().getValue();
    // "-2" to prevent triggering scrollbars
    inner.setMinWidth(widget_width - 2);
    inner.setMinHeight(widget_height - 2);
    final Resize resize = model_widget.propResize().getValue();
    final DisplayModel content_model = active_content_model.get();
    if (content_model != null) {
        final int content_width = content_model.propWidth().getValue();
        final int content_height = content_model.propHeight().getValue();
        if (resize == Resize.ResizeContent) {
            // Adjust sizes by +-1 so that content is completely visible
            final double zoom_x = content_width > 0 ? (double) (widget_width - 1) / (content_width + 1) : 1.0;
            final double zoom_y = content_height > 0 ? (double) (widget_height - 1) / (content_height + 1) : 1.0;
            zoom_factor = Math.min(zoom_x, zoom_y);
        } else if (resize == Resize.SizeToContent) {
            zoom_factor = 1.0;
            resizing = true;
            // Adjust sizes by 2 so that content is completely visible
            if (content_width > 0)
                model_widget.propWidth().setValue(content_width + 2);
            if (content_height > 0)
                model_widget.propHeight().setValue(content_height + 2);
            resizing = false;
        }
    }
    dirty_sizes.mark();
    toolkit.scheduleUpdate(this);
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel) Resize(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget.Resize)

Example 69 with DisplayModel

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

the class EmbeddedDisplayRepresentation method updatePendingDisplay.

/**
 * Update to the next pending display
 *
 *  <p>Synchronized to serialize the background threads.
 *
 *  <p>Example: Displays A, B, C are requested in quick succession.
 *
 *  <p>pending_display_and_group=A is submitted to executor thread A.
 *
 *  <p>While handling A, pending_display_and_group=B is submitted to executor thread B.
 *  Thread B will be blocked in synchronized method.
 *
 *  <p>Then pending_display_and_group=C is submitted to executor thread C.
 *  As thread A finishes, thread B finds pending_display_and_group==C.
 *  As thread C finally continues, it finds pending_display_and_group empty.
 *  --> Showing A, then C, skipping B.
 */
private synchronized void updatePendingDisplay() {
    final DisplayAndGroup handle = pending_display_and_group.getAndSet(null);
    if (handle == null) {
        // System.out.println("Nothing to handle");
        return;
    }
    if (inner == null) {
        // System.out.println("Aborted: " + handle);
        return;
    }
    try {
        // Load new model (potentially slow)
        final DisplayModel new_model = loadDisplayModel(model_widget, handle);
        // Stop (old) runtime
        // EmbeddedWidgetRuntime tracks this property to start/stop the embedded model's runtime
        model_widget.runtimePropEmbeddedModel().setValue(null);
        // Atomically update the 'active' model
        final DisplayModel old_model = active_content_model.getAndSet(new_model);
        new_model.propBackgroundColor().addUntypedPropertyListener(this::backgroundChanged);
        if (old_model != null) {
            // Dispose old model
            final Future<Object> completion = toolkit.submit(() -> {
                toolkit.disposeRepresentation(old_model);
                return null;
            });
            checkCompletion(model_widget, completion, "timeout disposing old representation");
        }
        // Represent new model on UI thread
        final Future<Object> completion = toolkit.submit(() -> {
            representContent(new_model);
            return null;
        });
        checkCompletion(model_widget, completion, "timeout representing new content");
        // Allow EmbeddedWidgetRuntime to start the new runtime
        model_widget.runtimePropEmbeddedModel().setValue(new_model);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to handle embedded display " + handle, ex);
    }
}
Also used : DisplayAndGroup(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)

Example 70 with DisplayModel

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

the class NavigationTabsRepresentation method updatePendingDisplay.

/**
 * Update to the next pending display
 *
 *  <p>Synchronized to serialize the background threads.
 *
 *  <p>Example: Displays A, B, C are requested in quick succession.
 *
 *  <p>pending_display_and_group=A is submitted to executor thread A.
 *
 *  <p>While handling A, pending_display_and_group=B is submitted to executor thread B.
 *  Thread B will be blocked in synchronized method.
 *
 *  <p>Then pending_display_and_group=C is submitted to executor thread C.
 *  As thread A finishes, thread B finds pending_display_and_group==C.
 *  As thread C finally continues, it finds pending_display_and_group empty.
 *  --> Showing A, then C, skipping B.
 */
private synchronized void updatePendingDisplay() {
    final DisplayAndGroup handle = pending_display_and_group.getAndSet(null);
    if (handle == null)
        return;
    if (body == null) {
        // System.out.println("Aborted: " + handle);
        return;
    }
    try {
        // Load new model (potentially slow)
        final DisplayModel new_model = loadDisplayModel(model_widget, handle);
        // Atomically update the 'active' model
        final DisplayModel old_model = active_content_model.getAndSet(new_model);
        if (old_model != null) {
            // Dispose old model
            final Future<Object> completion = toolkit.submit(() -> {
                toolkit.disposeRepresentation(old_model);
                return null;
            });
            checkCompletion(model_widget, completion, "timeout disposing old representation");
        }
        // Represent new model on UI thread
        final Future<Object> completion = toolkit.submit(() -> {
            representContent(new_model);
            return null;
        });
        checkCompletion(model_widget, completion, "timeout representing new content");
        model_widget.runtimePropEmbeddedModel().setValue(new_model);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to handle embedded display " + handle, ex);
    }
}
Also used : DisplayAndGroup(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)

Aggregations

DisplayModel (org.csstudio.display.builder.model.DisplayModel)73 Widget (org.csstudio.display.builder.model.Widget)15 Test (org.junit.Test)10 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)9 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)7 EmbeddedDisplayRepresentationUtil.loadDisplayModel (org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)5 Image (javafx.scene.image.Image)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Parent (javafx.scene.Parent)3 Macros (org.csstudio.display.builder.model.macros.Macros)3 PictureWidget (org.csstudio.display.builder.model.widgets.PictureWidget)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 Rectangle2D (javafx.geometry.Rectangle2D)2 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)2 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)2 ModelWriter (org.csstudio.display.builder.model.persist.ModelWriter)2