use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.
the class DeleteFromModelAction method run.
@Override
public void run() {
List<?> selection = getSelectedObjects();
List<IArchimateConcept> archimateConcepts = new ArrayList<IArchimateConcept>();
List<IDiagramModelComponent> diagramObjects = new ArrayList<IDiagramModelComponent>();
// Gather Model elements, relations
for (Object object : selection) {
if (object instanceof EditPart) {
Object model = ((EditPart) object).getModel();
if (model instanceof IDiagramModelArchimateObject) {
IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
if (!archimateConcepts.contains(element)) {
archimateConcepts.add(element);
}
// Element's relationships
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
} else if (model instanceof IDiagramModelArchimateConnection) {
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
}
}
// Gather referenced diagram objects
for (IArchimateConcept archimateConcept : archimateConcepts) {
for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
diagramObjects.add(dc);
}
}
}
// Check whether any of these concepts are referenced in other diagrams
if (hasMoreThanOneReference(archimateConcepts, diagramObjects)) {
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) {
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
compoundCommand.add(cmd);
} else if (archimateConcept instanceof IArchimateRelationship) {
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
compoundCommand.add(cmd);
}
}
for (IDiagramModelComponent dc : diagramObjects) {
if (dc instanceof IDiagramModelObject) {
Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) dc);
compoundCommand.add(cmd);
} else if (dc instanceof IDiagramModelConnection) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) dc);
compoundCommand.add(cmd);
}
}
execute(compoundCommand);
}
use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.
the class DiagramModelConnection method getCopy.
@Override
public EObject getCopy() {
IDiagramModelConnection newConnection = (IDiagramModelConnection) super.getCopy();
newConnection.setSource(null);
newConnection.setTarget(null);
newConnection.getSourceConnections().clear();
newConnection.getTargetConnections().clear();
return newConnection;
}
use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.
the class DiagramModelUtilsTests method hasExistingConnectionType.
@Test
public void hasExistingConnectionType() {
IDiagramModelObject source = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createArtifact());
IDiagramModelObject target = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createArtifact());
IAssignmentRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
IDiagramModelConnection conn = ArchimateTestModel.createDiagramModelArchimateConnection(relation);
conn.connect(source, target);
assertTrue(DiagramModelUtils.hasExistingConnectionType(source, target, relation.eClass()));
assertFalse(DiagramModelUtils.hasExistingConnectionType(source, target, IArchimatePackage.eINSTANCE.getAccessRelationship()));
}
use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.
the class SketchEditPartFactoryTests 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 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());
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);
assertSame(actor, dmo1Copy.getArchimateConcept());
assertSame(role, dmo2Copy.getArchimateConcept());
EList<IDiagramModelConnection> connections = dmo1Copy.getSourceConnections();
assertEquals(1, connections.size());
IDiagramModelArchimateConnection dmc1Copy = (IDiagramModelArchimateConnection) connections.get(0);
assertNotSame(dmc1, dmc1Copy);
assertSame(relation, dmc1Copy.getArchimateConcept());
}
Aggregations