Search in sources :

Example 11 with DisplayModel

use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.

the class OPIWidgetsTransfer method nativeToJava.

@Override
public Object nativeToJava(TransferData transferData) {
    if (!isSupportedType(transferData))
        return null;
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    if (bytes == null)
        return null;
    try {
        DisplayModel displayModel = // $NON-NLS-1$
        (DisplayModel) XMLUtil.fillWidgetsFromXMLString(new String(bytes, "UTF-8"), null);
        List<AbstractWidgetModel> widgets = displayModel.getChildren();
        return widgets;
    } catch (Exception e) {
        OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to transfer XML to widget", e);
    }
    return null;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel)

Example 12 with DisplayModel

use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.

the class LinkingContainerEditpart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (newValue != null && newValue instanceof IPath) {
                LinkingContainerModel widgetModel = getWidgetModel();
                IPath absolutePath = (IPath) newValue;
                if (!absolutePath.isAbsolute())
                    absolutePath = ResourceUtil.buildAbsolutePath(getWidgetModel(), absolutePath);
                if (oldValue != null && oldValue instanceof IPath) {
                    widgetModel.setDisplayModel(null);
                } else {
                    DisplayModel displayModel = new DisplayModel(resolveMacros(absolutePath));
                    if (widgetModel.getMacroMap().equals(displayModel.getMacroMap())) {
                        widgetModel.setDisplayModel(displayModel);
                    } else {
                        widgetModel.setDisplayModel(null);
                    }
                }
                configureDisplayModel();
            }
            return true;
        }
    };
    setPropertyChangeHandler(LinkingContainerModel.PROP_OPI_FILE, handler);
    // load from group
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            // loadWidgets(getWidgetModel(),true);
            configureDisplayModel();
            return false;
        }
    };
    setPropertyChangeHandler(LinkingContainerModel.PROP_GROUP_NAME, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if ((int) newValue == LinkingContainerModel.ResizeBehaviour.SIZE_OPI_TO_CONTAINER.ordinal()) {
                ((LinkingContainerFigure) figure).setZoomToFitAll(true);
            } else {
                ((LinkingContainerFigure) figure).setZoomToFitAll(false);
            }
            ((LinkingContainerFigure) figure).updateZoom();
            if ((int) newValue == LinkingContainerModel.ResizeBehaviour.SIZE_CONTAINER_TO_OPI.ordinal()) {
                performAutosize();
            }
            return false;
        }
    };
    setPropertyChangeHandler(LinkingContainerModel.PROP_RESIZE_BEHAVIOUR, handler);
    // loadWidgets(getWidgetModel(),true);
    configureDisplayModel();
}
Also used : LinkingContainerModel(org.csstudio.opibuilder.widgets.model.LinkingContainerModel) IPath(org.eclipse.core.runtime.IPath) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 13 with DisplayModel

use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.

the class LinkingContainerEditpart method configureDisplayModel.

/**
 * @param path the path of the OPI file
 */
private synchronized void configureDisplayModel() {
    // This need to be executed after GUI created.
    if (getWidgetModel().getDisplayModel() == null) {
        IPath path = resolveMacros(getWidgetModel().getOPIFilePath());
        log.info(path.toString());
        final DisplayModel 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);
        }
    }
    LinkingContainerModel widgetModel = getWidgetModel();
    DisplayModel displayModel = widgetModel.getDisplayModel();
    widgetModel.setDisplayModelViewer((GraphicalViewer) getViewer());
    widgetModel.setDisplayModelDisplayID(widgetModel.getRootDisplayModel(false).getDisplayID());
    UIBundlingThread.getInstance().addRunnable(new Runnable() {

        @Override
        public void run() {
            LinkingContainerModel widgetModel = getWidgetModel();
            widgetModel.setDisplayModelExecutionMode(getExecutionMode());
            widgetModel.setDisplayModelOpiRuntime(widgetModel.getRootDisplayModel(false).getOpiRuntime());
        }
    });
    updateConnectionListForLinkedOpi(displayModel);
    if (originalPoints != null && !originalPoints.isEmpty()) {
        // update connections after the figure is repainted.
        getViewer().getControl().getDisplay().asyncExec(() -> updateConnectionList());
    }
    UIBundlingThread.getInstance().addRunnable(() -> {
        layout();
        if (// getExecutionMode() == ExecutionMode.RUN_MODE &&
        !getWidgetModel().isAutoFit() && !getWidgetModel().isAutoSize()) {
            Rectangle 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();
    LinkedHashMap<String, String> map = new LinkedHashMap<>();
    AbstractContainerModel loadTarget = displayModel;
    if (!widgetModel.getGroupName().trim().equals("")) {
        // $NON-NLS-1$
        AbstractWidgetModel 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);
    DisplayModel parentDisplay = widgetModel.getRootDisplayModel();
    parentDisplay.syncConnections();
    DisplayModel parentDisplay2 = widgetModel.getRootDisplayModel(false);
    if (parentDisplay != parentDisplay2)
        parentDisplay2.syncConnections();
    if (getWidgetModel().isAutoSize()) {
        performAutosize();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) LinkedHashMap(java.util.LinkedHashMap) LinkingContainerModel(org.csstudio.opibuilder.widgets.model.LinkingContainerModel) LinkingContainerFigure(org.csstudio.swt.widgets.figures.LinkingContainerFigure) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel)

Example 14 with DisplayModel

use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.

the class OPIEditor method initDisplayModel.

/**
 */
private void initDisplayModel() {
    displayModel = new DisplayModel();
    displayModel.setOpiFilePath(getOPIFilePath());
    try {
        XMLUtil.fillDisplayModelFromInputStream(getInputStream(), displayModel);
    } catch (Exception e) {
        String message = "Error happened when loading the OPI file!\n";
        ErrorHandlerUtil.handleError(message, e, true, true);
        getEditorSite().getPage().closeEditor(this, false);
    }
}
Also used : DisplayModel(org.csstudio.opibuilder.model.DisplayModel) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with DisplayModel

use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.

the class ChangeOrderAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().size() == 0 || getSelectedObjects().size() == 1 && getSelectedObjects().get(0) instanceof EditPart && ((EditPart) getSelectedObjects().get(0)).getModel() instanceof DisplayModel)
        return false;
    Map<AbstractContainerModel, List<IndexedWidget>> widgetMap = new HashMap<AbstractContainerModel, List<IndexedWidget>>();
    fillWidgetMap(widgetMap);
    // create compound command
    for (final Map.Entry<AbstractContainerModel, List<IndexedWidget>> entry : widgetMap.entrySet()) {
        // sort the list in map by the widget's original order in its container
        AbstractContainerModel container = entry.getKey();
        List<IndexedWidget> widgetList = entry.getValue();
        Collections.sort(widgetList);
        int newIndex;
        switch(orderType) {
            case TO_FRONT:
                newIndex = container.getChildren().size() - 1;
                break;
            case STEP_FRONT:
                newIndex = widgetList.get(widgetList.size() - 1).getIndex() + 1;
                break;
            case STEP_BACK:
                newIndex = widgetList.get(0).getIndex() - 1;
                break;
            case TO_BACK:
            default:
                newIndex = 0;
                break;
        }
        if (newIndex > container.getChildren().size() - 1 || newIndex < 0)
            return false;
        for (IndexedWidget indexedWidget : widgetList) {
            if (container.getIndexOf(indexedWidget.getWidget()) != newIndex)
                return true;
        }
    }
    return false;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) HashMap(java.util.HashMap) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) EditPart(org.eclipse.gef.EditPart) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DisplayModel (org.csstudio.opibuilder.model.DisplayModel)20 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)9 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)7 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)4 IPath (org.eclipse.core.runtime.IPath)3 Point (org.eclipse.draw2d.geometry.Point)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 FileNotFoundException (java.io.FileNotFoundException)2 List (java.util.List)2 AbstractLinkingContainerModel (org.csstudio.opibuilder.model.AbstractLinkingContainerModel)2 LineAwareElement (org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement)2 WidgetDescriptor (org.csstudio.opibuilder.util.WidgetDescriptor)2 LinkingContainerModel (org.csstudio.opibuilder.widgets.model.LinkingContainerModel)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 PartInitException (org.eclipse.ui.PartInitException)2 Element (org.jdom.Element)2 JDOMException (org.jdom.JDOMException)2