Search in sources :

Example 46 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project whole by wholeplatform.

the class WholeDragEditPartsTracker method getCommand.

protected Command getCommand() {
    if (!isShareActive())
        return super.getCommand();
    CompoundCommand command = new CompoundCommand();
    // $NON-NLS-1$
    command.setDebugLabel("Drag Object Tracker");
    Request request = getTargetRequest();
    request.setType(REQ_SHARE);
    if (!isMove()) {
        if (getTargetEditPart() == null)
            command.add(UnexecutableCommand.INSTANCE);
        else
            command.add(getTargetEditPart().getCommand(getTargetRequest()));
    }
    return command;
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Request(org.eclipse.gef.Request) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 47 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class DiagramEditorFindReplaceProvider method doReplaceStringCommands.

void doReplaceStringCommands(List<EditPart> editParts, List<String> newTexts) {
    // Must match sizes
    if (editParts.size() != newTexts.size() || editParts.isEmpty()) {
        return;
    }
    CommandStack stack = (CommandStack) ((IAdapter) editParts.get(0).getModel()).getAdapter(CommandStack.class);
    if (stack == null) {
        return;
    }
    CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(Messages.DiagramEditorFindReplaceProvider_0);
    for (int i = 0; i < editParts.size(); i++) {
        EditPart editPart = editParts.get(i);
        String newText = newTexts.get(i);
        Command command = createCommand(editPart, newText);
        if (command != null) {
            compoundCommand.add(command);
        }
    }
    stack.execute(compoundCommand.unwrap());
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)

Example 48 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class DeleteFromModelAction method run.

@Override
public void run() {
    List<?> selection = getSelectedObjects();
    Set<IArchimateConcept> archimateConcepts = new HashSet<IArchimateConcept>();
    // Gather referenced model concepts
    for (Object object : selection) {
        if (object instanceof EditPart) {
            Object model = ((EditPart) object).getModel();
            if (model instanceof IDiagramModelArchimateObject) {
                IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
                archimateConcepts.add(element);
                // Element's relationships
                for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
                    archimateConcepts.add(relation);
                    // Relation's relationships
                    for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                        archimateConcepts.add(r);
                    }
                }
            } else if (model instanceof IDiagramModelArchimateConnection) {
                IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
                archimateConcepts.add(relation);
                // Relation's relationships
                for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                    archimateConcepts.add(r);
                }
            }
        }
    }
    // Check whether any of these concepts are referenced in other diagrams
    if (hasMoreThanOneReference(archimateConcepts)) {
        if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteFromModelAction_0, Messages.DeleteFromModelAction_1 + // $NON-NLS-1$
        "\n\n" + Messages.DeleteFromModelAction_2)) {
            return;
        }
    }
    // Create commands
    CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT);
    for (IArchimateConcept archimateConcept : archimateConcepts) {
        if (archimateConcept instanceof IArchimateElement) {
            // Element
            Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
            compoundCommand.add(cmd);
            // Diagram Model Objects
            for (IDiagramModelObject dmo : ((IArchimateElement) archimateConcept).getReferencingDiagramObjects()) {
                cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand(dmo);
                compoundCommand.add(cmd);
            }
        } else if (archimateConcept instanceof IArchimateRelationship) {
            // Relationship
            Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
            compoundCommand.add(cmd);
            // Diagram Model Connections
            for (IDiagramModelArchimateConnection dmc : ((IArchimateRelationship) archimateConcept).getReferencingDiagramConnections()) {
                cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(dmc);
                compoundCommand.add(cmd);
            }
        }
    }
    BusyIndicator.showWhile(null, new Runnable() {

        @Override
        public void run() {
            execute(compoundCommand);
        }
    });
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) EditPart(org.eclipse.gef.EditPart) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) Command(org.eclipse.gef.commands.Command) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) HashSet(java.util.HashSet)

Example 49 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class BringForwardAction method createCommand.

private Command createCommand(List<?> selection) {
    GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
    CompoundCommand result = new CompoundCommand(Messages.BringForwardAction_0);
    for (Object object : selection) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart editPart = (GraphicalEditPart) object;
            Object model = editPart.getModel();
            // This can happen if we do things wrong
            if (viewer != editPart.getViewer()) {
                // $NON-NLS-1$
                System.err.println("Wrong selection for viewer in " + getClass());
            }
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            if (model instanceof IDiagramModelObject) {
                IDiagramModelObject diagramObject = (IDiagramModelObject) model;
                IDiagramModelContainer parent = (IDiagramModelContainer) diagramObject.eContainer();
                /*
                     * Parent can be null when objects are selected (with marquee tool) and transferred from one container
                     * to another and the Diagram Editor updates the enablement state of Actions.
                     */
                if (parent == null) {
                    continue;
                }
                List<IDiagramModelObject> modelChildren = parent.getChildren();
                int originalPos = modelChildren.indexOf(diagramObject);
                if (originalPos < modelChildren.size() - 1) {
                    result.add(new BringForwardCommand(parent, originalPos));
                }
            }
        }
    }
    return result.unwrap();
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Example 50 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class CreateDiagramConnectionCommand method createBendPointsForCircularConnectionCommand.

/**
 * Create a Command for adding bendpoints to a circular connection
 * So it looks good
 */
public static Command createBendPointsForCircularConnectionCommand(IDiagramModelConnection connection) {
    // Only works for IDiagramModelObject as source and target objects not for connections
    if (!(connection.getSource() instanceof IDiagramModelObject) && !(connection.getTarget() instanceof IDiagramModelObject)) {
        return null;
    }
    IDiagramModelObject source = (IDiagramModelObject) connection.getSource();
    IDiagramModelObject target = (IDiagramModelObject) connection.getTarget();
    int width = source.getBounds().getWidth();
    if (width == -1) {
        width = 100;
    }
    int height = target.getBounds().getHeight();
    if (height == -1) {
        height = 60;
    }
    width = (int) Math.max(100, width * 0.6);
    height = (int) Math.max(60, height * 0.6);
    CompoundCommand result = new CompoundCommand();
    CreateBendpointCommand cmd = new CreateBendpointCommand();
    cmd.setDiagramModelConnection(connection);
    cmd.setRelativeDimensions(new Dimension(width, 0), new Dimension(width, 0));
    result.add(cmd);
    cmd = new CreateBendpointCommand();
    cmd.setDiagramModelConnection(connection);
    cmd.setRelativeDimensions(new Dimension(width, height), new Dimension(width, height));
    result.add(cmd);
    cmd = new CreateBendpointCommand();
    cmd.setDiagramModelConnection(connection);
    cmd.setRelativeDimensions(new Dimension(0, height), new Dimension(0, height));
    result.add(cmd);
    return result;
}
Also used : IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) 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