Search in sources :

Example 61 with AbstractWidgetModel

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

the class GroupingContainerEditPart method resizeChildren.

private void resizeChildren(int newValue, int oldValue, boolean isWidth) {
    if (!getWidgetModel().isLocked())
        return;
    if (getExecutionMode() == ExecutionMode.RUN_MODE && getWidgetModel().getRootDisplayModel().getDisplayScaleData().isAutoScaleWidgets() && (getWidgetModel().getScaleOptions().isHeightScalable() || getWidgetModel().getScaleOptions().isWidthScalable()))
        return;
    double ratio = (newValue - oldValue) / (double) oldValue;
    for (AbstractWidgetModel child : getWidgetModel().getChildren()) {
        if (isWidth) {
            child.setX((int) (child.getX() * (1 + ratio)));
            child.setWidth((int) (child.getWidth() * (1 + ratio)));
        } else {
            child.setY((int) (child.getY() * (1 + ratio)));
            child.setHeight((int) (child.getHeight() * (1 + ratio)));
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel)

Example 62 with AbstractWidgetModel

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

the class LinkingContainerEditpart method performAutosize.

/**
 * Automatically set the container size according its children's geography size.
 */
@Override
public void performAutosize() {
    Rectangle childrenRange = GeometryUtil.getChildrenRange(this);
    if (connectionList != null) {
        for (ConnectionModel connModel : connectionList) {
            final PointList connectionPoints = connModel.getPoints();
            childrenRange.union(connectionPoints.getBounds());
        }
    }
    cropTranslation = new Point(-childrenRange.x, -childrenRange.y);
    getWidgetModel().setSize(new Dimension(childrenRange.width + figure.getInsets().left + figure.getInsets().right, childrenRange.height + figure.getInsets().top + figure.getInsets().bottom));
    for (Object editPart : getChildren()) {
        AbstractWidgetModel widget = ((AbstractBaseEditPart) editPart).getWidgetModel();
        widget.setLocation(widget.getLocation().translate(cropTranslation));
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 63 with AbstractWidgetModel

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

the class TabEditPart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    TabFigure tabFigure = new TabFigure();
    tabFigure.setHorizontal(getWidgetModel().isHorizontal());
    tabFigure.setMinimumTabHeight(getWidgetModel().getMinimumTabHeight());
    tabFigure.addTabListener(new ITabListener() {

        @Override
        public void activeTabIndexChanged(int oldIndex, int newIndex) {
            for (AbstractWidgetModel child : getWidgetModel().getChildren()) child.setPropertyValue(AbstractWidgetModel.PROP_VISIBLE, false);
            getWidgetModel().getChildren().get(newIndex).setPropertyValue(AbstractWidgetModel.PROP_VISIBLE, true);
        // if (getExecutionMode() == ExecutionMode.RUN_MODE)
        // setPropertyValue(TabModel.PROP_ACTIVE_TAB, newIndex);
        }
    });
    return tabFigure;
}
Also used : ITabListener(org.csstudio.swt.widgets.figures.TabFigure.ITabListener) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) TabFigure(org.csstudio.swt.widgets.figures.TabFigure)

Example 64 with AbstractWidgetModel

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

the class TabEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    // init tabs
    int i = 0;
    for (AbstractWidgetModel child : getWidgetModel().getChildren()) {
        if (child instanceof GroupingContainerModel) {
            child.setPropertyValue(AbstractWidgetModel.PROP_VISIBLE, true);
            child.setPropertyValue(AbstractWidgetModel.PROP_VISIBLE, false);
            getTabFigure().addTab((String) getWidgetModel().getPropertyValue(TabModel.makeTabPropID(TabProperty.TITLE.propIDPre, i)));
            tabItemList.add(i, new TabItem(getWidgetModel(), i, (GroupingContainerModel) child));
            for (TabProperty tabProperty : TabProperty.values()) setTabProperty(i, tabProperty, getWidgetModel().getPropertyValue(TabModel.makeTabPropID(tabProperty.propIDPre, i)));
            i++;
        }
    }
    IWidgetPropertyChangeHandler relocContainerHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            updateTabAreaSize();
            refreshVisuals();
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_WIDTH, relocContainerHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_HEIGHT, relocContainerHandler);
    IWidgetPropertyChangeHandler horizontalHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((TabFigure) figure).setHorizontal((Boolean) newValue);
            updateTabAreaSize();
            refreshVisuals();
            return false;
        }
    };
    setPropertyChangeHandler(TabModel.PROP_HORIZONTAL_TABS, horizontalHandler);
    IWidgetPropertyChangeHandler activeTabHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((TabFigure) figure).setActiveTabIndex((Integer) newValue);
            updateTabAreaSize();
            refreshVisuals();
            return false;
        }
    };
    setPropertyChangeHandler(TabModel.PROP_ACTIVE_TAB, activeTabHandler);
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((TabFigure) figure).setMinimumTabHeight((Integer) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(TabModel.PROP_MINIMUM_TAB_HEIGHT, handler);
    IWidgetPropertyChangeHandler updateTabAreaSizeHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            updateTabAreaSize();
            return false;
        }
    };
    setPropertyChangeHandler(TabModel.PROP_BORDER_WIDTH, updateTabAreaSizeHandler);
    registerTabPropertyChangeHandlers();
    registerTabsAmountChangeHandler();
}
Also used : GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) TabProperty(org.csstudio.opibuilder.widgets.model.TabModel.TabProperty) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) TabFigure(org.csstudio.swt.widgets.figures.TabFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 65 with AbstractWidgetModel

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

the class TextUpdateEditPart method registerPropertyChangeHandlers.

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

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

                    @Override
                    public void run() {
                        performAutoSize();
                    }
                });
            }
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_TEXT, handler);
    IWidgetPropertyChangeHandler fontHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setFont(CustomMediaFactory.getInstance().getFont(((OPIFont) newValue).getFontData()));
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_FONT, fontHandler);
    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()) {
                        performAutoSize();
                        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) {
            figure.setOpaque(!(Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_TRANSPARENT, handler);
    handler = new IWidgetPropertyChangeHandler() {

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

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (figure instanceof TextFigure)
                ((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) {
            if (figure instanceof TextFigure)
                ((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, final IFigure figure) {
            if (newValue == null)
                return false;
            formatValue(newValue, AbstractPVWidgetModel.PROP_PVVALUE);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVVALUE, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            format = FormatEnum.values()[(Integer) newValue];
            formatValue(newValue, TextUpdateModel.PROP_FORMAT_TYPE);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_FORMAT_TYPE, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            precision = (Integer) newValue;
            formatValue(newValue, TextUpdateModel.PROP_PRECISION);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_PRECISION, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            isPrecisionFromDB = (Boolean) newValue;
            formatValue(newValue, TextUpdateModel.PROP_PRECISION_FROM_DB);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_PRECISION_FROM_DB, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            isShowUnits = (Boolean) newValue;
            formatValue(newValue, TextUpdateModel.PROP_SHOW_UNITS);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_SHOW_UNITS, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, final IFigure figure) {
            if (figure instanceof TextFigure)
                ((TextFigure) figure).setRotate((Double) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(TextUpdateModel.PROP_ROTATION, 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(TextUpdateModel.PROP_WRAP_WORDS, handler);
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) NativeTextFigure(org.csstudio.opibuilder.widgets.figures.NativeTextFigure) TextFigure(org.csstudio.swt.widgets.figures.TextFigure) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

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