Search in sources :

Example 21 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 22 with AbstractWidgetModel

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

the class ArrayModel method addChild.

@Override
public synchronized void addChild(AbstractWidgetModel child, boolean changeParent) {
    if (!getChildren().isEmpty())
        return;
    // child should not be scalable because their size are layoutted by the array figure.
    child.setScaleOptions(false, false, false);
    super.addChild(child, changeParent);
    for (int i = 1; i < getVisibleElementsCount(); i++) {
        try {
            AbstractWidgetModel clone = XMLUtil.XMLElementToWidget(XMLUtil.widgetToXMLElement(child));
            super.addChild(clone, changeParent);
        } catch (Exception e) {
            ErrorHandlerUtil.handleError("Failed to generate copy of the element widget in array widget.", e);
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel)

Example 23 with AbstractWidgetModel

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

the class GroupingContainerModel method rotate90.

@Override
public void rotate90(boolean clockwise) {
    boolean oldLock = isLocked();
    setPropertyValue(PROP_LOCK_CHILDREN, false);
    Point center = new Point(getWidth() / 2, getHeight() / 2);
    for (AbstractWidgetModel abstractWidgetModel : getChildren()) {
        abstractWidgetModel.rotate90(clockwise, center);
    }
    Point oldLoc = getLocation();
    super.rotate90(clockwise);
    Point newLoc = getLocation();
    int dx = newLoc.x - oldLoc.x;
    int dy = newLoc.y - oldLoc.y;
    // move back
    for (AbstractWidgetModel abstractWidgetModel : getChildren()) {
        abstractWidgetModel.setLocation(abstractWidgetModel.getLocation().translate(-dx, -dy));
    }
    setPropertyValue(PROP_LOCK_CHILDREN, oldLock);
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 24 with AbstractWidgetModel

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

the class LabelEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    setPropertyChangeHandler(PROP_TEXT, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setText((String) newValue);
        Display.getCurrent().timerExec(10, () -> {
            if (getWidgetModel().isAutoSize()) {
                getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
            }
        });
        return true;
    });
    setPropertyChangeHandler(PROP_ACTIONS, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setSelectable(determinSelectable());
        return false;
    });
    setPropertyChangeHandler(PROP_TOOLTIP, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setSelectable(determinSelectable());
        return false;
    });
    IWidgetPropertyChangeHandler handler = (oldValue, newValue, figure) -> {
        Display.getCurrent().timerExec(10, () -> {
            if (getWidgetModel().isAutoSize()) {
                getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
                figure.revalidate();
            }
        });
        return true;
    };
    setPropertyChangeHandler(PROP_FONT, handler);
    setPropertyChangeHandler(PROP_BORDER_STYLE, handler);
    setPropertyChangeHandler(PROP_BORDER_WIDTH, handler);
    setPropertyChangeHandler(PROP_TRANSPARENT, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setOpaque(!(Boolean) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_AUTOSIZE, (oldValue, newValue, figure) -> {
        if ((Boolean) newValue) {
            getWidgetModel().setSize(((TextFigure) figure).getAutoSizeDimension());
            figure.revalidate();
        }
        return true;
    });
    setPropertyChangeHandler(PROP_ALIGN_H, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setHorizontalAlignment(H_ALIGN.values()[(Integer) newValue]);
        return true;
    });
    setPropertyChangeHandler(PROP_ALIGN_V, (oldValue, newValue, figure) -> {
        ((TextFigure) figure).setVerticalAlignment(V_ALIGN.values()[(Integer) newValue]);
        return true;
    });
    setPropertyChangeHandler(PROP_WRAP_WORDS, (oldValue, newValue, figure) -> {
        AbstractWidgetModel model = getWidgetModel();
        var parent = model.getParent();
        parent.removeChild(model);
        parent.addChild(model);
        parent.selectWidget(model, true);
        return false;
    });
    getWidgetModel().getProperty(PROP_WRAP_WORDS).addPropertyChangeListener(evt -> updatePropertyVisibility());
    setPropertyChangeHandler(PROP_SHOW_SCROLLBAR, (oldValue, newValue, figure) -> {
        if (figure instanceof WrappableTextFigure) {
            ((WrappableTextFigure) figure).setShowScrollbar((Boolean) newValue);
        }
        return false;
    });
}
Also used : WrappableTextFigure(org.csstudio.swt.widgets.figures.WrappableTextFigure) PROP_ALIGN_H(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_ALIGN_H) PROP_TOOLTIP(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_TOOLTIP) AbstractWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractWidgetEditPart) PROP_BORDER_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH) PROP_ACTIONS(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_ACTIONS) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) RequestConstants(org.eclipse.gef.RequestConstants) IFigure(org.eclipse.draw2d.IFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) PROP_ALIGN_V(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_ALIGN_V) Request(org.eclipse.gef.Request) PROP_AUTOSIZE(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_AUTOSIZE) PROP_TEXT(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_TEXT) H_ALIGN(org.csstudio.swt.widgets.figures.TextFigure.H_ALIGN) PROP_WRAP_WORDS(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_WRAP_WORDS) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) LabelModel(org.csstudio.opibuilder.widgets.model.LabelModel) Display(org.eclipse.swt.widgets.Display) PROP_FONT(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_FONT) TextFigure(org.csstudio.swt.widgets.figures.TextFigure) V_ALIGN(org.csstudio.swt.widgets.figures.TextFigure.V_ALIGN) PROP_SHOW_SCROLLBAR(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_SHOW_SCROLLBAR) PROP_TRANSPARENT(org.csstudio.opibuilder.widgets.model.LabelModel.PROP_TRANSPARENT) EditPolicy(org.eclipse.gef.EditPolicy) PROP_BORDER_STYLE(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_STYLE) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) 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)

Example 25 with AbstractWidgetModel

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

the class ActionButtonEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    PropertyChangeListener styleListener = evt -> {
        AbstractWidgetModel model = getWidgetModel();
        var descriptor = WidgetsService.getInstance().getWidgetDescriptor(model.getTypeID());
        var type = descriptor == null ? model.getTypeID().substring(model.getTypeID().lastIndexOf(".") + 1) : descriptor.getName();
        model.setPropertyValue(AbstractWidgetModel.PROP_WIDGET_TYPE, type);
        var parent = model.getParent();
        parent.removeChild(model);
        parent.addChild(model);
        parent.selectWidget(model, true);
    };
    getWidgetModel().getProperty(ActionButtonModel.PROP_STYLE).addPropertyChangeListener(styleListener);
    updatePropSheet();
    delegate.registerPropertyChangeHandlers();
}
Also used : WidgetsService(org.csstudio.opibuilder.util.WidgetsService) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) RequestConstants(org.eclipse.gef.RequestConstants) IFigure(org.eclipse.draw2d.IFigure) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) List(java.util.List) Request(org.eclipse.gef.Request) PropertyChangeListener(java.beans.PropertyChangeListener) AbstractPVWidgetModel(org.csstudio.opibuilder.model.AbstractPVWidgetModel) ActionButtonModel(org.csstudio.opibuilder.widgets.model.ActionButtonModel) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) EditPolicy(org.eclipse.gef.EditPolicy) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertyChangeListener(java.beans.PropertyChangeListener)

Aggregations

AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)50 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)15 ArrayList (java.util.ArrayList)11 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)10 Point (org.eclipse.draw2d.geometry.Point)7 Rectangle (org.eclipse.draw2d.geometry.Rectangle)7 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)7 EditPart (org.eclipse.gef.EditPart)6 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)5 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)5 IFigure (org.eclipse.draw2d.IFigure)5 PropertyChangeListener (java.beans.PropertyChangeListener)4 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)3 ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)3 EditPolicy (org.eclipse.gef.EditPolicy)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 List (java.util.List)2 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)2