Search in sources :

Example 1 with LinkingContainerFigure

use of org.csstudio.swt.widgets.figures.LinkingContainerFigure in project yamcs-studio by yamcs.

the class LinkingContainerEditpart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    LinkingContainerFigure f = new LinkingContainerFigure();
    f.setZoomToFitAll(getWidgetModel().isAutoFit());
    f.getZoomManager().addZoomListener(new ZoomListener() {

        @Override
        public void zoomChanged(double arg0) {
            if (getViewer() == null || getViewer().getControl() == null) {
                // can happen before the parent is set.
                return;
            }
            getViewer().getControl().getDisplay().asyncExec(() -> updateConnectionList());
        }
    });
    return f;
}
Also used : LinkingContainerFigure(org.csstudio.swt.widgets.figures.LinkingContainerFigure) ZoomListener(org.eclipse.gef.editparts.ZoomListener)

Example 2 with LinkingContainerFigure

use of org.csstudio.swt.widgets.figures.LinkingContainerFigure in project yamcs-studio by yamcs.

the class LinkingContainerEditpart method configureDisplayModel.

private synchronized void configureDisplayModel() {
    // This need to be executed after GUI created.
    if (getWidgetModel().getDisplayModel() == null) {
        var path = resolveMacros(getWidgetModel().getOPIFilePath());
        var tempDisplayModel = new DisplayModel(path);
        getWidgetModel().setDisplayModel(tempDisplayModel);
        try {
            if (!path.isEmpty()) {
                XMLUtil.fillDisplayModelFromInputStream(ResourceUtil.pathToInputStream(path), tempDisplayModel, getViewer().getControl().getDisplay());
            }
        } catch (Exception e) {
            OPIBuilderPlugin.getLogger().log(Level.WARNING, "Could not reload the linking container.", e);
        }
    }
    var widgetModel = getWidgetModel();
    var displayModel = widgetModel.getDisplayModel();
    widgetModel.setDisplayModelViewer((GraphicalViewer) getViewer());
    widgetModel.setDisplayModelDisplayID(widgetModel.getRootDisplayModel(false).getDisplayID());
    UIBundlingThread.getInstance().addRunnable(() -> {
        var widgetModel1 = getWidgetModel();
        widgetModel1.setDisplayModelExecutionMode(getExecutionMode());
        widgetModel1.setDisplayModelOpiRuntime(widgetModel1.getRootDisplayModel(false).getOpiRuntime());
    });
    updateConnectionListForLinkedOpi(displayModel);
    if (originalPoints != null && !originalPoints.isEmpty()) {
        // update connections after the figure is repainted.
        getViewer().getControl().getDisplay().asyncExec(this::updateConnectionList);
    }
    UIBundlingThread.getInstance().addRunnable(() -> {
        layout();
        if (// getExecutionMode() == ExecutionMode.RUN_MODE &&
        !getWidgetModel().isAutoFit() && !getWidgetModel().isAutoSize()) {
            var childrenRange = GeometryUtil.getChildrenRange(LinkingContainerEditpart.this);
            getWidgetModel().setChildrenGeoSize(new Dimension(childrenRange.width + childrenRange.x + figure.getInsets().left + figure.getInsets().right - 1, childrenRange.height + childrenRange.y + figure.getInsets().top + figure.getInsets().bottom - 1));
            getWidgetModel().scaleChildren();
        }
        ((LinkingContainerFigure) getFigure()).setShowScrollBars(getWidgetModel().isShowScrollBars());
        ((LinkingContainerFigure) getFigure()).setZoomToFitAll(getWidgetModel().isAutoFit());
        ((LinkingContainerFigure) getFigure()).updateZoom();
    });
    // Add scripts on display model
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        widgetModel.getScriptsInput().getScriptList().addAll(widgetModel.getDisplayModel().getScriptsInput().getScriptList());
    }
    // tempDisplayModel.removeAllChildren();
    var map = new LinkedHashMap<String, String>();
    AbstractContainerModel loadTarget = displayModel;
    if (!widgetModel.getGroupName().trim().equals("")) {
        var group = displayModel.getChildByName(widgetModel.getGroupName());
        if (group != null && group instanceof AbstractContainerModel) {
            loadTarget = (AbstractContainerModel) group;
        }
    }
    // Load "LCID" macro whose value is unique to this instance of Linking Container.
    if (widgetModel.getExecutionMode() == ExecutionMode.RUN_MODE) {
        map.put("LCID", "LCID_" + getLinkingContainerID());
    }
    // Load system macro
    if (displayModel.getMacrosInput().isInclude_parent_macros()) {
        map.putAll(displayModel.getParentMacroMap());
    }
    // Load macro from its macrosInput
    map.putAll(displayModel.getMacrosInput().getMacrosMap());
    // It also include the macros on this linking container
    // which includes the macros from action and global macros if included
    // It will replace the old one too.
    map.putAll(widgetModel.getMacroMap());
    widgetModel.setMacroMap(map);
    widgetModel.removeAllChildren();
    widgetModel.addChildren(loadTarget.getChildren(), true);
    widgetModel.setDisplayModel(displayModel);
    var parentDisplay = widgetModel.getRootDisplayModel();
    parentDisplay.syncConnections();
    var parentDisplay2 = widgetModel.getRootDisplayModel(false);
    if (parentDisplay != parentDisplay2) {
        parentDisplay2.syncConnections();
    }
    if (getWidgetModel().isAutoSize()) {
        performAutosize();
    }
}
Also used : LinkingContainerFigure(org.csstudio.swt.widgets.figures.LinkingContainerFigure) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Dimension(org.eclipse.draw2d.geometry.Dimension) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkingContainerFigure (org.csstudio.swt.widgets.figures.LinkingContainerFigure)2 LinkedHashMap (java.util.LinkedHashMap)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 ZoomListener (org.eclipse.gef.editparts.ZoomListener)1