Search in sources :

Example 1 with WidgetCreateCommand

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;
}
Also used : WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand)

Example 2 with WidgetCreateCommand

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;
}
Also used : WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) CloneCommand(org.csstudio.opibuilder.commands.CloneCommand) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 3 with 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;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand)

Example 4 with WidgetCreateCommand

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);
}
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 5 with WidgetCreateCommand

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;
}
Also used : Random(java.util.Random) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand)

Aggregations

WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)5 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)2 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)2 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ChangeGuideCommand (org.csstudio.opibuilder.commands.ChangeGuideCommand)1 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)1 OrphanChildCommand (org.csstudio.opibuilder.commands.OrphanChildCommand)1 WidgetSetConstraintCommand (org.csstudio.opibuilder.commands.WidgetSetConstraintCommand)1 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)1 IGraphicalFeedbackFactory (org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1 WidgetsSelectDialog (org.csstudio.opibuilder.visualparts.WidgetsSelectDialog)1 GroupingContainerModel (org.csstudio.opibuilder.widgets.model.GroupingContainerModel)1 Point (org.eclipse.draw2d.geometry.Point)1