Search in sources :

Example 11 with IDiagramModelArchimateComponent

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

the class DiagramModelUtils method shouldBeHiddenConnection.

/**
 * @param connection The connection to check
 * @return true if a connection should be hidden when its source (parent) element contains its target (child) element
 */
public static boolean shouldBeHiddenConnection(IDiagramModelArchimateConnection connection) {
    if (!ConnectionPreferences.useNestedConnections()) {
        return false;
    }
    // Only if the connection's source and target are both ArchiMate concepts
    if (!(connection.getSource() instanceof IDiagramModelArchimateComponent) && !(connection.getTarget() instanceof IDiagramModelArchimateComponent)) {
        return false;
    }
    IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) connection.getSource();
    IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) connection.getTarget();
    // If the connection's source element contains the target element, or the connection's target element contains the source element
    if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateObject) {
        if (((IDiagramModelContainer) source).getChildren().contains((IDiagramModelArchimateObject) target) || ((IDiagramModelContainer) target).getChildren().contains((IDiagramModelArchimateObject) source)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    // If connection's source is an element and target is a connection
    if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateConnection) {
        IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) source;
        IConnectable connectionSource = ((IDiagramModelArchimateConnection) target).getSource();
        IConnectable connectionTarget = ((IDiagramModelArchimateConnection) target).getTarget();
        if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    // TODO: Not sure if this directionality should be allowed
    if (target instanceof IDiagramModelArchimateObject && source instanceof IDiagramModelArchimateConnection) {
        IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) target;
        IConnectable connectionSource = ((IDiagramModelArchimateConnection) source).getSource();
        IConnectable connectionTarget = ((IDiagramModelArchimateConnection) source).getTarget();
        if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IConnectable(com.archimatetool.model.IConnectable) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 12 with IDiagramModelArchimateComponent

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

the class ArchimateDiagramConnectionPolicy method getConnectionCreateCommand.

@Override
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
    CreateDiagramConnectionCommand cmd = null;
    EClass classType = (EClass) request.getNewObjectType();
    IConnectable source = (IConnectable) getHost().getModel();
    // Plain Connection
    if (classType == IArchimatePackage.eINSTANCE.getDiagramModelConnection()) {
        if (isValidConnectionSource(source, classType)) {
            cmd = new CreateDiagramConnectionCommand(request);
        }
    } else // Archimate Model Component Source
    if (source instanceof IDiagramModelArchimateComponent) {
        if (isValidConnectionSource(source, classType)) {
            cmd = new CreateDiagramArchimateConnectionWithDialogCommand(request);
        }
    }
    if (cmd != null) {
        cmd.setSource(source);
        request.setStartCommand(cmd);
    }
    return cmd;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IConnectable(com.archimatetool.model.IConnectable) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand)

Example 13 with IDiagramModelArchimateComponent

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

the class DiagramModelUtilsTests method findDiagramModelComponentsForArchimateConcept_Relationship.

@Test
public void findDiagramModelComponentsForArchimateConcept_Relationship() {
    IArchimateRelationship relationship = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    IDiagramModel diagramModel = tm.addNewArchimateDiagramModel();
    // Should not be found
    List<IDiagramModelArchimateComponent> list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship);
    assertTrue(list.isEmpty());
    // Create various IDiagramModelArchimateObject objects
    createDataForDiagramModelArchimateObjects(IArchimateFactory.eINSTANCE.createBusinessActor(), diagramModel);
    // And make some connections using the relationship
    createDataForDiagramModelConnections(relationship);
    // Found in diagram
    list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship);
    assertEquals(3, list.size());
    assertTrue(list.contains(conn1));
    assertTrue(list.contains(conn2));
    assertTrue(list.contains(conn3));
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

Example 14 with IDiagramModelArchimateComponent

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

the class CreateDiagramArchimateConnectionWithDialogCommand method checkToReuseExistingRelationship.

boolean checkToReuseExistingRelationship() {
    EClass classType = (EClass) fRequest.getNewObjectType();
    if (fSource instanceof IDiagramModelArchimateComponent && fTarget instanceof IDiagramModelArchimateComponent) {
        IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) fSource;
        IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) fTarget;
        // If there is already a relation of this type in the model...
        IArchimateRelationship relation = getExistingRelationshipOfType(classType, source.getArchimateConcept(), target.getArchimateConcept());
        if (relation != null) {
            // ...then ask the user if they want to re-use it
            boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.CreateArchimateConnectionWithDialogCommand_0, NLS.bind(Messages.CreateArchimateConnectionWithDialogCommand_1, ArchiLabelProvider.INSTANCE.getLabel(source), ArchiLabelProvider.INSTANCE.getLabel(target)));
            // Yes...
            if (answer) {
                // ...set connection's relationship to the existing relation
                fConnection = createNewConnection();
                ((IDiagramModelArchimateConnection) fConnection).setArchimateRelationship(relation);
                return true;
            }
        }
    }
    return false;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Example 15 with IDiagramModelArchimateComponent

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

the class ObjectUIFactory method getProvider.

public IObjectUIProvider getProvider(EObject eObject) {
    EClass eClass = null;
    // We need to unwrap these here as this is called from diagram model objects
    if (eObject instanceof IDiagramModelArchimateComponent) {
        eClass = ((IDiagramModelArchimateComponent) eObject).getArchimateConcept().eClass();
    } else if (eObject != null) {
        eClass = eObject.eClass();
    }
    IObjectUIProvider provider = getProviderForClass(eClass);
    if (provider != null) {
        provider.setInstance(eObject);
    }
    return provider;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent)

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