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);
}
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);
}
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();
}
Aggregations