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