Search in sources :

Example 61 with IArchimateElement

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

the class DuplicateElementChecker method findDuplicateNamesElements.

List<IIssue> findDuplicateNamesElements() {
    List<IIssue> issues = new ArrayList<IIssue>();
    Set<IArchimateElement> dupes = new LinkedHashSet<IArchimateElement>();
    for (int i = 0; i < fArchimateElements.size(); i++) {
        for (int j = i + 1; j < fArchimateElements.size(); j++) {
            IArchimateElement element1 = fArchimateElements.get(i);
            IArchimateElement element2 = fArchimateElements.get(j);
            if (isDuplicate(element1, element2)) {
                dupes.add(element1);
                dupes.add(element2);
            }
        }
    }
    for (IArchimateElement element : dupes) {
        String description = NLS.bind(DESCRIPTION, new Object[] { element.getName(), ArchiLabelProvider.INSTANCE.getDefaultName(element.eClass()) });
        IIssue issue = new WarningType(NAME, description, EXPLANATION, element);
        issues.add(issue);
    }
    return issues;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) WarningType(com.archimatetool.hammer.validation.issues.WarningType) IArchimateElement(com.archimatetool.model.IArchimateElement) IIssue(com.archimatetool.hammer.validation.issues.IIssue)

Example 62 with IArchimateElement

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

the class NestedElementsChecker method isNestedWithoutValidRelation.

boolean isNestedWithoutValidRelation(IDiagramModelArchimateObject parent, IDiagramModelArchimateObject child) {
    IArchimateElement parentElement = parent.getArchimateElement();
    IArchimateElement childElement = child.getArchimateElement();
    // Ignore nested Junctions
    if (childElement instanceof IJunction) {
        return false;
    }
    // Specialization relationship goes the other way around
    for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
        if (relation.getSource() == childElement) {
            if (relation instanceof ISpecializationRelationship) {
                return false;
            }
        }
    }
    // Other relationships
    for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
        if (relation.getTarget() == childElement) {
            if (relation instanceof ICompositionRelationship || relation instanceof IAggregationRelationship || relation instanceof IAssignmentRelationship || relation instanceof IRealizationRelationship || relation instanceof IAccessRelationship) {
                return false;
            }
        }
    }
    return true;
}
Also used : ICompositionRelationship(com.archimatetool.model.ICompositionRelationship) IRealizationRelationship(com.archimatetool.model.IRealizationRelationship) ISpecializationRelationship(com.archimatetool.model.ISpecializationRelationship) IAssignmentRelationship(com.archimatetool.model.IAssignmentRelationship) IAggregationRelationship(com.archimatetool.model.IAggregationRelationship) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IAccessRelationship(com.archimatetool.model.IAccessRelationship) IJunction(com.archimatetool.model.IJunction)

Example 63 with IArchimateElement

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

the class TreeModelViewerDragDropHandlerTests method __doTestHasCommonAncestorFolderWithTheseFolders.

private void __doTestHasCommonAncestorFolderWithTheseFolders(IFolder parentFolder1, IFolder parentFolder2) {
    /*
        
        businessFolder 
                   |-- f2
                        |-- e1
                   |-- f3
                        |-- e2
        appFolder
                   |-- f4
                        |-- e3
                   |-- f5
                        |-- e4
         
         */
    IFolder f2 = IArchimateFactory.eINSTANCE.createFolder();
    IFolder f3 = IArchimateFactory.eINSTANCE.createFolder();
    parentFolder1.getFolders().add(f2);
    parentFolder1.getFolders().add(f3);
    IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    f2.getElements().add(e1);
    IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    f3.getElements().add(e2);
    IFolder f4 = IArchimateFactory.eINSTANCE.createFolder();
    IFolder f5 = IArchimateFactory.eINSTANCE.createFolder();
    parentFolder2.getFolders().add(f4);
    parentFolder2.getFolders().add(f5);
    IArchimateElement e3 = IArchimateFactory.eINSTANCE.createApplicationComponent();
    f4.getElements().add(e3);
    IArchimateElement e4 = IArchimateFactory.eINSTANCE.createApplicationComponent();
    f5.getElements().add(e4);
    // Same common ancestor
    assertTrue(dragHandler.hasCommonAncestorFolder(f2, f3));
    assertTrue(dragHandler.hasCommonAncestorFolder(f2, e1));
    assertTrue(dragHandler.hasCommonAncestorFolder(f3, e1));
    assertTrue(dragHandler.hasCommonAncestorFolder(e1, e2));
    // Different common ancestors
    assertFalse(dragHandler.hasCommonAncestorFolder(f2, f4));
    assertFalse(dragHandler.hasCommonAncestorFolder(f3, f5));
    assertFalse(dragHandler.hasCommonAncestorFolder(f3, e3));
    assertFalse(dragHandler.hasCommonAncestorFolder(e1, e4));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IFolder(com.archimatetool.model.IFolder)

Example 64 with IArchimateElement

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

the class TreeModelViewerDragDropHandlerTests method testIsValidTreeSelection.

@Test
public void testIsValidTreeSelection() {
    // Null selection is not valid
    StructuredSelection selection = null;
    assertFalse(dragHandler.isValidTreeSelection(selection));
    // Set up some data
    IFolder userFolder = IArchimateFactory.eINSTANCE.createFolder();
    model.getFolder(FolderType.DIAGRAMS).getFolders().add(userFolder);
    IFolder businessFolder = model.getFolder(FolderType.BUSINESS);
    IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    businessFolder.getElements().add(e1);
    IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    businessFolder.getElements().add(e2);
    // Elements from the same root parent are OK
    selection = new StructuredSelection(new Object[] { e1, e2 });
    assertTrue(dragHandler.isValidTreeSelection(selection));
    // Can't DnD a model
    selection = new StructuredSelection(new Object[] { model });
    assertFalse(dragHandler.isValidTreeSelection(selection));
    // Can DnD a user folder
    selection = new StructuredSelection(new Object[] { userFolder });
    assertTrue(dragHandler.isValidTreeSelection(selection));
    // Can't DnD a system folder
    selection = new StructuredSelection(new Object[] { businessFolder });
    assertFalse(dragHandler.isValidTreeSelection(selection));
    // Can't DnD Mixed parent models
    IArchimateModel model2 = IArchimateFactory.eINSTANCE.createArchimateModel();
    model2.setDefaults();
    IArchimateElement e3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    model2.getFolder(FolderType.BUSINESS).getElements().add(e3);
    selection = new StructuredSelection(new Object[] { e1, e3 });
    assertFalse(dragHandler.isValidTreeSelection(selection));
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 65 with IArchimateElement

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

the class TreeModelViewerDragDropHandlerTests method moveTreeObjects_DropChildElementsOntoDifferentParent.

/**
 * Drag and dropping child elements onto different parent
 */
@Test
public void moveTreeObjects_DropChildElementsOntoDifferentParent() {
    // Add child elements to a  folder
    IFolder sourceParentFolder = model.getFolder(FolderType.BUSINESS);
    IArchimateElement childElement1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    sourceParentFolder.getElements().add(childElement1);
    IArchimateElement childElement2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    sourceParentFolder.getElements().add(childElement2);
    // Check all is well
    assertEquals(2, sourceParentFolder.getElements().size());
    assertEquals(childElement1, sourceParentFolder.getElements().get(0));
    assertEquals(childElement2, sourceParentFolder.getElements().get(1));
    // New target parent folder and all is well
    IFolder targetParentFolder = model.getFolder(FolderType.APPLICATION);
    assertTrue(targetParentFolder.getFolders().isEmpty());
    assertTrue(targetParentFolder.getElements().isEmpty());
    // Move child element to the different target parent folder
    dragHandler.moveTreeObjects(targetParentFolder, new Object[] { childElement1, childElement2 });
    // Source should be empty
    assertTrue(sourceParentFolder.getElements().isEmpty());
    // Shouldn't affect folders
    assertEquals(2, targetParentFolder.getElements().size());
    // Target should be populated
    assertEquals(childElement1, targetParentFolder.getElements().get(0));
    assertEquals(childElement2, targetParentFolder.getElements().get(1));
    assertTrue(targetParentFolder.getFolders().isEmpty());
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

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