Search in sources :

Example 1 with OrphanChildCommand

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

the class CreateGroupAction method run.

@Override
public void run(IAction action) {
    List<AbstractWidgetModel> originalSelectedWidgets = getSelectedWidgetModels();
    CompoundCommand compoundCommand = new CompoundCommand("Create Group");
    List<AbstractWidgetModel> selectedWidgets = new ArrayList<AbstractWidgetModel>();
    selectedWidgets.addAll(originalSelectedWidgets);
    // remove the selected widgets which are children of another selected widget.
    for (AbstractWidgetModel widget : originalSelectedWidgets) {
        if (widget instanceof DisplayModel) {
            selectedWidgets.remove(widget);
            continue;
        }
        if (widget instanceof AbstractContainerModel) {
            for (AbstractWidgetModel child : originalSelectedWidgets) {
                if (((AbstractContainerModel) widget).getChildren().contains(child))
                    selectedWidgets.remove(child);
            }
        }
    }
    int minDepth = Integer.MAX_VALUE;
    int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
    AbstractWidgetModel minDepthWidget = selectedWidgets.get(0);
    for (AbstractWidgetModel widget : selectedWidgets) {
        int leftX = widget.getLocation().x;
        int upY = widget.getLocation().y;
        int rightX = widget.getLocation().x + widget.getSize().width;
        int bottomY = widget.getLocation().y + widget.getSize().height;
        int depth = widget.getNestedDepth();
        if (leftX < minX)
            minX = leftX;
        if (upY < minY)
            minY = upY;
        if (rightX > maxX)
            maxX = rightX;
        if (bottomY > maxY)
            maxY = bottomY;
        if (minDepth > depth) {
            minDepth = depth;
            minDepthWidget = widget;
        }
    }
    // Orphan order should be reversed so that undo operation has the correct order.
    AbstractWidgetModel[] widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
    for (int i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
    }
    GroupingContainerModel groupingContainerModel = new GroupingContainerModel();
    SchemaService.getInstance().applySchema(groupingContainerModel);
    // the parent should be the widget with minimum nested depth
    AbstractContainerModel parent = minDepthWidget.getParent();
    int borderWidth = 0;
    if (groupingContainerModel.getBorderStyle() == BorderStyle.GROUP_BOX)
        borderWidth = 30;
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN, true);
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_SHOW_SCROLLBAR, false);
    compoundCommand.add(new WidgetCreateCommand(groupingContainerModel, parent, new Rectangle(minX, minY, maxX - minX + borderWidth, maxY - minY + borderWidth), false));
    for (AbstractWidgetModel widget : selectedWidgets) {
        compoundCommand.add(new AddWidgetCommand(groupingContainerModel, widget, new Rectangle(widget.getLocation().translate(-minX, -minY), widget.getSize())));
    }
    execute(compoundCommand);
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand)

Example 2 with OrphanChildCommand

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

the class RemoveGroupAction method run.

@Override
public void run(IAction action) {
    CompoundCommand compoundCommand = new CompoundCommand("Remove Group");
    GroupingContainerModel containerModel = getSelectedContainer();
    // Orphan order should be reversed so that undo operation has the correct order.
    AbstractWidgetModel[] widgetsArray = containerModel.getChildren().toArray(new AbstractWidgetModel[containerModel.getChildren().size()]);
    for (int i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(containerModel, widgetsArray[i]));
    }
    Point leftCorner = containerModel.getLocation();
    for (AbstractWidgetModel widget : containerModel.getChildren()) {
        compoundCommand.add(new AddWidgetCommand(containerModel.getParent(), widget, new Rectangle(widget.getLocation(), widget.getSize()).translate(leftCorner)));
    }
    compoundCommand.add(new WidgetDeleteCommand(containerModel.getParent(), containerModel));
    execute(compoundCommand);
}
Also used : GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) WidgetDeleteCommand(org.csstudio.opibuilder.commands.WidgetDeleteCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 3 with OrphanChildCommand

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

the class WidgetContainerEditPolicy method getOrphanChildrenCommand.

@Override
protected Command getOrphanChildrenCommand(GroupRequest request) {
    @SuppressWarnings("rawtypes") List parts = request.getEditParts();
    CompoundCommand result = new CompoundCommand("Orphan Children");
    for (int i = 0; i < parts.size(); i++) {
        OrphanChildCommand orphan = new OrphanChildCommand((AbstractContainerModel) (getHost().getModel()), (AbstractWidgetModel) ((EditPart) parts.get(i)).getModel());
        orphan.setLabel("Reparenting widget");
        result.add(orphan);
    }
    return result.unwrap();
}
Also used : EditPart(org.eclipse.gef.EditPart) List(java.util.List) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

OrphanChildCommand (org.csstudio.opibuilder.commands.OrphanChildCommand)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)2 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)2 GroupingContainerModel (org.csstudio.opibuilder.widgets.model.GroupingContainerModel)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)1 WidgetDeleteCommand (org.csstudio.opibuilder.commands.WidgetDeleteCommand)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1 Point (org.eclipse.draw2d.geometry.Point)1 EditPart (org.eclipse.gef.EditPart)1