use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class DuplicateCommandHandlerTests method testDuplicateDiagramModel.
@Test
public void testDuplicateDiagramModel() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
IDiagramModel dm = model.getDefaultDiagramModel();
IArchimateElement actor = IArchimateFactory.eINSTANCE.createBusinessActor();
IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(actor);
dmo1.setName("dm");
dm.getChildren().add(dmo1);
IArchimateElement role = IArchimateFactory.eINSTANCE.createBusinessRole();
IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(role);
dm.getChildren().add(dmo2);
IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
relation.setSource(actor);
relation.setTarget(role);
IDiagramModelArchimateConnection dmc1 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation);
dmc1.connect(dmo1, dmo2);
DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { dm });
handler.duplicate();
assertEquals(2, model.getDiagramModels().size());
IDiagramModel dmCopy = model.getDiagramModels().get(1);
assertNotSame(dm, dmCopy);
assertEquals(dm.getName() + " (copy)", dmCopy.getName());
assertNotEquals(dmCopy.getId(), dm.getId());
EList<IDiagramModelObject> children = dmCopy.getChildren();
assertEquals(2, children.size());
IDiagramModelArchimateObject dmo1Copy = (IDiagramModelArchimateObject) children.get(0);
IDiagramModelArchimateObject dmo2Copy = (IDiagramModelArchimateObject) children.get(1);
assertNotSame(dmo1, dmo1Copy);
assertNotSame(dmo2, dmo2Copy);
assertNotEquals(dmo1.getId(), dmo1Copy.getId());
assertNotEquals(dmo2.getId(), dmo2Copy.getId());
assertSame(actor, dmo1Copy.getArchimateConcept());
assertSame(role, dmo2Copy.getArchimateConcept());
assertSame(actor.getId(), dmo1Copy.getArchimateConcept().getId());
assertSame(role.getId(), dmo2Copy.getArchimateConcept().getId());
EList<IDiagramModelConnection> connections = dmo1Copy.getSourceConnections();
assertEquals(1, connections.size());
IDiagramModelArchimateConnection dmc1Copy = (IDiagramModelArchimateConnection) connections.get(0);
assertNotSame(dmc1, dmc1Copy);
assertNotEquals(dmc1.getId(), dmc1Copy.getId());
assertSame(relation, dmc1Copy.getArchimateConcept());
assertSame(relation.getId(), dmc1Copy.getArchimateConcept().getId());
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class ArchimateTestModel method createDiagramModelArchimateConnectionAndAddToModel.
/**
* Create a DiagramModelArchimateConnection and add an Archimate relationship to it.
* The relationship will be added to its default container folder in the model
*/
public IDiagramModelArchimateConnection createDiagramModelArchimateConnectionAndAddToModel(IArchimateRelationship relationship) {
IDiagramModelArchimateConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
conn.setArchimateRelationship(relationship);
if (relationship.eContainer() == null) {
model.getArchimateModel().getDefaultFolderForObject(relationship).getElements().add(relationship);
}
return conn;
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class AbstractIssueTypeTests method testGetAdapter_ObjectIsAssignableFrom_Relation.
@Test
public void testGetAdapter_ObjectIsAssignableFrom_Relation() {
IAggregationRelationship relation = IArchimateFactory.eINSTANCE.createAggregationRelationship();
IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
dmc.setArchimateConcept(relation);
issueType.setObject(dmc);
assertSame(relation, issueType.getAdapter(IArchimateConcept.class));
assertSame(relation, issueType.getAdapter(IArchimateRelationship.class));
assertNull(issueType.getAdapter(IArchimateElement.class));
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class DeleteFromModelAction method run.
@Override
public void run() {
List<?> selection = getSelectedObjects();
Set<IArchimateConcept> archimateConcepts = new HashSet<IArchimateConcept>();
// Gather referenced model concepts
for (Object object : selection) {
if (object instanceof EditPart) {
Object model = ((EditPart) object).getModel();
if (model instanceof IDiagramModelArchimateObject) {
IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
archimateConcepts.add(element);
// Element's relationships
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
archimateConcepts.add(relation);
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
archimateConcepts.add(r);
}
}
} else if (model instanceof IDiagramModelArchimateConnection) {
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
archimateConcepts.add(relation);
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
archimateConcepts.add(r);
}
}
}
}
// Check whether any of these concepts are referenced in other diagrams
if (hasMoreThanOneReference(archimateConcepts)) {
if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteFromModelAction_0, Messages.DeleteFromModelAction_1 + // $NON-NLS-1$
"\n\n" + Messages.DeleteFromModelAction_2)) {
return;
}
}
// Create commands
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT);
for (IArchimateConcept archimateConcept : archimateConcepts) {
if (archimateConcept instanceof IArchimateElement) {
// Element
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
compoundCommand.add(cmd);
// Diagram Model Objects
for (IDiagramModelObject dmo : ((IArchimateElement) archimateConcept).getReferencingDiagramObjects()) {
cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand(dmo);
compoundCommand.add(cmd);
}
} else if (archimateConcept instanceof IArchimateRelationship) {
// Relationship
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
compoundCommand.add(cmd);
// Diagram Model Connections
for (IDiagramModelArchimateConnection dmc : ((IArchimateRelationship) archimateConcept).getReferencingDiagramConnections()) {
cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(dmc);
compoundCommand.add(cmd);
}
}
}
BusyIndicator.showWhile(null, new Runnable() {
@Override
public void run() {
execute(compoundCommand);
}
});
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class ViewImporter method createConnections.
/**
* Create and add new diagram connections
* Do this in two passes in case there are connection -> connections
*/
private void createConnections() throws ImportException {
Hashtable<IDiagramModelConnection, IDiagramModelConnection> connections = new Hashtable<>();
// Create new connections. They will be cached in ModelImporter
for (Iterator<EObject> iter = importedView.eAllContents(); iter.hasNext(); ) {
EObject importedObject = iter.next();
if (importedObject instanceof IDiagramModelConnection) {
connections.put((IDiagramModelConnection) importedObject, cloneObject((IDiagramModelConnection) importedObject));
}
}
// Now connect the source and target ends
for (Entry<IDiagramModelConnection, IDiagramModelConnection> entry : connections.entrySet()) {
IDiagramModelConnection importedConnection = entry.getKey();
IDiagramModelConnection targetConnection = entry.getValue();
IConnectable targetSource = findObjectInTargetModel(importedConnection.getSource());
if (targetSource == null) {
// $NON-NLS-1$
throw new ImportException("Could not find source component: " + importedConnection.getSource().getId());
}
IConnectable targetTarget = findObjectInTargetModel(importedConnection.getTarget());
if (targetTarget == null) {
// $NON-NLS-1$
throw new ImportException("Could not find target component: " + importedConnection.getTarget().getId());
}
// It's an Archimate connection
if (targetConnection instanceof IDiagramModelArchimateConnection) {
// Set the connections's relationship first before connecting source and target otherwise we end up with duplicate relationships
setArchimateConcept((IDiagramModelArchimateConnection) importedConnection, (IDiagramModelArchimateConnection) targetConnection);
// Need a Command for this
addCommand(new ArchimateConnectionCommand((IDiagramModelArchimateConnection) targetConnection, targetSource, targetTarget));
} else // Other connection
{
targetConnection.connect(targetSource, targetTarget);
}
}
}
Aggregations