Search in sources :

Example 1 with SetBoundsCommand

use of org.csstudio.opibuilder.commands.SetBoundsCommand in project yamcs-studio by yamcs.

the class FillParentContainerAction method run.

@Override
public void run(IAction action) {
    AbstractBaseEditPart widget = (AbstractBaseEditPart) selection.getFirstElement();
    AbstractContainerEditpart containerEditpart = getParentContainerEditpart();
    Dimension size = null;
    if (containerEditpart instanceof DisplayEditpart)
        size = ((DisplayEditpart) containerEditpart).getWidgetModel().getSize();
    else
        size = containerEditpart.getFigure().getClientArea().getSize();
    Command cmd = new SetBoundsCommand(widget.getWidgetModel(), new Rectangle(0, 0, size.width, size.height));
    execute(cmd);
}
Also used : AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Command(org.eclipse.gef.commands.Command) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Dimension(org.eclipse.draw2d.geometry.Dimension) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Example 2 with SetBoundsCommand

use of org.csstudio.opibuilder.commands.SetBoundsCommand in project yamcs-studio by yamcs.

the class LayoutWidgetsImp method run.

public static void run(AbstractLayoutEditpart layoutWidget, CommandStack commandStack) {
    AbstractContainerModel container = layoutWidget.getWidgetModel().getParent();
    List<AbstractWidgetModel> modelChildren = new ArrayList<AbstractWidgetModel>();
    modelChildren.addAll(container.getChildren());
    modelChildren.remove(layoutWidget.getWidgetModel());
    if (modelChildren.size() == 0)
        return;
    List<Rectangle> newBounds = layoutWidget.getNewBounds(modelChildren, container.getBounds());
    CompoundCommand compoundCommand = new CompoundCommand("Layout Widgets");
    int i = 0;
    for (AbstractWidgetModel model : modelChildren) {
        compoundCommand.add(new SetBoundsCommand(model, newBounds.get(i)));
        i++;
    }
    commandStack.execute(compoundCommand);
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 3 with SetBoundsCommand

use of org.csstudio.opibuilder.commands.SetBoundsCommand in project yamcs-studio by yamcs.

the class PerformAutoSizeAction method run.

@Override
public void run(IAction action) {
    if (getContainerEditpart().getChildren().size() <= 0) {
        return;
    }
    CompoundCommand compoundCommand = new CompoundCommand("Perform AutoSize");
    AbstractContainerEditpart containerEditpart = getContainerEditpart();
    AbstractContainerModel containerModel = containerEditpart.getWidgetModel();
    // temporary unlock children so children will not be resized.
    if (containerEditpart instanceof GroupingContainerEditPart) {
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, false));
    }
    IFigure figure = getContainerFigure();
    Rectangle childrenRange = GeometryUtil.getChildrenRange(containerEditpart);
    Point tranlateSize = new Point(childrenRange.x, childrenRange.y);
    compoundCommand.add(new SetBoundsCommand(containerModel, new Rectangle(containerModel.getLocation().translate(tranlateSize), new Dimension(childrenRange.width + figure.getInsets().left + figure.getInsets().right, childrenRange.height + figure.getInsets().top + figure.getInsets().bottom))));
    for (Object editpart : containerEditpart.getChildren()) {
        AbstractWidgetModel widget = ((AbstractBaseEditPart) editpart).getWidgetModel();
        compoundCommand.add(new SetBoundsCommand(widget, new Rectangle(widget.getLocation().translate(tranlateSize.getNegated()), widget.getSize())));
    }
    // recover lock
    if (containerEditpart instanceof GroupingContainerEditPart) {
        Object oldvalue = containerEditpart.getWidgetModel().getPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN);
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, oldvalue));
    }
    execute(compoundCommand);
}
Also used : AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GroupingContainerEditPart(org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

SetBoundsCommand (org.csstudio.opibuilder.commands.SetBoundsCommand)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)2 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)2 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)2 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 ArrayList (java.util.ArrayList)1 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)1 GroupingContainerEditPart (org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart)1 IFigure (org.eclipse.draw2d.IFigure)1 Point (org.eclipse.draw2d.geometry.Point)1 Command (org.eclipse.gef.commands.Command)1