Search in sources :

Example 46 with AbstractWidgetModel

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

the class LabelEditPart method registerPropertyChangeHandlers.

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

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            ((TextFigure) figure).setText((String) newValue);
            Display.getCurrent().timerExec(10, new Runnable() {

                @Override
                public void run() {
                    if (getWidgetModel().isAutoSize())
                        getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
                }
            });
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_TEXT, handler);
    IWidgetPropertyChangeHandler clickableHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((TextFigure) figure).setSelectable(determinSelectable());
            return false;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ACTIONS, clickableHandler);
    setPropertyChangeHandler(LabelModel.PROP_TOOLTIP, clickableHandler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            Display.getCurrent().timerExec(10, new Runnable() {

                @Override
                public void run() {
                    if (getWidgetModel().isAutoSize()) {
                        getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
                        figure.revalidate();
                    }
                }
            });
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_FONT, handler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_STYLE, handler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_WIDTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((TextFigure) figure).setOpaque(!(Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_TRANSPARENT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if ((Boolean) newValue) {
                getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
                figure.revalidate();
            }
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_AUTOSIZE, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((TextFigure) figure).setHorizontalAlignment(H_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_H, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((TextFigure) figure).setVerticalAlignment(V_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_V, handler);
    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(LabelModel.PROP_WRAP_WORDS, handler);
    getWidgetModel().getProperty(LabelModel.PROP_WRAP_WORDS).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            updatePropertyVisibility();
        }
    });
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (figure instanceof WrappableTextFigure)
                ((WrappableTextFigure) figure).setShowScrollbar((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_SHOW_SCROLLBAR, handler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) PropertyChangeListener(java.beans.PropertyChangeListener) WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) TextFigure(org.csstudio.swt.widgets.figures.TextFigure) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 47 with AbstractWidgetModel

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

the class LinkingContainerEditpart method layout.

@Override
public void layout() {
    AbstractLayoutEditpart layoutter = getLayoutWidget();
    if (layoutter != null && layoutter.getWidgetModel().isEnabled()) {
        List<AbstractWidgetModel> modelChildren = new ArrayList<AbstractWidgetModel>();
        for (Object child : getChildren()) {
            if (child instanceof AbstractBaseEditPart && !(child instanceof AbstractLayoutEditpart)) {
                modelChildren.add(((AbstractBaseEditPart) child).getWidgetModel());
            }
        }
        layoutter.layout(modelChildren, getFigure().getClientArea());
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) AbstractLayoutEditpart(org.csstudio.opibuilder.editparts.AbstractLayoutEditpart)

Example 48 with AbstractWidgetModel

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

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

the class GeometryUtil method getChildrenRange.

/**
 *Get the range of children widgets.
 * @param container editpart of the container widget.
 * @return the range (minX, minY, maxX-minX, maxY-minY) relative to the container.
 */
public static Rectangle getChildrenRange(AbstractContainerEditpart container) {
    PointList pointList = new PointList(container.getChildren().size());
    for (Object child : container.getChildren()) {
        AbstractWidgetModel childModel = ((AbstractBaseEditPart) child).getWidgetModel();
        pointList.addPoint(childModel.getLocation());
        pointList.addPoint(childModel.getX() + childModel.getWidth(), childModel.getY() + childModel.getHeight());
    }
    return pointList.getBounds();
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart)

Example 50 with AbstractWidgetModel

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

the class ArrayModel method configureProperties.

@Override
protected void configureProperties() {
    addProperty(new IntegerProperty(PROP_ARRAY_LENGTH, "Array Length", WidgetPropertyCategory.Behavior, 10, 0, Integer.MAX_VALUE));
    addProperty(new IntegerProperty(PROP_SPINNER_WIDTH, "Spinner Width", WidgetPropertyCategory.Display, 40, 0, 1000));
    addProperty(new BooleanProperty(PROP_HORIZONTAL, "Horizontal", WidgetPropertyCategory.Display, false));
    addProperty(new BooleanProperty(PROP_SHOW_SPINNER, "Show Spinner", WidgetPropertyCategory.Display, true));
    addProperty(new BooleanProperty(PROP_SHOW_SCROLLBAR, "Show Scrollbar", WidgetPropertyCategory.Display, true));
    addProperty(new IntegerProperty(PROP_VISIBLE_ELEMENTS_COUNT, "Visible Elements Count", WidgetPropertyCategory.Display, 1, 0, 1000));
    addProperty(new ComboProperty(PROP_DATA_TYPE, "Data Type", WidgetPropertyCategory.Behavior, ArrayDataType.stringValues(), 0));
    setPropertyVisibleAndSavable(PROP_VISIBLE_ELEMENTS_COUNT, false, true);
    getProperty(PROP_VISIBLE_ELEMENTS_COUNT).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (getChildren().size() < 1)
                return;
            AbstractWidgetModel child = getChildren().get(0);
            removeAllChildren();
            addChild(child);
        }
    });
}
Also used : ComboProperty(org.csstudio.opibuilder.properties.ComboProperty) IntegerProperty(org.csstudio.opibuilder.properties.IntegerProperty) PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertyChangeListener(java.beans.PropertyChangeListener) BooleanProperty(org.csstudio.opibuilder.properties.BooleanProperty)

Aggregations

AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)82 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)27 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)22 Rectangle (org.eclipse.draw2d.geometry.Rectangle)18 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)17 ArrayList (java.util.ArrayList)15 Point (org.eclipse.draw2d.geometry.Point)14 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)12 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)10 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)9 IFigure (org.eclipse.draw2d.IFigure)9 PropertyChangeEvent (java.beans.PropertyChangeEvent)8 PropertyChangeListener (java.beans.PropertyChangeListener)8 Dimension (org.eclipse.draw2d.geometry.Dimension)8 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)7 EditPart (org.eclipse.gef.EditPart)7 PointList (org.eclipse.draw2d.geometry.PointList)6 List (java.util.List)5 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)5 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)5