use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommandTests method testCreationOfConnectionAndRelationship.
@Test
public void testCreationOfConnectionAndRelationship() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessActor());
IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessRole());
model.getDefaultDiagramModel().getChildren().add(dmo1);
model.getDefaultDiagramModel().getChildren().add(dmo2);
cmd.setSource(dmo1);
cmd.setTarget(dmo2);
cmd.execute();
IDiagramModelConnection connection = cmd.fConnection;
assertTrue(connection instanceof IDiagramModelArchimateConnection);
assertSame(dmo1, connection.getSource());
assertSame(dmo2, connection.getTarget());
IArchimateRelationship relationship = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
assertTrue(relationship instanceof IAssignmentRelationship);
assertNotNull(relationship.eContainer());
cmd.undo();
assertNull(relationship.eContainer());
}
use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.
the class ArchimateDiagramEditPartFactoryTests method testLineConnectionEditPart.
@Test
public void testLineConnectionEditPart() {
IDiagramModelConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelConnection();
EditPart editPart = editPartFactory.createEditPart(null, conn);
assertTrue(editPart instanceof DiagramConnectionEditPart);
assertEquals(conn, editPart.getModel());
}
use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.
the class CopySnapshot method createSnapshotConnectionsForSelectedComponents.
/*
* Create copies of connections that have been selected (if source and target also have been selected/mapped)
*/
private void createSnapshotConnectionsForSelectedComponents(List<IDiagramModelComponent> selected) {
// Create new connection copies for all selected connections, but don't connect them yet
for (IDiagramModelComponent component : selected) {
if (component instanceof IDiagramModelConnection) {
IDiagramModelConnection connection = (IDiagramModelConnection) component;
// The source and the target object must also be selected
if (isSelectedConnectionCopyable(connection, selected)) {
IDiagramModelConnection newConnection = (IDiagramModelConnection) connection.getCopy();
fOriginalToSnapshotComponentsMapping.put(connection, newConnection);
}
}
}
// Now connect both ends if both ends are also in the selection/mapping
for (Entry<IConnectable, IConnectable> entry : fOriginalToSnapshotComponentsMapping.entrySet()) {
if (entry.getKey() instanceof IDiagramModelConnection) {
IDiagramModelConnection originalConnection = (IDiagramModelConnection) entry.getKey();
IConnectable newSource = fOriginalToSnapshotComponentsMapping.get(originalConnection.getSource());
IConnectable newTarget = fOriginalToSnapshotComponentsMapping.get(originalConnection.getTarget());
if (newSource != null && newTarget != null) {
IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
newConnection.connect(newSource, newTarget);
}
}
}
}
use of com.archimatetool.model.IDiagramModelConnection 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();
createID(newConnection);
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.IDiagramModelConnection in project archi by archimatetool.
the class CopySnapshot method createAutomaticSnapshotConnections.
/*
* Create automatic copies of connections (if source and target also have been selected/mapped)
*/
private void createAutomaticSnapshotConnections() {
List<IDiagramModelConnection> allConnections = new ArrayList<IDiagramModelConnection>();
// Get all connections from objects
for (IConnectable connectable : fOriginalToSnapshotComponentsMapping.keySet()) {
for (IDiagramModelConnection connection : connectable.getSourceConnections()) {
if (!allConnections.contains(connection)) {
allConnections.add(connection);
}
}
for (IDiagramModelConnection connection : connectable.getTargetConnections()) {
if (!allConnections.contains(connection)) {
allConnections.add(connection);
}
}
}
// Create copies of ones that have both ends
for (IDiagramModelConnection connection : allConnections) {
if (isSelectedConnectionCopyable(connection, allConnections)) {
IDiagramModelConnection newConnection = (IDiagramModelConnection) connection.getCopy();
fOriginalToSnapshotComponentsMapping.put(connection, newConnection);
}
}
// Now connect both ends if both ends are also in the mapping
for (Entry<IConnectable, IConnectable> entry : fOriginalToSnapshotComponentsMapping.entrySet()) {
if (entry.getKey() instanceof IDiagramModelConnection) {
IDiagramModelConnection originalConnection = (IDiagramModelConnection) entry.getKey();
IConnectable newSource = fOriginalToSnapshotComponentsMapping.get(originalConnection.getSource());
IConnectable newTarget = fOriginalToSnapshotComponentsMapping.get(originalConnection.getTarget());
if (newSource != null && newTarget != null) {
IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
newConnection.connect(newSource, newTarget);
} else {
// $NON-NLS-1$
System.err.println("No source or target in CopySnapshot!");
}
}
}
}
Aggregations