Search in sources :

Example 26 with IFolder

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

Example 27 with IFolder

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

the class DeleteCommandHandlerTests method testDelete_Folder_Deleted_SubElements.

@Test
public void testDelete_Folder_Deleted_SubElements() {
    // Sub-folder with elements
    Object[] folder = new Object[] { ArchimateModelUtils.getObjectByID(model, "0bd99416") };
    assertTrue(folder[0] instanceof IFolder);
    // sub-Elements that should be zapped
    String[] elementIDs = new String[] { // element
    "e836c6be", // element
    "b5742e18", // element
    "d1247cf1" };
    List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
    for (String id : elementIDs) {
        elements.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
    }
    // Delete top folder
    DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, folder);
    commandHandler.delete();
    // Is top folder deleted?
    assertNull(ArchimateModelUtils.getObjectByID(model, "0bd99416"));
    // Is sub folder deleted?
    assertNull(ArchimateModelUtils.getObjectByID(model, "02460ff1"));
    // Are elements deleted?
    for (IArchimateElement element : elements) {
        assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
        assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
    }
}
Also used : ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 28 with IFolder

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

the class DuplicateCommandHandlerTests method testDuplicateArchimateElements.

@Test
public void testDuplicateArchimateElements() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IFolder folder = model.getFolder(FolderType.BUSINESS);
    IArchimateElement element1 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    element1.setName("Actor 1");
    element1.setDocumentation("Doc 1");
    assertEquals(1, folder.getElements().size());
    assertSame(element1, folder.getElements().get(0));
    IArchimateElement element2 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    element2.setName("Actor 2");
    element2.setDocumentation("Doc 2");
    assertEquals(2, folder.getElements().size());
    assertSame(element2, folder.getElements().get(1));
    IArchimateRelationship relation = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getAssociationRelationship());
    relation.connect(element1, element2);
    assertTrue(element1.getSourceRelationships().contains(relation));
    assertTrue(element2.getTargetRelationships().contains(relation));
    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { element1, element2 });
    handler.duplicate();
    assertEquals(4, folder.getElements().size());
    assertSame(element1, folder.getElements().get(0));
    assertSame(element2, folder.getElements().get(1));
    IArchimateElement copy1 = (IArchimateElement) folder.getElements().get(2);
    assertNotSame(element1, copy1);
    assertNotEquals(element1.getId(), copy1.getId());
    assertEquals(element1.getName() + " (copy)", copy1.getName());
    assertEquals(element1.getDocumentation(), copy1.getDocumentation());
    IArchimateElement copy2 = (IArchimateElement) folder.getElements().get(3);
    assertNotSame(element2, copy2);
    assertNotEquals(element2.getId(), copy2.getId());
    assertEquals(element2.getName() + " (copy)", copy2.getName());
    assertEquals(element2.getDocumentation(), copy2.getDocumentation());
    assertTrue(copy1.getSourceRelationships().isEmpty());
    assertTrue(copy1.getTargetRelationships().isEmpty());
    assertTrue(copy2.getSourceRelationships().isEmpty());
    assertTrue(copy2.getTargetRelationships().isEmpty());
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 29 with IFolder

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

the class CommandsTests method testDeleteFolderCommand.

@Test
public void testDeleteFolderCommand() {
    IFolder folder = (IFolder) tm.getObjectByID("403e5717");
    assertNotNull(folder);
    IFolder parent = (IFolder) folder.eContainer();
    DeleteFolderCommand cmd = new DeleteFolderCommand(folder);
    cmd.execute();
    assertNull(folder.eContainer());
    assertFalse(parent.getFolders().contains(folder));
    cmd.undo();
    assertEquals(1, parent.getFolders().indexOf(folder));
}
Also used : IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 30 with IFolder

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

the class ArchimateModelTests method testGetDefaultFolderForWrongElement.

@Test
public void testGetDefaultFolderForWrongElement() {
    // Null
    IFolder folder = model.getDefaultFolderForObject(null);
    assertNull(folder);
    // Folder
    EObject element = IArchimateFactory.eINSTANCE.createFolder();
    folder = model.getDefaultFolderForObject(element);
    assertNull(folder);
    element = IArchimateFactory.eINSTANCE.createSketchModelActor();
    folder = model.getDefaultFolderForObject(element);
    assertNull(folder);
    element = IArchimateFactory.eINSTANCE.createSketchModelSticky();
    folder = model.getDefaultFolderForObject(element);
    assertNull(folder);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Aggregations

IFolder (com.archimatetool.model.IFolder)41 Test (org.junit.Test)19 EObject (org.eclipse.emf.ecore.EObject)13 IArchimateElement (com.archimatetool.model.IArchimateElement)11 IArchimateModel (com.archimatetool.model.IArchimateModel)11 ArrayList (java.util.ArrayList)6 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)5 IDiagramModel (com.archimatetool.model.IDiagramModel)5 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)4 Command (org.eclipse.gef.commands.Command)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 File (java.io.File)3 ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)2 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)2 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)2