Search in sources :

Example 36 with IArchimateRelationship

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);
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) EObject(org.eclipse.emf.ecore.EObject) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 37 with IArchimateRelationship

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));
        }
    }
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) IDiagramModel(com.archimatetool.model.IDiagramModel) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 38 with IArchimateRelationship

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));
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) Command(org.eclipse.gef.commands.Command) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Test(org.junit.Test)

Example 39 with IArchimateRelationship

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));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 40 with IArchimateRelationship

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());
}
Also used : IAssignmentRelationship(com.archimatetool.model.IAssignmentRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Aggregations

IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)74 Test (org.junit.Test)39 IArchimateElement (com.archimatetool.model.IArchimateElement)33 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)22 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)15 ArrayList (java.util.ArrayList)15 IArchimateConcept (com.archimatetool.model.IArchimateConcept)14 IDiagramModel (com.archimatetool.model.IDiagramModel)12 IArchimateModel (com.archimatetool.model.IArchimateModel)9 EObject (org.eclipse.emf.ecore.EObject)9 IIssue (com.archimatetool.hammer.validation.issues.IIssue)7 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)7 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)5 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)5 ErrorType (com.archimatetool.hammer.validation.issues.ErrorType)4 IFolder (com.archimatetool.model.IFolder)4 EClass (org.eclipse.emf.ecore.EClass)4 Command (org.eclipse.gef.commands.Command)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3