Search in sources :

Example 6 with AbstractContainerModel

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

the class XMLUtil method widgetToXMLElement.

/**
 * Flatten a widget to XML element.
 *
 * @param widgetModel
 *            model of the widget
 * @return the XML element
 */
public static Element widgetToXMLElement(AbstractWidgetModel widgetModel) {
    Element result = new Element((widgetModel instanceof DisplayModel) ? XMLTAG_DISPLAY : (widgetModel instanceof ConnectionModel) ? XMLTAG_CONNECTION : XMLTAG_WIDGET);
    result.setAttribute(XMLATTR_TYPEID, widgetModel.getTypeID());
    result.setAttribute(XMLATTR_VERSION, widgetModel.getVersion().toString());
    List<String> propIds = new ArrayList<>(widgetModel.getAllPropertyIDs());
    Collections.sort(propIds);
    for (String propId : propIds) {
        if (widgetModel.getProperty(propId).isSavable()) {
            Element propElement = new Element(propId);
            widgetModel.getProperty(propId).writeToXML(propElement);
            result.addContent(propElement);
        }
    }
    if (widgetModel instanceof AbstractContainerModel && !(widgetModel instanceof AbstractLinkingContainerModel)) {
        AbstractContainerModel containerModel = (AbstractContainerModel) widgetModel;
        for (AbstractWidgetModel child : containerModel.getChildren()) {
            result.addContent(widgetToXMLElement(child));
        }
    }
    // convert connections on this displayModel to xml element
    if (widgetModel instanceof DisplayModel && ((DisplayModel) widgetModel).getConnectionList() != null) {
        for (ConnectionModel connectionModel : ((DisplayModel) widgetModel).getConnectionList()) {
            if (!connectionModel.isLoadedFromLinkedOpi()) {
                Element connElement = widgetToXMLElement(connectionModel);
                result.addContent(connElement);
            }
        }
    }
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) LineAwareElement(org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) AbstractLinkingContainerModel(org.csstudio.opibuilder.model.AbstractLinkingContainerModel)

Example 7 with AbstractContainerModel

use of org.csstudio.opibuilder.model.AbstractContainerModel 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 8 with AbstractContainerModel

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

the class NativeTextEditpart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    super.registerPropertyChangeHandlers();
    removeAllPropertyChangeHandlers(NativeTextModel.PROP_ALIGN_H);
    PropertyChangeListener updatePropSheetListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            updatePropSheet();
        }
    };
    getWidgetModel().getProperty(NativeTextModel.PROP_MULTILINE_INPUT).addPropertyChangeListener(updatePropSheetListener);
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            AbstractWidgetModel model = getWidgetModel();
            AbstractContainerModel parent = model.getParent();
            parent.removeChild(model);
            parent.addChild(model);
            parent.selectWidget(model, true);
            return false;
        }
    };
    setPropertyChangeHandler(NativeTextModel.PROP_SHOW_NATIVE_BORDER, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_MULTILINE_INPUT, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_WRAP_WORDS, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_SHOW_H_SCROLL, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_SHOW_V_SCROLL, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_PASSWORD_INPUT, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_ALIGN_H, handler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 9 with AbstractContainerModel

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

the class NativeTextEditpartDelegate method registerPropertyChangeHandlers.

@Override
public void registerPropertyChangeHandlers() {
    editpart.removeAllPropertyChangeHandlers(TextInputModel.PROP_ALIGN_H);
    PropertyChangeListener updatePropSheetListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            updatePropSheet();
        }
    };
    model.getProperty(TextInputModel.PROP_MULTILINE_INPUT).addPropertyChangeListener(updatePropSheetListener);
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            AbstractContainerModel parent = model.getParent();
            parent.removeChild(model);
            parent.addChild(model);
            parent.selectWidget(model, true);
            return false;
        }
    };
    editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_NATIVE_BORDER, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_MULTILINE_INPUT, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_WRAP_WORDS, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_H_SCROLL, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_V_SCROLL, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_PASSWORD_INPUT, handler);
    editpart.setPropertyChangeHandler(TextInputModel.PROP_ALIGN_H, handler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 10 with AbstractContainerModel

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

the class CopyWidgetsAction method getSelectedWidgetModels.

/**
 * Gets the widget models of all currently selected EditParts.
 *
 * @return a list with all widget models that are currently selected.
 * The order of the selected widgets was kept.
 */
protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
    List<?> selection = getSelectedObjects();
    List<AbstractWidgetModel> sameParentModels = new ArrayList<AbstractWidgetModel>();
    List<AbstractWidgetModel> differentParentModels = new ArrayList<AbstractWidgetModel>();
    List<AbstractWidgetModel> result = new ArrayList<AbstractWidgetModel>();
    AbstractContainerModel parent = null;
    for (Object o : selection) {
        if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
            AbstractWidgetModel widgetModel = (AbstractWidgetModel) ((EditPart) o).getModel();
            if (parent == null)
                parent = widgetModel.getParent();
            if (widgetModel.getParent() == parent)
                sameParentModels.add(widgetModel);
            else
                differentParentModels.add(widgetModel);
        }
    }
    // sort widgets to its original order
    if (sameParentModels.size() > 1) {
        AbstractWidgetModel[] modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
        Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {

            @Override
            public int compare(AbstractWidgetModel o1, AbstractWidgetModel o2) {
                if (o1.getParent().getChildren().indexOf(o1) > o2.getParent().getChildren().indexOf(o2))
                    return 1;
                else
                    return -1;
            }
        });
        result.addAll(Arrays.asList(modelArray));
        if (differentParentModels.size() > 0)
            result.addAll(differentParentModels);
        return result;
    }
    if (differentParentModels.size() > 0)
        sameParentModels.addAll(differentParentModels);
    return sameParentModels;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Aggregations

AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)34 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)27 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)11 ArrayList (java.util.ArrayList)10 Rectangle (org.eclipse.draw2d.geometry.Rectangle)10 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)9 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)7 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)6 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)5 IFigure (org.eclipse.draw2d.IFigure)5 Point (org.eclipse.draw2d.geometry.Point)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeListener (java.beans.PropertyChangeListener)4 List (java.util.List)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)4 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4 HashMap (java.util.HashMap)3 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)3