use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.
the class GenerateViewCommand method createDiagramModel.
private IArchimateDiagramModel createDiagramModel() {
// New Diagram
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
dm.setName(fViewName);
dm.setViewpoint(fViewpoint.getID());
fParentFolder = fSelectedElements.get(0).getArchimateModel().getDefaultFolderForObject(dm);
fParentFolder.getElements().add(dm);
int x = 20;
int y = 20;
getElementsToAdd();
for (IArchimateElement element : fSelectedElements) {
createDiagramNode(element, dm, x, y);
y += 100;
}
x = 170;
y = 20;
for (IArchimateElement element : fAddedElements) {
if (!fSelectedElements.contains(element)) {
createDiagramNode(element, dm, x, y);
y += 80;
if (y > 700) {
y = 20;
x += 150;
}
}
}
// Add connections between elements first
for (IDiagramModelObject dmoSource : dm.getChildren()) {
IArchimateElement elementSource = ((IDiagramModelArchimateObject) dmoSource).getArchimateElement();
for (IArchimateRelationship relation : elementSource.getSourceRelationships()) {
for (IDiagramModelObject dmoTarget : dm.getChildren()) {
IArchimateElement elementTarget = ((IDiagramModelArchimateObject) dmoTarget).getArchimateElement();
// Don't add connections that are not connected to the main elements if option is set
if (!fAddAllConnections && !(fSelectedElements.contains(elementSource)) && !(fSelectedElements.contains(elementTarget))) {
continue;
}
if (relation.getTarget() == elementTarget) {
// Create connection
IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
newConnection.connect(dmoSource, dmoTarget);
}
}
}
}
// Add connections to connections
for (Iterator<EObject> iter1 = dm.eAllContents(); iter1.hasNext(); ) {
EObject eObject1 = iter1.next();
if (eObject1 instanceof IDiagramModelArchimateConnection) {
IDiagramModelArchimateConnection connection = (IDiagramModelArchimateConnection) eObject1;
for (IDiagramModelObject dmo : dm.getChildren()) {
IArchimateElement element = ((IDiagramModelArchimateObject) dmo).getArchimateElement();
for (IArchimateRelationship relation : connection.getArchimateRelationship().getSourceRelationships()) {
if (relation.getTarget() == element) {
IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
newConnection.connect(connection, dmo);
}
}
for (IArchimateRelationship relation : connection.getArchimateRelationship().getTargetRelationships()) {
if (relation.getSource() == element) {
IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
newConnection.connect(dmo, connection);
}
}
}
}
}
return dm;
}
use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.
the class DiagramModelArchimateConnectionTests method testAdd_Remove_ArchimateRelationshipToModel.
@Test
public void testAdd_Remove_ArchimateRelationshipToModel() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm).getElements().add(dm);
dm.getChildren().add(source);
dm.getChildren().add(target);
connection.connect(source, target);
// Passing null uses a default folder in the model
IFolder expectedFolder = model.getDefaultFolderForObject(connection.getArchimateRelationship());
connection.addArchimateConceptToModel(null);
assertSame(expectedFolder, connection.getArchimateRelationship().eContainer());
connection.removeArchimateConceptFromModel();
assertNull(connection.getArchimateRelationship().eContainer());
expectedFolder = IArchimateFactory.eINSTANCE.createFolder();
connection.addArchimateConceptToModel(expectedFolder);
assertSame(expectedFolder, connection.getArchimateRelationship().eContainer());
}
use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.
the class DiagramModelArchimateObjectTests method testAdd_Remove_ArchimateElementToModel.
@Test
public void testAdd_Remove_ArchimateElementToModel() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm).getElements().add(dm);
dm.getChildren().add(object);
// Passing null uses a default folder in the model
IFolder expectedFolder = model.getDefaultFolderForObject(object.getArchimateElement());
object.addArchimateConceptToModel(null);
assertSame(expectedFolder, object.getArchimateElement().eContainer());
object.removeArchimateConceptFromModel();
assertNull(object.getArchimateElement().eContainer());
expectedFolder = IArchimateFactory.eINSTANCE.createFolder();
object.addArchimateConceptToModel(expectedFolder);
assertSame(expectedFolder, object.getArchimateElement().eContainer());
}
use of com.archimatetool.model.IArchimateDiagramModel in project archi by archimatetool.
the class ViewpointManagerTests method testIsAllowedConceptForDiagramModel.
@Test
public void testIsAllowedConceptForDiagramModel() {
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
dm.setViewpoint("organization");
assertTrue(ViewpointManager.INSTANCE.isAllowedConceptForDiagramModel(dm, IArchimatePackage.eINSTANCE.getBusinessActor()));
assertFalse(ViewpointManager.INSTANCE.isAllowedConceptForDiagramModel(dm, IArchimatePackage.eINSTANCE.getNode()));
}
Aggregations