Search in sources :

Example 1 with AddWidgetCommand

use of org.csstudio.opibuilder.commands.AddWidgetCommand 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 AddWidgetCommand

use of org.csstudio.opibuilder.commands.AddWidgetCommand 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 AddWidgetCommand

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

the class ArrayLayoutEditPolicy method createAddCommand.

@Override
protected Command createAddCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
    if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
        return super.createAddCommand(request, child, constraint);
    AbstractContainerModel container = (AbstractContainerModel) getHost().getModel();
    if (!container.getChildren().isEmpty())
        return null;
    AbstractWidgetModel widget = (AbstractWidgetModel) child.getModel();
    CompoundCommand result = new CompoundCommand("Add widget to array");
    addUpdateContainerCommands(container, widget.getSize(), result);
    result.add(new AddWidgetCommand(container, widget, (Rectangle) constraint));
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 4 with AddWidgetCommand

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

the class WidgetXYLayoutEditPolicy method createAddCommand.

@SuppressWarnings("deprecation")
@Override
protected Command createAddCommand(EditPart child, Object constraint) {
    if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
        return super.createAddCommand(child, constraint);
    AbstractContainerModel container = (AbstractContainerModel) getHost().getModel();
    AbstractWidgetModel widget = (AbstractWidgetModel) child.getModel();
    CompoundCommand result = new CompoundCommand("Adding widgets to container");
    result.add(new AddWidgetCommand(container, widget, (Rectangle) constraint));
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

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