Search in sources :

Example 6 with IDiagramModelArchimateComponent

use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.

the class ArchimateDiagramConnectionPolicy method isValidConnection.

/**
 * @param source
 * @param target
 * @param relationshipType
 * @return True if valid connection source/target for connection type
 */
static boolean isValidConnection(IConnectable source, IConnectable target, EClass relationshipType) {
    /*
         * Diagram Connection from/to notes/groups/diagram refs.
         * Allowed between notes, visual groups, diagram refs and ArchiMate components
         */
    if (relationshipType == IArchimatePackage.eINSTANCE.getDiagramModelConnection()) {
        // Not circular
        if (source == target) {
            return false;
        }
        // Notes
        if (source instanceof IDiagramModelNote || target instanceof IDiagramModelNote) {
            return true;
        }
        // Groups
        if (source instanceof IDiagramModelGroup || target instanceof IDiagramModelGroup) {
            return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
        }
        // Diagram Refs
        if (source instanceof IDiagramModelReference || target instanceof IDiagramModelReference) {
            return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
        }
        return false;
    }
    // Connection from Archimate concept to Archimate concept (but not from relation to relation)
    if ((source instanceof IDiagramModelArchimateComponent && target instanceof IDiagramModelArchimateComponent) && !(source instanceof IDiagramModelArchimateConnection && target instanceof IDiagramModelArchimateConnection)) {
        // Special case if relationshipType == null. Means that the Magic connector is being used
        if (relationshipType == null) {
            return true;
        }
        IArchimateConcept sourceConcept = ((IDiagramModelArchimateComponent) source).getArchimateConcept();
        IArchimateConcept targetConcept = ((IDiagramModelArchimateComponent) target).getArchimateConcept();
        return ArchimateModelUtils.isValidRelationship(sourceConcept, targetConcept, relationshipType);
    }
    return false;
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelNote(com.archimatetool.model.IDiagramModelNote)

Example 7 with IDiagramModelArchimateComponent

use of com.archimatetool.model.IDiagramModelArchimateComponent 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 8 with IDiagramModelArchimateComponent

use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.

the class MyImporter method createAndAddConnectionsToView.

protected void createAndAddConnectionsToView(IDiagramModel diagramModel, IArchimateRelationship relationship) {
    List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getSource());
    List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getTarget());
    for (IDiagramModelComponent dmcSource : sources) {
        for (IDiagramModelComponent dmcTarget : targets) {
            IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
            dmc.setArchimateRelationship(relationship);
            dmc.connect((IDiagramModelObject) dmcSource, (IDiagramModelObject) dmcTarget);
            idLookup.put(dmc.getId(), dmc);
        }
    }
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent)

Example 9 with IDiagramModelArchimateComponent

use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.

the class MagicConnectionCreationTool method handleCreateConnection.

/**
 * When this is called, a CreateConnectionRequest will already have been created.
 * This CreateConnectionRequest will be passed to the ArchimateDiagramConnectionPolicy.
 * ArchimateDiagramConnectionPolicy will, in turn, create a CreateArchimateConnectionCommand.
 *
 * So, at this point, we already have the source and target edit parts and model objects set in a Command.
 * If we want to change this at all we will have to kludge it.
 */
@Override
protected boolean handleCreateConnection() {
    // Clear the connection factory first
    getFactory().clear();
    // Do this first, here (we have to!)
    fCanSetCurrentCommand = true;
    Command endCommand = getCommand();
    setCurrentCommand(endCommand);
    // Get this now!
    CreateConnectionRequest request = (CreateConnectionRequest) getTargetRequest();
    EditPart sourceEditPart = request.getSourceEditPart();
    EditPart targetEditPart = request.getTargetEditPart();
    if (sourceEditPart == null || sourceEditPart == targetEditPart) {
        eraseSourceFeedback();
        return false;
    }
    IDiagramModelArchimateComponent sourceDiagramModelComponent = (IDiagramModelArchimateComponent) sourceEditPart.getModel();
    // If targetEditPart is null then user clicked on the diagram or on a non-Archimate concept Editpart
    if (targetEditPart == null) {
        return createElementAndConnection(sourceDiagramModelComponent, request.getLocation());
    }
    // User clicked on Archimate target concept edit part
    if (targetEditPart.getModel() instanceof IDiagramModelArchimateComponent) {
        return createConnection(request, sourceDiagramModelComponent, (IDiagramModelArchimateComponent) targetEditPart.getModel());
    }
    eraseSourceFeedback();
    return false;
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) AbstractBaseEditPart(com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest)

Example 10 with IDiagramModelArchimateComponent

use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.

the class MagicConnectionCreationTool method setTargetEditPart.

@Override
protected void setTargetEditPart(EditPart editpart) {
    /*
         * Set editpart to null if it's not an Archimate target concept so we can handle it as if we clicked on the canvas.
         * This also disables unwanted connection target feedback.
         */
    if (editpart != null && !(editpart.getModel() instanceof IDiagramModelArchimateComponent)) {
        editpart = null;
    }
    /*
         * Check whether we are trying to connect an element to a relation where the relation is already connected to that element
         * If we are, set editpart to null to veto it.
         */
    if (editpart != null) {
        EditPart sourceEditPart = ((CreateConnectionRequest) getSourceRequest()).getSourceEditPart();
        if (sourceEditPart != null) {
            if (sourceEditPart.getModel() instanceof IDiagramModelArchimateComponent && editpart.getModel() instanceof IDiagramModelArchimateComponent) {
                IArchimateConcept sourceConcept = ((IDiagramModelArchimateComponent) sourceEditPart.getModel()).getArchimateConcept();
                IArchimateConcept targetConcept = ((IDiagramModelArchimateComponent) editpart.getModel()).getArchimateConcept();
                if (ArchimateModelUtils.hasDirectRelationship(sourceConcept, targetConcept)) {
                    editpart = null;
                }
            }
        }
    }
    super.setTargetEditPart(editpart);
}
Also used : IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) AbstractBaseEditPart(com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) IArchimateConcept(com.archimatetool.model.IArchimateConcept) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest)

Aggregations

IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)16 IArchimateConcept (com.archimatetool.model.IArchimateConcept)6 IDiagramModel (com.archimatetool.model.IDiagramModel)6 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)6 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)5 EClass (org.eclipse.emf.ecore.EClass)5 IConnectable (com.archimatetool.model.IConnectable)4 ArrayList (java.util.ArrayList)4 EditPart (org.eclipse.gef.EditPart)4 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)3 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)3 Command (org.eclipse.gef.commands.Command)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)2 AbstractBaseEditPart (com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart)2 GroupEditPart (com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart)2 IArchimateElement (com.archimatetool.model.IArchimateElement)2 EObject (org.eclipse.emf.ecore.EObject)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2