Search in sources :

Example 1 with GroupingContainerEditPart

use of org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart in project yamcs-studio by yamcs.

the class PerformAutoSizeAction method run.

@Override
public void run(IAction action) {
    if (getContainerEditpart().getChildren().size() <= 0) {
        return;
    }
    var compoundCommand = new CompoundCommand("Perform AutoSize");
    var containerEditpart = getContainerEditpart();
    var 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));
    }
    var figure = getContainerFigure();
    var childrenRange = GeometryUtil.getChildrenRange(containerEditpart);
    var 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 (var editpart : containerEditpart.getChildren()) {
        var widget = ((AbstractBaseEditPart) editpart).getWidgetModel();
        compoundCommand.add(new SetBoundsCommand(widget, new Rectangle(widget.getLocation().translate(tranlateSize.getNegated()), widget.getSize())));
    }
    // recover lock
    if (containerEditpart instanceof GroupingContainerEditPart) {
        var oldvalue = containerEditpart.getWidgetModel().getPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN);
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, oldvalue));
    }
    execute(compoundCommand);
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) 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)

Example 2 with GroupingContainerEditPart

use of org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart in project yamcs-studio by yamcs.

the class LockUnlockChildrenHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    GraphicalViewer viewer = HandlerUtil.getActivePart(event).getAdapter(GraphicalViewer.class);
    if (viewer == null)
        return null;
    ISelection currentSelection = viewer.getSelection();
    if (currentSelection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) currentSelection).getFirstElement();
        if (element instanceof GroupingContainerEditPart) {
            CommandStack commandStack = HandlerUtil.getActivePart(event).getAdapter(CommandStack.class);
            if (commandStack != null)
                commandStack.execute(LockUnlockChildrenAction.createLockUnlockCommand(((GroupingContainerEditPart) element).getWidgetModel()));
        }
    }
    return null;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) GraphicalViewer(org.eclipse.gef.GraphicalViewer) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GroupingContainerEditPart(org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart)

Aggregations

GroupingContainerEditPart (org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart)2 SetBoundsCommand (org.csstudio.opibuilder.commands.SetBoundsCommand)1 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Point (org.eclipse.draw2d.geometry.Point)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1