Search in sources :

Example 91 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand 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);
    }
    var container = (AbstractContainerModel) getHost().getModel();
    var widget = (AbstractWidgetModel) child.getModel();
    var result = new CompoundCommand("Adding widgets to container");
    result.add(new AddWidgetCommand(container, widget, (Rectangle) constraint));
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 92 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class DropPVtoContainerEditPolicy method getCommand.

@Override
public Command getCommand(Request request) {
    if (request.getType() == DropPVRequest.REQ_DROP_PV && request instanceof DropPVRequest) {
        var dropPVRequest = (DropPVRequest) request;
        if (dropPVRequest.getTargetWidget() != null && dropPVRequest.getTargetWidget() instanceof AbstractContainerEditpart) {
            var dialog = new WidgetsSelectDialog(getHost().getViewer().getControl().getShell(), dropPVRequest.getPvNames().length, true);
            if (dialog.open() == Window.OK) {
                var typeID = dialog.getOutput();
                var command = new CompoundCommand("Create Widget");
                var pvNames = dropPVRequest.getPvNames();
                var location = dropPVRequest.getLocation().getCopy();
                var container = ((AbstractContainerEditpart) dropPVRequest.getTargetWidget()).getWidgetModel();
                var parent = container.getParent();
                var temp = container;
                while (parent != null) {
                    location.translate(temp.getLocation().getNegated());
                    temp = parent;
                    parent = parent.getParent();
                }
                var i = 1;
                int lastWidth = 0, lastHeight = 0;
                for (var pvName : pvNames) {
                    var widgetModel = WidgetsService.getInstance().getWidgetDescriptor(typeID).getWidgetModel();
                    command.add(new WidgetCreateCommand(widgetModel, container, new Rectangle(location.getCopy().translate(lastWidth, lastHeight), new Dimension(-1, -1)), i != 1, true));
                    command.add(new SetWidgetPropertyCommand(widgetModel, AbstractPVWidgetModel.PROP_PVNAME, pvName.trim()));
                    if (i % WIDGETS_ACCOUNT_ON_A_ROW == 0) {
                        lastWidth = 0;
                        lastHeight += widgetModel.getHeight();
                    } else {
                        lastWidth += widgetModel.getWidth();
                    }
                    i++;
                }
                return command;
            }
        }
    }
    return null;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) WidgetsSelectDialog(org.csstudio.opibuilder.visualparts.WidgetsSelectDialog) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand)

Example 93 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class CloneCommand method execute.

@Override
public void execute() {
    var clipboard = new Clipboard(Display.getCurrent());
    var tempModel = new DisplayModel();
    for (var widget : _models) {
        tempModel.addChild(widget, false);
    }
    var xml = XMLUtil.widgetToXMLString(tempModel, false);
    clipboard.setContents(new Object[] { xml }, new Transfer[] { OPIWidgetsTransfer.getInstance() });
    _clonedWidgets = getWidgetsFromClipboard();
    _compoundCommand = new CompoundCommand();
    var i = 0;
    for (var widgetModel : _clonedWidgets) {
        if (_difference != null) {
            widgetModel.setLocation((widgetModel.getLocation().x + _difference.width), (widgetModel.getLocation().y + _difference.height));
        } else {
            widgetModel.setLocation((widgetModel.getLocation().x + 10), (widgetModel.getLocation().y + 10));
        }
        _compoundCommand.add(new WidgetCreateCommand(widgetModel, _parent, new Rectangle(widgetModel.getLocation(), widgetModel.getSize()), (i++ == 0 ? false : true)));
        if (_hGuide != null) {
            var hGuideCommand = new ChangeGuideCommand(widgetModel, true);
            hGuideCommand.setNewGuide(_hGuide, _hAlignment);
            _compoundCommand.add(hGuideCommand);
        }
        if (_vGuide != null) {
            var vGuideCommand = new ChangeGuideCommand(widgetModel, false);
            vGuideCommand.setNewGuide(_vGuide, _vAlignment);
            _compoundCommand.add(vGuideCommand);
        }
    }
    _compoundCommand.execute();
}
Also used : DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Clipboard(org.eclipse.swt.dnd.Clipboard) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 94 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class ChangeOrderAction method run.

@Override
public void run() {
    Map<AbstractContainerModel, List<IndexedWidget>> widgetMap = new HashMap<>();
    fillWidgetMap(widgetMap);
    var compoundCommand = new CompoundCommand(orderType.getLabel());
    // create compound command
    for (var entry : widgetMap.entrySet()) {
        // sort the list in map by the widget's original order in its container
        var container = entry.getKey();
        var widgetList = entry.getValue();
        Collections.sort(widgetList);
        int newIndex;
        switch(orderType) {
            case TO_FRONT:
                newIndex = container.getChildren().size() - 1;
                break;
            case STEP_FRONT:
                newIndex = widgetList.get(widgetList.size() - 1).getIndex() + 1;
                break;
            case STEP_BACK:
                newIndex = widgetList.get(0).getIndex() - 1;
                break;
            case TO_BACK:
            default:
                newIndex = 0;
                break;
        }
        // reorder
        switch(orderType) {
            case TO_FRONT:
            case STEP_FRONT:
                for (var indexedWidget : widgetList) {
                    compoundCommand.add(new ChangeOrderCommand(newIndex, container, indexedWidget.getWidget()));
                }
                break;
            case STEP_BACK:
            case TO_BACK:
                for (var i = widgetList.size() - 1; i >= 0; i--) {
                    compoundCommand.add(new ChangeOrderCommand(newIndex, container, widgetList.get(i).getWidget()));
                }
                break;
            default:
                break;
        }
    }
    execute(compoundCommand);
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) HashMap(java.util.HashMap) ChangeOrderCommand(org.csstudio.opibuilder.commands.ChangeOrderCommand) List(java.util.List) LinkedList(java.util.LinkedList) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 95 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class ChangeOrientationAction method run.

@Override
public void run() {
    var compoundCommand = new CompoundCommand(orientationType.getLabel());
    for (var widgetModel : getSelectedWidgetModels()) {
        compoundCommand.add(new ChangeOrientationCommand(widgetModel, orientationType));
    }
    execute(compoundCommand);
}
Also used : ChangeOrientationCommand(org.csstudio.opibuilder.commands.ChangeOrientationCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

CompoundCommand (org.eclipse.gef.commands.CompoundCommand)193 Command (org.eclipse.gef.commands.Command)86 EObject (org.eclipse.emf.ecore.EObject)40 ArrayList (java.util.ArrayList)28 EditPart (org.eclipse.gef.EditPart)28 List (java.util.List)24 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)23 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)18 Point (org.eclipse.draw2d.geometry.Point)16 IElementParameter (org.talend.core.model.process.IElementParameter)16 Combo (org.eclipse.swt.widgets.Combo)15 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)14 Rectangle (org.eclipse.draw2d.geometry.Rectangle)14 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)14 INode (org.talend.core.model.process.INode)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14