Search in sources :

Example 6 with DisplayModel

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

the class XMLUtil method fillLinkingContainerSub.

private static void fillLinkingContainerSub(final AbstractLinkingContainerModel container, List<IPath> trace, final MacrosInput macrosInput_) throws Exception {
    if (container == null)
        return;
    if (container.getRootDisplayModel() != null && container.getRootDisplayModel().getOpiFilePath() != null) {
        if (trace.contains(container.getRootDisplayModel().getOpiFilePath())) {
            container.setOPIFilePath("");
            throw new Exception("Opi link contains some loops.\n" + trace.toString());
        } else {
            trace.add(container.getRootDisplayModel().getOpiFilePath());
        }
        IPath path = container.getOPIFilePath();
        if (path != null && !path.isEmpty()) {
            final Map<String, String> macroMap = PreferencesHelper.getMacros();
            if (macrosInput_ != null && macrosInput_.getMacrosMap() != null) {
                macroMap.putAll(macrosInput_.getMacrosMap());
            }
            macroMap.putAll(buildMacroMap(container));
            String resolvedPath = MacroUtil.replaceMacros(path.toString(), s -> macroMap.get(s));
            path = ResourceUtil.getPathFromString(resolvedPath);
            final DisplayModel inside = new DisplayModel(path);
            inside.setDisplayID(container.getRootDisplayModel(false).getDisplayID());
            inside.setParentDisplayModel(container.getRootDisplayModel());
            try {
                fillDisplayModelFromInputStreamSub(ResourceUtil.pathToInputStream(path), inside, Display.getCurrent(), trace, macrosInput_);
            } catch (Exception ex) {
                OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to load LinkingContainer opi_file " + path, ex);
            }
            // mark connection as it is loaded from linked opi
            for (AbstractWidgetModel w : inside.getAllDescendants()) for (ConnectionModel conn : w.getSourceConnections()) conn.setLoadedFromLinkedOpi(true);
            AbstractContainerModel loadTarget = inside;
            if (!container.getGroupName().trim().equals("")) {
                // $NON-NLS-1$
                AbstractWidgetModel group = inside.getChildByName(container.getGroupName());
                if (group != null && group instanceof AbstractContainerModel) {
                    loadTarget = (AbstractContainerModel) group;
                }
            }
            // container.addChildren(loadTarget.getChildren(), true);
            container.setDisplayModel(inside);
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) IPath(org.eclipse.core.runtime.IPath) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException)

Example 7 with DisplayModel

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

the class CopyWidgetsAction method run.

@Override
public void run() {
    DisplayModel tempModel = new DisplayModel();
    List<AbstractWidgetModel> widgetModels = getSelectedWidgetModels();
    for (AbstractWidgetModel widget : widgetModels) {
        tempModel.addChild(widget, false);
    }
    String xml = XMLUtil.widgetToXMLString(tempModel, false);
    ((OPIEditor) getWorkbenchPart()).getClipboard().setContents(new Object[] { xml }, new Transfer[] { OPIWidgetsTransfer.getInstance() });
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            IAction pasteAction = ((ActionRegistry) ((OPIEditor) getWorkbenchPart()).getAdapter(ActionRegistry.class)).getAction(ActionFactory.PASTE.getId());
            if (pasteAction != null) {
                ((PasteWidgetsAction) pasteAction).refreshEnable();
            }
        }
    });
}
Also used : OPIEditor(org.csstudio.opibuilder.editor.OPIEditor) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IAction(org.eclipse.jface.action.IAction) DisplayModel(org.csstudio.opibuilder.model.DisplayModel)

Example 8 with DisplayModel

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

the class PasteWidgetsAction method getAbsolutePosition.

/**
 * @param widgetModel
 * @return the absolute position of a widget relative to display.
 */
private Point getAbsolutePosition(AbstractWidgetModel widgetModel) {
    if (widgetModel instanceof DisplayModel)
        return new Point(0, 0);
    Point result = widgetModel.getLocation();
    AbstractContainerModel parent = widgetModel.getParent();
    while (!(parent instanceof DisplayModel)) {
        result.translate(parent.getLocation());
        parent = parent.getParent();
    }
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Point(org.eclipse.draw2d.geometry.Point)

Example 9 with DisplayModel

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

the class NewOPIFileWizardPage method getInitialContents.

@Override
protected InputStream getInitialContents() {
    DisplayModel displayModel = new DisplayModel();
    SchemaService.getInstance().applySchema(displayModel);
    String s = XMLUtil.widgetToXMLString(displayModel, true);
    InputStream result = new ByteArrayInputStream(s.getBytes());
    return result;
}
Also used : DisplayModel(org.csstudio.opibuilder.model.DisplayModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 10 with DisplayModel

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

the class CreateGroupAction method run.

@Override
public void run(IAction action) {
    List<AbstractWidgetModel> originalSelectedWidgets = getSelectedWidgetModels();
    CompoundCommand compoundCommand = new CompoundCommand("Create Group");
    List<AbstractWidgetModel> selectedWidgets = new ArrayList<AbstractWidgetModel>();
    selectedWidgets.addAll(originalSelectedWidgets);
    // remove the selected widgets which are children of another selected widget.
    for (AbstractWidgetModel widget : originalSelectedWidgets) {
        if (widget instanceof DisplayModel) {
            selectedWidgets.remove(widget);
            continue;
        }
        if (widget instanceof AbstractContainerModel) {
            for (AbstractWidgetModel child : originalSelectedWidgets) {
                if (((AbstractContainerModel) widget).getChildren().contains(child))
                    selectedWidgets.remove(child);
            }
        }
    }
    int minDepth = Integer.MAX_VALUE;
    int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
    AbstractWidgetModel minDepthWidget = selectedWidgets.get(0);
    for (AbstractWidgetModel widget : selectedWidgets) {
        int leftX = widget.getLocation().x;
        int upY = widget.getLocation().y;
        int rightX = widget.getLocation().x + widget.getSize().width;
        int bottomY = widget.getLocation().y + widget.getSize().height;
        int depth = widget.getNestedDepth();
        if (leftX < minX)
            minX = leftX;
        if (upY < minY)
            minY = upY;
        if (rightX > maxX)
            maxX = rightX;
        if (bottomY > maxY)
            maxY = bottomY;
        if (minDepth > depth) {
            minDepth = depth;
            minDepthWidget = widget;
        }
    }
    // Orphan order should be reversed so that undo operation has the correct order.
    AbstractWidgetModel[] widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
    for (int i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
    }
    GroupingContainerModel groupingContainerModel = new GroupingContainerModel();
    SchemaService.getInstance().applySchema(groupingContainerModel);
    // the parent should be the widget with minimum nested depth
    AbstractContainerModel parent = minDepthWidget.getParent();
    int borderWidth = 0;
    if (groupingContainerModel.getBorderStyle() == BorderStyle.GROUP_BOX)
        borderWidth = 30;
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN, true);
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_SHOW_SCROLLBAR, false);
    compoundCommand.add(new WidgetCreateCommand(groupingContainerModel, parent, new Rectangle(minX, minY, maxX - minX + borderWidth, maxY - minY + borderWidth), false));
    for (AbstractWidgetModel widget : selectedWidgets) {
        compoundCommand.add(new AddWidgetCommand(groupingContainerModel, widget, new Rectangle(widget.getLocation().translate(-minX, -minY), widget.getSize())));
    }
    execute(compoundCommand);
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand)

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