use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class NestedElementsChecker method isNestedWithoutValidRelation.
private boolean isNestedWithoutValidRelation(IDiagramModelArchimateObject parent, IDiagramModelArchimateObject child) {
IArchimateElement parentElement = parent.getArchimateElement();
IArchimateElement childElement = child.getArchimateElement();
// Ignore nested Junctions
if (childElement instanceof IJunction) {
return false;
}
// Get all diagram connections between parent and child objects
List<IDiagramModelConnection> connections = new ArrayList<>(parent.getSourceConnections());
connections.addAll(parent.getTargetConnections());
for (IDiagramModelConnection connection : connections) {
// If this is an ArchiMate connection...
if (connection instanceof IDiagramModelArchimateConnection && (connection.getSource() == child || connection.getTarget() == child)) {
// Get its relationship
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
// Check for non-nested type relationships
if (!isNestedTypeRelationship(relation)) {
return true;
}
// Specialization relationship needs a special check as it goes the other way around
if (relation instanceof ISpecializationRelationship) {
if (relation.getTarget() == childElement) {
return true;
}
} else // Else reversed nested
if (relation.getSource() == childElement && isNestedTypeRelationship(relation)) {
return true;
}
}
}
// Check for any nested type relationships in the model, return false if one is found
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(parentElement)) {
if ((relation.getTarget() == childElement || relation.getSource() == childElement) && isNestedTypeRelationship(relation)) {
return false;
}
}
return true;
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class UnusedRelationsCheckerTests method testGetIssues.
@Test
public void testGetIssues() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
List<IArchimateRelationship> relations = new ArrayList<IArchimateRelationship>();
IArchimateRelationship relation = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getAssociationRelationship());
relations.add(relation);
IArchimateElement e1 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
IArchimateElement e2 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
relation.connect(e1, e2);
UnusedRelationsChecker checker = new UnusedRelationsChecker(relations);
// Should not be OK
List<IIssue> issues = checker.getIssues();
assertEquals(1, issues.size());
assertSame(relation, issues.get(0).getObject());
// Add it to a diagram
IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo1.setArchimateElement(e1);
model.getDefaultDiagramModel().getChildren().add(dmo1);
IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo2.setArchimateElement(e2);
model.getDefaultDiagramModel().getChildren().add(dmo2);
IDiagramModelArchimateConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
conn.setArchimateRelationship(relation);
conn.connect(dmo1, dmo2);
// Should be OK
issues = checker.getIssues();
assertEquals(0, issues.size());
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class DiagramModelExtraTests method testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects.
/**
* See {@link DiagramModelArchimateConnection#eInverseAdd(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
* See {@link DiagramModelArchimateConnection#eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
*/
@Test
public void testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects() {
IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement e3 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement e4 = IArchimateFactory.eINSTANCE.createBusinessActor();
IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo4 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo1.setArchimateElement(e1);
dmo2.setArchimateElement(e2);
dmo3.setArchimateElement(e3);
dmo4.setArchimateElement(e4);
ArchimateRelationship r1 = (ArchimateRelationship) IArchimateFactory.eINSTANCE.createAssociationRelationship();
ArchimateRelationship r2 = (ArchimateRelationship) IArchimateFactory.eINSTANCE.createAssociationRelationship();
ArchimateRelationship r3 = (ArchimateRelationship) IArchimateFactory.eINSTANCE.createAssociationRelationship();
r1.setSource(e1);
r1.setTarget(e2);
r2.setSource(e2);
r2.setTarget(e3);
r3.setSource(e3);
r3.setTarget(e4);
IDiagramModelArchimateConnection conn1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
IDiagramModelArchimateConnection conn2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
IDiagramModelArchimateConnection conn3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
// conn3a shares a relationship with conn3
IDiagramModelArchimateConnection conn3a = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
conn1.setArchimateRelationship(r1);
conn2.setArchimateRelationship(r2);
conn3.setArchimateRelationship(r3);
// same
conn3a.setArchimateRelationship(r3);
// Set up model and diagram model
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
IDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm).getElements().add(dm);
// Add some parents
IDiagramModelGroup parent1 = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
dm.getChildren().add(parent1);
IDiagramModelArchimateObject parent2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
parent1.getChildren().add(parent2);
// Add the dmos
dm.getChildren().add(dmo1);
parent1.getChildren().add(dmo2);
parent2.getChildren().add(dmo3);
dm.getChildren().add(dmo4);
// Public methods should return zero
assertEquals(0, r1.getReferencingDiagramConnections().size());
assertEquals(0, r2.getReferencingDiagramConnections().size());
assertEquals(0, r3.getReferencingDiagramConnections().size());
assertEquals(0, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// But internally, referenced
assertEquals(1, r1.diagramConnections.size());
assertEquals(1, r2.diagramConnections.size());
// beacause r3 is in conn3 and conn3a
assertEquals(2, r3.diagramConnections.size());
assertEquals(2, ((ArchimateRelationship) conn3a.getArchimateRelationship()).diagramConnections.size());
// Connect, should be the same
conn1.connect(dmo1, dmo2);
assertEquals(1, r1.getReferencingDiagramConnections().size());
assertEquals(1, r1.diagramConnections.size());
conn2.connect(dmo2, dmo3);
assertEquals(1, r2.getReferencingDiagramConnections().size());
assertEquals(1, r2.diagramConnections.size());
conn3.connect(dmo3, dmo4);
assertEquals(1, r3.getReferencingDiagramConnections().size());
// beacause r3 is in conn3 and conn3a
assertEquals(2, r3.diagramConnections.size());
conn3a.connect(dmo3, dmo4);
assertEquals(2, r3.getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, ((ArchimateRelationship) conn3a.getArchimateRelationship()).diagramConnections.size());
// Remove diagram model
((IFolder) dm.eContainer()).getElements().remove(dm);
// Public methods should return zero
assertEquals(0, r1.getReferencingDiagramConnections().size());
assertEquals(0, r2.getReferencingDiagramConnections().size());
assertEquals(0, r3.getReferencingDiagramConnections().size());
assertEquals(0, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// But internally still referenced
assertEquals(1, r1.diagramConnections.size());
assertEquals(1, r2.diagramConnections.size());
// beacause r3 is in conn3 and conn3a
assertEquals(2, r3.diagramConnections.size());
assertEquals(2, ((ArchimateRelationship) conn3a.getArchimateRelationship()).diagramConnections.size());
// Add diagram model back again
model.getDefaultFolderForObject(dm).getElements().add(dm);
// Public methods should be as before
assertEquals(1, r1.getReferencingDiagramConnections().size());
assertEquals(1, r2.getReferencingDiagramConnections().size());
assertEquals(2, r3.getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// And internally still referenced
assertEquals(1, r1.diagramConnections.size());
assertEquals(1, r2.diagramConnections.size());
// beacause r3 is in conn3 and conn3a
assertEquals(2, r3.diagramConnections.size());
assertEquals(2, ((ArchimateRelationship) conn3a.getArchimateRelationship()).diagramConnections.size());
// Disconnect
conn1.disconnect();
conn2.disconnect();
conn3.disconnect();
conn3a.disconnect();
// Public methods should return zero again
assertEquals(0, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// And internally zero
assertEquals(0, r1.diagramConnections.size());
assertEquals(0, r2.diagramConnections.size());
// beacause r3 is in conn3 and conn3a
assertEquals(0, r3.diagramConnections.size());
assertEquals(0, ((ArchimateRelationship) conn3a.getArchimateRelationship()).diagramConnections.size());
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class CopySnapshot method createPasteConnections.
private List<IDiagramModelConnection> createPasteConnections() {
List<IDiagramModelConnection> connections = new ArrayList<IDiagramModelConnection>();
// Create new connections from basis of snapshot
for (IConnectable connectable : fOriginalToSnapshotComponentsMapping.values()) {
if (connectable instanceof IDiagramModelConnection) {
IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) connectable;
IDiagramModelConnection newConnection = (IDiagramModelConnection) snapshotConnection.getCopy();
connections.add(newConnection);
// Mapping
fSnapshotToNewComponentMapping.put(snapshotConnection, newConnection);
// Re-use original Archimate relationship if required
if (!fDoCreateNewArchimateComponents && snapshotConnection instanceof IDiagramModelArchimateConnection) {
IDiagramModelArchimateConnection originalDiagramConnection = (IDiagramModelArchimateConnection) fOriginalToSnapshotComponentsMapping.getKey(snapshotConnection);
IArchimateRelationship relationship = originalDiagramConnection.getArchimateRelationship();
((IDiagramModelArchimateConnection) newConnection).setArchimateRelationship(relationship);
}
}
}
// Connect them
for (Entry<IConnectable, IConnectable> entry : fSnapshotToNewComponentMapping.entrySet()) {
if (entry.getKey() instanceof IDiagramModelConnection) {
IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) entry.getKey();
IConnectable newSource = fSnapshotToNewComponentMapping.get(snapshotConnection.getSource());
IConnectable newTarget = fSnapshotToNewComponentMapping.get(snapshotConnection.getTarget());
if (newSource != null && newTarget != null) {
IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
newConnection.connect(newSource, newTarget);
}
}
}
return connections;
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommand method checkToReuseExistingRelationship.
private boolean checkToReuseExistingRelationship() {
if (fSource instanceof IDiagramModelArchimateComponent && fTarget instanceof IDiagramModelArchimateComponent) {
IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) fSource;
IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) fTarget;
EClass classType = (EClass) fRequest.getNewObjectType();
// Find any relations of this type connecting source and target concepts
List<IArchimateRelationship> relations = getExistingRelationshipsOfType(classType, source.getArchimateConcept(), target.getArchimateConcept());
// If there is already a relation of this type connecting source and target concepts...
if (!relations.isEmpty()) {
// Ask user in dialog if they want to reference an existing one
ChooseRelationDialog dialog = new ChooseRelationDialog(ArchiLabelProvider.INSTANCE.getDefaultName(classType), NLS.bind(Messages.CreateArchimateConnectionWithDialogCommand_1, ArchiLabelProvider.INSTANCE.getLabel(source), ArchiLabelProvider.INSTANCE.getLabel(target)), relations);
if (dialog.open() == Window.OK) {
// Create a new connection
fConnection = createNewConnection();
// set the connection's relationship to the chosen relation
((IDiagramModelArchimateConnection) fConnection).setArchimateRelationship(dialog.getSelected());
return true;
}
}
}
return false;
}
Aggregations