use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class MyImporter method doImport.
@Override
public void doImport() throws IOException {
File file = askOpenFile();
if (file == null) {
return;
}
// Load in the file and get its information here.
// Assuming you load in the data in some way, perhaps with JDOM, or a SAX Parser ot text reader then you will
// have a representation of it in memory that you need to map to Archi elements.
// Here is some example raw data in String format. This is a very simple example so the data
// is not in the best format. There is no error checking either.
// Elements
String[] elements = { // Type, Name, ID
"BusinessActor", "Actor", "elementID1", "BusinessRole", "Client", "elementID2", "BusinessFunction", "My Function", "elementID3" };
// Relationships
String[] relations = { // Type, Name, ID, sourceID, targetID
"AssignmentRelationship", "Assigned to", "relID1", "elementID1", "elementID2", "UsedByRelationship", "", "relID2", "elementID1", "elementID3", "AssociationRelationship", "", "relID3", "elementID2", "elementID3" };
// Views
String[] views = { // Name, ID
"A View", "view1", "Another View", "view2" };
// View elements
String[] viewElements = { // ID of parent View, ID of referenced element, x, y, width, height
"view1", "elementID1", "10", "10", "-1", "-1", "view1", "elementID2", "310", "10", "-1", "-1", "view1", "elementID3", "310", "110", "-1", "-1", "view2", "elementID2", "10", "10", "-1", "-1", "view2", "elementID3", "10", "110", "-1", "-1" };
// View connections
String[] viewConnections = { // ID of parent View, ID of relationship
"view1", "relID1", "view1", "relID2", "view2", "relID3" };
// Create the model...
// Create a new Archimate Model and set its defaults
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
model.setName("My Model");
// Create and add elements matching imported data
// If an ID is not provided for an element then a unique ID will be generated when the model element is added to a parent
// model element, otherwise you can use your own IDs provided in the input data.
// Let's use an ID -> EObject mapping table for convenience
idLookup = new HashMap<String, EObject>();
// Create and add model elements
for (int i = 0; i < elements.length; ) {
String type = elements[i++];
String name = elements[i++];
String id = elements[i++];
createAndAddArchimateElement(model, (EClass) IArchimatePackage.eINSTANCE.getEClassifier(type), name, id);
}
// Create and add model relationships and set source and target elements
for (int i = 0; i < relations.length; ) {
String type = relations[i++];
String name = relations[i++];
String id = relations[i++];
String sourceID = relations[i++];
String targetID = relations[i++];
IArchimateRelationship relationship = createAndAddArchimateRelationship(model, (EClass) IArchimatePackage.eINSTANCE.getEClassifier(type), name, id);
// Find source and target elements from their IDs in the lookup table
IArchimateElement source = (IArchimateElement) idLookup.get(sourceID);
IArchimateElement target = (IArchimateElement) idLookup.get(targetID);
relationship.setSource(source);
relationship.setTarget(target);
}
// Create and add diagram views
for (int i = 0; i < views.length; ) {
String name = views[i++];
String id = views[i++];
createAndAddView(model, name, id);
}
// Add diagram elements to views
for (int i = 0; i < viewElements.length; ) {
String viewID = viewElements[i++];
String refID = viewElements[i++];
int x = Integer.parseInt(viewElements[i++]);
int y = Integer.parseInt(viewElements[i++]);
int width = Integer.parseInt(viewElements[i++]);
int height = Integer.parseInt(viewElements[i++]);
IDiagramModel diagramModel = (IDiagramModel) idLookup.get(viewID);
IArchimateElement element = (IArchimateElement) idLookup.get(refID);
createAndAddElementToView(diagramModel, element, x, y, width, height);
}
// Add diagram connections to views
for (int i = 0; i < viewConnections.length; ) {
String viewID = viewConnections[i++];
String relationshipID = viewConnections[i++];
IDiagramModel diagramModel = (IDiagramModel) idLookup.get(viewID);
IArchimateRelationship relationship = (IArchimateRelationship) idLookup.get(relationshipID);
createAndAddConnectionsToView(diagramModel, relationship);
}
// And open the Model in the Editor
IEditorModelManager.INSTANCE.openModel(model);
}
use of com.archimatetool.model.IArchimateRelationship in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method resolveProxies.
/**
* Iterate through all model objects, and resolve proxies on known classes
*/
private void resolveProxies() {
for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IArchimateRelationship) {
// Resolve proxies for Relations
IArchimateRelationship relation = (IArchimateRelationship) eObject;
relation.setSource((IArchimateConcept) resolve(relation.getSource(), relation));
relation.setTarget((IArchimateConcept) resolve(relation.getTarget(), relation));
} else if (eObject instanceof IDiagramModelArchimateObject) {
// Resolve proxies for Elements
IDiagramModelArchimateObject element = (IDiagramModelArchimateObject) eObject;
element.setArchimateElement((IArchimateElement) resolve(element.getArchimateElement(), element));
// Update cross-references
element.getArchimateElement().getReferencingDiagramObjects().add(element);
} else if (eObject instanceof IDiagramModelArchimateConnection) {
// Resolve proxies for Connections
IDiagramModelArchimateConnection archiConnection = (IDiagramModelArchimateConnection) eObject;
archiConnection.setArchimateRelationship((IArchimateRelationship) resolve(archiConnection.getArchimateRelationship(), archiConnection));
// Update cross-reference
archiConnection.getArchimateRelationship().getReferencingDiagramConnections().add(archiConnection);
} else if (eObject instanceof IDiagramModelReference) {
// Resolve proxies for Model References
IDiagramModelReference element = (IDiagramModelReference) eObject;
element.setReferencedModel((IDiagramModel) resolve(element.getReferencedModel(), element));
}
}
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class CopySnapshotTests method testNestedConnectionIsCopied.
@Test
public void testNestedConnectionIsCopied() throws IOException {
loadTestModel1();
// Create parent object
IDiagramModelArchimateObject dmoParent = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createBusinessActor());
dmoParent.setBounds(0, 0, 200, 200);
sourceDiagramModel.getChildren().add(dmoParent);
// Create child object
IDiagramModelArchimateObject dmoChild = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createBusinessRole());
dmoChild.setBounds(0, 0, 100, 100);
dmoParent.getChildren().add(dmoChild);
// Create relationship
IArchimateRelationship relationship = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
relationship.setSource(dmoParent.getArchimateElement());
relationship.setTarget(dmoChild.getArchimateElement());
// Test that an explicit connection is copied
// Create connection
IDiagramModelArchimateConnection connection = ArchimateTestModel.createDiagramModelArchimateConnection(relationship);
connection.connect(dmoParent, dmoChild);
List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
selected.add(dmoParent);
CopySnapshot snapshot = new CopySnapshot(selected);
Command cmd = snapshot.getPasteCommand(targetDiagramModel, null, null, false);
assertNotNull(cmd);
cmd.execute();
assertEquals(1, countAllConnections(targetDiagramModel));
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommandTests method testGetExistingRelationshipOfType.
@Test
public void testGetExistingRelationshipOfType() {
ArchimateTestModel tm = new ArchimateTestModel();
tm.createSimpleModel();
IArchimateElement source = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
IArchimateElement target = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
IArchimateRelationship relation1 = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getAssignmentRelationship());
IArchimateRelationship relation2 = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getFlowRelationship());
assertNull(cmd.getExistingRelationshipOfType(IArchimatePackage.eINSTANCE.getAssignmentRelationship(), source, target));
relation1.setSource(source);
relation1.setTarget(target);
relation2.setSource(source);
relation2.setTarget(target);
assertEquals(relation1, cmd.getExistingRelationshipOfType(IArchimatePackage.eINSTANCE.getAssignmentRelationship(), source, target));
assertEquals(relation2, cmd.getExistingRelationshipOfType(IArchimatePackage.eINSTANCE.getFlowRelationship(), source, target));
}
use of com.archimatetool.model.IArchimateRelationship 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());
}
Aggregations