use of org.csstudio.opibuilder.commands.WidgetCreateCommand in project yamcs-studio by yamcs.
the class WidgetTreeContainerEditPolicy method createCreateCommand.
protected Command createCreateCommand(AbstractWidgetModel widgetModel, Rectangle r, int index, String label) {
WidgetCreateCommand cmd = new WidgetCreateCommand(widgetModel, (AbstractContainerModel) getHost().getModel(), r, false, true);
cmd.setLabel(label);
cmd.setIndex(index);
return cmd;
}
use of org.csstudio.opibuilder.commands.WidgetCreateCommand in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method getCreateCommand.
@Override
protected Command getCreateCommand(CreateRequest request) {
String typeId = determineTypeIdFromRequest(request);
IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(typeId);
Command widgetCreateCommand = createWidgetCreateCommand(request);
if (widgetCreateCommand == null)
return null;
if (feedbackFactory != null) {
CompoundCommand compoundCommand = new CompoundCommand();
compoundCommand.add(widgetCreateCommand);
Command initialBoundsCommand = feedbackFactory.createInitialBoundsCommand((AbstractWidgetModel) request.getNewObject(), request, (Rectangle) getConstraintFor(request));
if (initialBoundsCommand != null)
compoundCommand.add(initialBoundsCommand);
return compoundCommand;
} else
return widgetCreateCommand;
}
use of org.csstudio.opibuilder.commands.WidgetCreateCommand in project yamcs-studio by yamcs.
the class ArrayLayoutEditPolicy method createWidgetCreateCommand.
@Override
protected Command createWidgetCreateCommand(CreateRequest request) {
AbstractContainerModel container = (AbstractContainerModel) getHost().getModel();
if (!container.getChildren().isEmpty())
return null;
CompoundCommand result = new CompoundCommand("Create widget in array");
Dimension size = ((Rectangle) getConstraintFor(request)).getSize();
AbstractWidgetModel widget = (AbstractWidgetModel) request.getNewObject();
if (size == null || size.width < 1 || size.height < 1)
size = widget.getSize();
addUpdateContainerCommands(container, size, result);
WidgetCreateCommand widgetCreateCommand = new WidgetCreateCommand(widget, container, (Rectangle) getConstraintFor(request), false, true);
result.add(widgetCreateCommand);
return result;
}
use of org.csstudio.opibuilder.commands.WidgetCreateCommand in project yamcs-studio by yamcs.
the class CreateGroupAction method run.
@Override
public void run(IAction action) {
var originalSelectedWidgets = getSelectedWidgetModels();
var compoundCommand = new CompoundCommand("Create Group");
List<AbstractWidgetModel> selectedWidgets = new ArrayList<>();
selectedWidgets.addAll(originalSelectedWidgets);
// remove the selected widgets which are children of another selected widget.
for (var widget : originalSelectedWidgets) {
if (widget instanceof DisplayModel) {
selectedWidgets.remove(widget);
continue;
}
if (widget instanceof AbstractContainerModel) {
for (var child : originalSelectedWidgets) {
if (((AbstractContainerModel) widget).getChildren().contains(child)) {
selectedWidgets.remove(child);
}
}
}
}
var minDepth = Integer.MAX_VALUE;
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
var minDepthWidget = selectedWidgets.get(0);
for (var widget : selectedWidgets) {
var leftX = widget.getLocation().x;
var upY = widget.getLocation().y;
var rightX = widget.getLocation().x + widget.getSize().width;
var bottomY = widget.getLocation().y + widget.getSize().height;
var 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.
var widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
for (var i = widgetsArray.length - 1; i >= 0; i--) {
compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
}
var groupingContainerModel = new GroupingContainerModel();
SchemaService.getInstance().applySchema(groupingContainerModel);
// the parent should be the widget with minimum nested depth
var parent = minDepthWidget.getParent();
var 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 (var 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.WidgetCreateCommand in project yamcs-studio by yamcs.
the class PasteWidgetsAction method createPasteCommand.
/**
* Creates the paste command.
*
* @return Command The paste command
*/
public Command createPasteCommand() {
var targetModel = getTargetContainerModel();
var widgets = getWidgetsFromClipboard();
if (widgets != null) {
if (_cursorLocation == null) {
fetchCurrentCursorLocation();
}
var cursorControl = Display.getCurrent().getCursorControl();
Point pastePoint;
if (isCursorAboveTargetContainer(cursorControl, targetModel)) {
pastePoint = getCursorRelativePositionToTargetContainer(getCursorLocationOnDisplay(cursorControl), targetModel);
// move the cursor location so that the user could know he has pasted how many widgets.
Display.getCurrent().setCursorLocation(_cursorLocation.x + 10, _cursorLocation.y + 10);
} else {
var rand = new Random();
pastePoint = new Point(rand.nextInt(20), rand.nextInt(20));
}
var intrinsicLocations = getWidgetsIntrinsicRelativePositions(widgets);
var cmd = new CompoundCommand("Paste " + widgets.size() + " Widget" + (widgets.size() > 0 ? "s" : ""));
var i = 0;
for (var widgetModel : widgets) {
// create command
cmd.add(new WidgetCreateCommand(widgetModel, targetModel, new Rectangle(intrinsicLocations.get(i).translate(pastePoint), widgetModel.getSize()), (i == 0 ? false : true)));
i++;
}
_cursorLocation = null;
return cmd;
}
return null;
}
Aggregations