Search in sources :

Example 11 with IFolder

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

the class TreeModelViewerDragDropHandlerTests method testIsValidDropTarget.

@Test
public void testIsValidDropTarget() {
    IFolder folder = IArchimateFactory.eINSTANCE.createFolder();
    IArchimateElement childElement = IArchimateFactory.eINSTANCE.createBusinessActor();
    folder.getElements().add(childElement);
    LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(new Object[] { childElement }));
    // Can only drop onto a folder
    DropTargetEvent event = createMockDropTargetEvent(folder);
    assertTrue(dragHandler.isValidDropTarget(event));
    // And not something else
    event = createMockDropTargetEvent(childElement);
    assertFalse(dragHandler.isValidDropTarget(event));
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IArchimateElement(com.archimatetool.model.IArchimateElement) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 12 with IFolder

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

the class TreeModelViewerDragDropHandlerTests method testDoDropOperation.

@Test
public void testDoDropOperation() {
    // Source
    IFolder sourceParentFolder = model.getFolder(FolderType.BUSINESS);
    IArchimateElement childElement = IArchimateFactory.eINSTANCE.createBusinessActor();
    sourceParentFolder.getElements().add(childElement);
    assertTrue(sourceParentFolder.getElements().contains(childElement));
    // Target
    IFolder targetParentFolder = model.getFolder(FolderType.APPLICATION);
    assertTrue(targetParentFolder.getElements().isEmpty());
    assertTrue(targetParentFolder.getFolders().isEmpty());
    // Set up a mock DropTargetEvent for the DropOperation
    DropTargetEvent event = createMockDropTargetEvent(targetParentFolder);
    // Set the selection of elements we want to DnD
    LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(new Object[] { childElement }));
    // And call the drop method
    dragHandler.doDropOperation(event);
    assertTrue(sourceParentFolder.getElements().isEmpty());
    assertTrue(targetParentFolder.getElements().contains(childElement));
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IArchimateElement(com.archimatetool.model.IArchimateElement) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 13 with IFolder

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

the class TreeModelViewerDragDropHandlerTests method moveTreeObjects_DropChildElementsOntoSameParentIsSame.

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

Example 14 with IFolder

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

the class TreeModelViewerDragDropHandlerTests method testHasCommonAncestorFolder.

@Test
public void testHasCommonAncestorFolder() {
    // Test with folders and elements that have a root model
    IFolder businessFolder = model.getFolder(FolderType.BUSINESS);
    IFolder appFolder = model.getFolder(FolderType.APPLICATION);
    __doTestHasCommonAncestorFolderWithTheseFolders(businessFolder, appFolder);
    // Test with folders and elements that have no root model
    IFolder parent1 = IArchimateFactory.eINSTANCE.createFolder();
    IFolder parent2 = IArchimateFactory.eINSTANCE.createFolder();
    __doTestHasCommonAncestorFolderWithTheseFolders(parent1, parent2);
}
Also used : IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 15 with IFolder

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

the class TreeModelViewerDragDropHandlerTests method moveTreeObjects_DropChildFolderOntoSameParentIsSame.

/**
 * The famous DnD bug of drag and dropping a child folder onto its parent (fixed in Archi 2.4.1)
 */
@Test
public void moveTreeObjects_DropChildFolderOntoSameParentIsSame() {
    // Add a child folder to a parent folder
    IFolder parentFolder = model.getFolder(FolderType.BUSINESS);
    IFolder childFolder = IArchimateFactory.eINSTANCE.createFolder();
    parentFolder.getFolders().add(childFolder);
    // Check all is well
    assertEquals(1, parentFolder.getFolders().size());
    assertTrue(parentFolder.getFolders().contains(childFolder));
    assertTrue(parentFolder.getElements().isEmpty());
    // Move child folder to the same target parent folder
    dragHandler.moveTreeObjects(parentFolder, new Object[] { childFolder });
    // Should be the same
    assertEquals(1, parentFolder.getFolders().size());
    assertTrue(parentFolder.getFolders().contains(childFolder));
    // Elements should not be affected
    assertTrue(parentFolder.getElements().isEmpty());
}
Also used : 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