Search in sources :

Example 1 with WidgetDeleteCommand

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

the class WidgetComponentEditPolicy method createDeleteCommand.

@Override
protected Command createDeleteCommand(GroupRequest deleteRequest) {
    Object containerModel = getHost().getParent().getModel();
    Object widget = getHost().getModel();
    if (containerModel instanceof AbstractContainerModel && widget instanceof AbstractWidgetModel)
        return new WidgetDeleteCommand((AbstractContainerModel) containerModel, (AbstractWidgetModel) widget);
    return super.createDeleteCommand(deleteRequest);
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) WidgetDeleteCommand(org.csstudio.opibuilder.commands.WidgetDeleteCommand)

Example 2 with WidgetDeleteCommand

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

the class RemoveGroupAction method run.

@Override
public void run(IAction action) {
    var compoundCommand = new CompoundCommand("Remove Group");
    var containerModel = getSelectedContainer();
    // Orphan order should be reversed so that undo operation has the correct order.
    var widgetsArray = containerModel.getChildren().toArray(new AbstractWidgetModel[containerModel.getChildren().size()]);
    for (var i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(containerModel, widgetsArray[i]));
    }
    var leftCorner = containerModel.getLocation();
    for (var 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 : WidgetDeleteCommand(org.csstudio.opibuilder.commands.WidgetDeleteCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

WidgetDeleteCommand (org.csstudio.opibuilder.commands.WidgetDeleteCommand)2 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)1 OrphanChildCommand (org.csstudio.opibuilder.commands.OrphanChildCommand)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1