Search in sources :

Example 1 with ReconnectDiagramConnectionCommand

use of com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand in project archi by archimatetool.

the class ArchimateDiagramConnectionPolicy method getReconnectCommand.

/**
 * Create a ReconnectCommand
 */
protected Command getReconnectCommand(ReconnectRequest request, boolean isSourceCommand) {
    IDiagramModelConnection connection = (IDiagramModelConnection) request.getConnectionEditPart().getModel();
    // The re-connected object
    IConnectable newObject = (IConnectable) getHost().getModel();
    // Get the type of connection (plain) or relationship (if archimate connection) and check if it is valid
    EClass type = connection.eClass();
    if (connection instanceof IDiagramModelArchimateConnection) {
        type = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship().eClass();
    }
    if (isSourceCommand) {
        if (!isValidConnection(newObject, connection.getTarget(), type)) {
            return null;
        }
    } else {
        if (!isValidConnection(connection.getSource(), newObject, type)) {
            return null;
        }
    }
    /*
         * Re-connect ArchiMate Connection to Archimate Component
         * In this case we have to check for matching occurences on all diagrams
         */
    if (connection instanceof IDiagramModelArchimateConnection && newObject instanceof IDiagramModelArchimateComponent) {
        IArchimateRelationship relationship = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
        IArchimateConcept newConcept = ((IDiagramModelArchimateComponent) newObject).getArchimateConcept();
        // Compound Command
        CompoundCommand result = new CompoundCommand();
        // Check for matching connections in this and other diagrams
        for (IDiagramModel diagramModel : newConcept.getArchimateModel().getDiagramModels()) {
            for (IDiagramModelArchimateConnection matchingConnection : DiagramModelUtils.findDiagramModelConnectionsForRelation(diagramModel, relationship)) {
                IDiagramModelArchimateComponent matchingComponent = null;
                // Same Diagram so use the new target
                if (newObject.getDiagramModel() == diagramModel) {
                    matchingComponent = (IDiagramModelArchimateComponent) newObject;
                } else // Different Diagram so find a match
                {
                    List<IDiagramModelArchimateComponent> list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, newConcept);
                    if (!list.isEmpty()) {
                        matchingComponent = list.get(0);
                    }
                }
                // Does the new object exist on the diagram? Yes, reconnect
                if (matchingComponent != null) {
                    ReconnectDiagramConnectionCommand cmd = new ReconnectDiagramConnectionCommand(matchingConnection);
                    if (isSourceCommand) {
                        cmd.setNewSource(matchingComponent);
                    } else {
                        cmd.setNewTarget(matchingComponent);
                    }
                    result.add(cmd);
                } else // No, so delete the matching connection
                {
                    result.add(DiagramCommandFactory.createDeleteDiagramConnectionCommand(matchingConnection));
                }
            }
        }
        return result.unwrap();
    } else // Re-connect other cases
    {
        ReconnectDiagramConnectionCommand cmd = new ReconnectDiagramConnectionCommand(connection);
        if (isSourceCommand) {
            cmd.setNewSource(newObject);
        } else {
            cmd.setNewTarget(newObject);
        }
        return cmd;
    }
}
Also used : IConnectable(com.archimatetool.model.IConnectable) EClass(org.eclipse.emf.ecore.EClass) ReconnectDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with ReconnectDiagramConnectionCommand

use of com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand in project archi by archimatetool.

the class BasicConnectionPolicy method getReconnectSourceCommand.

@Override
protected Command getReconnectSourceCommand(ReconnectRequest request) {
    ReconnectDiagramConnectionCommand cmd = null;
    IDiagramModelConnection connection = (IDiagramModelConnection) request.getConnectionEditPart().getModel();
    IDiagramModelObject newSource = (IDiagramModelObject) getHost().getModel();
    if (isValidConnectionSource(newSource, connection.eClass())) {
        cmd = new ReconnectDiagramConnectionCommand(connection);
        cmd.setNewSource(newSource);
    }
    return cmd;
}
Also used : ReconnectDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject)

Example 3 with ReconnectDiagramConnectionCommand

use of com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand in project archi by archimatetool.

the class BasicConnectionPolicy method getReconnectTargetCommand.

@Override
protected Command getReconnectTargetCommand(ReconnectRequest request) {
    ReconnectDiagramConnectionCommand cmd = null;
    IDiagramModelConnection connection = (IDiagramModelConnection) request.getConnectionEditPart().getModel();
    IDiagramModelObject newTarget = (IDiagramModelObject) getHost().getModel();
    if (isValidConnectionTarget(newTarget, connection.eClass())) {
        cmd = new ReconnectDiagramConnectionCommand(connection);
        cmd.setNewTarget(newTarget);
    }
    return cmd;
}
Also used : ReconnectDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject)

Aggregations

ReconnectDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand)3 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)3 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)1 IConnectable (com.archimatetool.model.IConnectable)1 IDiagramModel (com.archimatetool.model.IDiagramModel)1 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)1 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)1 EClass (org.eclipse.emf.ecore.EClass)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1