Search in sources :

Example 41 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class CSVExporterTests method testSort.

@Test
public void testSort() {
    IArchimateElement element1 = IArchimateFactory.eINSTANCE.createDevice();
    element1.setName("AA");
    IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    element2.setName("ZZ");
    IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    element3.setName("AA");
    IArchimateElement element4 = IArchimateFactory.eINSTANCE.createApplicationCollaboration();
    element4.setName("ZZ");
    List<IArchimateConcept> list = new ArrayList<IArchimateConcept>();
    list.add(element1);
    list.add(element2);
    list.add(element3);
    list.add(element4);
    exporter.sort(list);
    assertEquals(element4, list.get(0));
    assertEquals(element3, list.get(1));
    assertEquals(element2, list.get(2));
    assertEquals(element1, list.get(3));
}
Also used : ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateConcept(com.archimatetool.model.IArchimateConcept) Test(org.junit.Test)

Example 42 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class CSVImporterTests method testGetProperty.

@Test
public void testGetProperty() {
    IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
    IProperty property = IArchimateFactory.eINSTANCE.createProperty();
    property.setKey("key");
    property.setValue("value");
    element.getProperties().add(property);
    assertEquals(property, importer.getProperty(element, "key"));
    assertNull(importer.getProperty(element, "key2"));
}
Also used : IProperty(com.archimatetool.model.IProperty) IArchimateElement(com.archimatetool.model.IArchimateElement) Test(org.junit.Test)

Example 43 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class ArchimateContainerEditPolicy method createNewConnectionCommands.

/**
 * When Archimate child objects are dragged out of a parent Archimate object check to see if new connections should be created
 *
 * TODO A3: If O1--C1--O2 and in parent. C1 is also connected to parent (and hidden).
 *          O1 or O2 is removed from parent - should add connection from C1 to parent?
 *          Or should it be only when O1 AND O2 are removed from parent?
 */
void createNewConnectionCommands(IDiagramModelArchimateObject parentObject, List<?> childEditParts, CompoundCommand command) {
    IArchimateElement parentElement = parentObject.getArchimateElement();
    for (Object o : childEditParts) {
        IDiagramModelObject child = (IDiagramModelObject) ((EditPart) o).getModel();
        // If it's an Archimate type child object...
        if (child instanceof IDiagramModelArchimateObject) {
            IDiagramModelArchimateObject childObject = (IDiagramModelArchimateObject) child;
            IArchimateElement childElement = childObject.getArchimateElement();
            // See if there are any (nested type) relationships between parent element and child element...
            for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
                if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                    // And there's not a connection already there then add one
                    if (!DiagramModelUtils.hasDiagramModelArchimateConnection(parentObject, childObject, relation)) {
                        command.add(new CreateDiagramArchimateConnectionCommand(parentObject, childObject, relation));
                    }
                }
            }
        }
    }
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 44 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class ArchimateDNDEditPolicy method getDropCommand.

@Override
protected Command getDropCommand(DiagramDropRequest request) {
    if (!(request.getData() instanceof IStructuredSelection)) {
        return null;
    }
    // XY drop point
    Point pt = getDropLocation(request);
    int origin = pt.x;
    int x = pt.x;
    int y = pt.y;
    fElementsToAdd = new ArrayList<IArchimateElement>();
    fRelationsToAdd = new ArrayList<IArchimateRelationship>();
    fDiagramRefsToAdd = new ArrayList<IDiagramModel>();
    // Gather an actual list of elements dragged onto the container, omitting duplicates and anything already on the diagram
    Object[] objects = ((IStructuredSelection) request.getData()).toArray();
    getElementsToAdd(objects);
    // Store the Diagram Model Components that will be added in this list
    List<IDiagramModelArchimateComponent> diagramComponentsThatWereAdded = new ArrayList<IDiagramModelArchimateComponent>();
    // Create a Compound Command - it has to be Non-Notifying or it's too slow (tested with Bill's UoB model!)
    CompoundCommand result = new NonNotifyingCompoundCommand(Messages.ArchimateDNDEditPolicy_0);
    // Add the Commands adding the Elements first
    for (IArchimateElement element : fElementsToAdd) {
        // Add Diagram object
        IDiagramModelArchimateObject dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject(element);
        // Set location
        dmo.getBounds().setLocation(x, y);
        // Store it
        diagramComponentsThatWereAdded.add(dmo);
        // Add Command
        result.add(new AddDiagramObjectCommand(getTargetContainer(), dmo));
        // Increase x,y
        x += 150;
        if (x > origin + 400) {
            x = origin;
            y += 100;
        }
    }
    // Then any Diagram Model Ref Commands
    for (IDiagramModel diagramModel : fDiagramRefsToAdd) {
        result.add(new AddDiagramModelReferenceCommand(getTargetContainer(), diagramModel, x, y));
        x += 150;
        if (x > origin + 400) {
            x = origin;
            y += 100;
        }
    }
    // Add selected Relations to create connections to those elements on the diagram that don't already have them
    for (IArchimateRelationship relation : fRelationsToAdd) {
        // Find existing source & target components on the diagram that the new connection will link to
        List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
        List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
        for (IDiagramModelComponent dcSource : sources) {
            for (IDiagramModelComponent dcTarget : targets) {
                if (dcSource instanceof IConnectable && dcTarget instanceof IConnectable) {
                    // Add a new connection between dcSource & dcTarget if there isn't already one on the diagram
                    if (dcTarget != dcSource && !DiagramModelUtils.hasDiagramModelArchimateConnection((IConnectable) dcSource, (IConnectable) dcTarget, relation)) {
                        // Check that source or target is not a hiden connection
                        if (!((dcSource instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcSource)) || (dcTarget instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcTarget)))) {
                            AddDiagramArchimateConnectionCommand cmd = new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dcTarget, relation);
                            result.add(cmd);
                            // Store it
                            diagramComponentsThatWereAdded.add(cmd.getConnection());
                        }
                    }
                }
            }
        }
    }
    // Whether to add connections to elements
    Boolean value = (Boolean) request.getExtendedData().get(ArchimateDiagramTransferDropTargetListener.ADD_ELEMENT_CONNECTIONS);
    boolean addConnectionsToElements = value != null && value.booleanValue();
    // Newly added concepts will need new connections to both existing and newly added concepts
    for (IDiagramModelArchimateComponent dmComponent : diagramComponentsThatWereAdded) {
        IArchimateConcept archimateConcept = dmComponent.getArchimateConcept();
        for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(archimateConcept)) {
            /*
                 * If the user holds down the Copy key (Ctrl on win/lnx, Alt on Mac) then linked connections
                 * are not added on drag and drop. However, any selected relations' linked objects are added.
                 */
            if (!addConnectionsToElements && !fRelationsToAdd.contains(relation)) {
                continue;
            }
            // Find existing objects
            List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
            List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
            // Add new ones too
            for (IDiagramModelArchimateComponent dmComponent2 : diagramComponentsThatWereAdded) {
                if (dmComponent != dmComponent2) {
                    IArchimateConcept archimateConcept2 = dmComponent2.getArchimateConcept();
                    if (archimateConcept2 == relation.getSource()) {
                        // Only need to add sources, not targets
                        sources.add(dmComponent2);
                    }
                }
            }
            // Make the Commands...
            for (IDiagramModelComponent dcSource : sources) {
                if (dcSource instanceof IConnectable && archimateConcept == relation.getTarget()) {
                    result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dmComponent, relation));
                }
            }
            for (IDiagramModelComponent dcTarget : targets) {
                if (dcTarget instanceof IConnectable && archimateConcept == relation.getSource()) {
                    result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dmComponent, (IConnectable) dcTarget, relation));
                }
            }
        }
    }
    // Then, if adding to an Archimate container type to create nesting, ask whether to add new relations if none exist...
    if (ConnectionPreferences.createRelationWhenAddingModelTreeElement() && getTargetContainer() instanceof IDiagramModelArchimateObject) {
        List<IDiagramModelArchimateObject> diagramObjectsThatWereAdded = new ArrayList<IDiagramModelArchimateObject>();
        for (IDiagramModelArchimateComponent dmc : diagramComponentsThatWereAdded) {
            if (dmc instanceof IDiagramModelArchimateObject) {
                diagramObjectsThatWereAdded.add((IDiagramModelArchimateObject) dmc);
            }
        }
        Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject) getTargetContainer(), diagramObjectsThatWereAdded);
        result.add(cmd);
    }
    // return the full compound command
    return result;
}
Also used : CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) ArrayList(java.util.ArrayList) AddDiagramObjectCommand(com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AddDiagramModelReferenceCommand(com.archimatetool.editor.diagram.commands.AddDiagramModelReferenceCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IConnectable(com.archimatetool.model.IConnectable) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) AddDiagramModelReferenceCommand(com.archimatetool.editor.diagram.commands.AddDiagramModelReferenceCommand) AddDiagramObjectCommand(com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand) CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) Command(org.eclipse.gef.commands.Command) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 45 with IArchimateElement

use of com.archimatetool.model.IArchimateElement 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)

Aggregations

IArchimateElement (com.archimatetool.model.IArchimateElement)92 Test (org.junit.Test)57 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)33 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)30 ArrayList (java.util.ArrayList)19 IDiagramModel (com.archimatetool.model.IDiagramModel)16 IArchimateModel (com.archimatetool.model.IArchimateModel)14 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)13 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)11 IFolder (com.archimatetool.model.IFolder)11 EObject (org.eclipse.emf.ecore.EObject)11 IIssue (com.archimatetool.hammer.validation.issues.IIssue)8 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)6 Command (org.eclipse.gef.commands.Command)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)5 WarningType (com.archimatetool.hammer.validation.issues.WarningType)4 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3