use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class UnusedElementsCheckerTests method testGetIssues.
@Test
public void testGetIssues() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
IArchimateElement element = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
elements.add(element);
UnusedElementsChecker checker = new UnusedElementsChecker(elements);
// Should not be OK
List<IIssue> issues = checker.getIssues();
assertEquals(1, issues.size());
assertSame(element, issues.get(0).getObject());
// Add it to a diagram
IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo.setArchimateElement(element);
model.getDefaultDiagramModel().getChildren().add(dmo);
// Should be OK
issues = checker.getIssues();
assertEquals(0, issues.size());
}
use of com.archimatetool.model.IDiagramModelArchimateObject 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.IDiagramModelArchimateObject in project archi by archimatetool.
the class CreateNestedArchimateConnectionsWithDialogCommand method createNewConnectionCommands.
/**
* Create Commands for child objects that don't have connections and need new ones
*
* TODO A3: If O1--C1--O2. C1 is also connected to parent.
* O1 or O2 is added to parent - should add connection from C1 to parent?
* Or should it be only when O1 AND O2 are added to parent?
*/
void createNewConnectionCommands() {
IArchimateElement parentElement = fParentObject.getArchimateElement();
// Check connections between parent and child objects that are being dragged in
for (IDiagramModelArchimateObject childObject : fChildObjects) {
IArchimateElement childElement = childObject.getArchimateElement();
boolean aConnectionExists = false;
// Specialization relationship is the other way around
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement && relation.eClass() == IArchimatePackage.eINSTANCE.getSpecializationRelationship() && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
if (DiagramModelUtils.hasDiagramModelArchimateConnection(childObject, fParentObject, relation)) {
aConnectionExists = true;
break;
}
}
}
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
if (DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, childObject, relation)) {
aConnectionExists = true;
break;
}
}
}
// Create connections from relationships if none already exists
if (!aConnectionExists) {
// Specialization relationship is the other way around
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement && relation.eClass() == IArchimatePackage.eINSTANCE.getSpecializationRelationship() && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
add(new CreateDiagramArchimateConnectionCommand(childObject, fParentObject, relation));
}
}
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
add(new CreateDiagramArchimateConnectionCommand(fParentObject, childObject, relation));
}
}
}
}
// Check connections between parent and child connections of objects
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() instanceof IArchimateRelationship) {
IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship) relation.getTarget());
if (dmc != null) {
if (!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) {
add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation));
}
}
}
}
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() instanceof IArchimateRelationship) {
IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship) relation.getSource());
if (dmc != null) {
if (!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) {
add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation));
}
}
}
}
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class DeleteNestedConnectionsCommand method createDeleteCommands.
/**
* Child Objects that have connections
*/
void createDeleteCommands() {
for (IDiagramModelArchimateObject child : fChildObjects) {
for (IDiagramModelConnection connection : child.getTargetConnections()) {
if (connection instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) connection)) {
for (IDiagramModelConnection subconnection : connection.getTargetConnections()) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
add(cmd);
}
for (IDiagramModelConnection subconnection : connection.getSourceConnections()) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
add(cmd);
}
}
}
}
}
use of com.archimatetool.model.IDiagramModelArchimateObject 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;
}
Aggregations