Search in sources :

Example 31 with IArchimateElement

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

the class PropertiesLabelProviderTests method testGetAdaptable.

@Test
public void testGetAdaptable() {
    IAdaptable adaptable = new IAdaptable() {

        IArchimateElement element = IArchimateFactory.eINSTANCE.createArtifact();

        @SuppressWarnings({ "rawtypes", "unchecked" })
        public Object getAdapter(Class adapter) {
            if (adapter != null && (adapter.isInstance(element) || adapter.isInstance(this))) {
                return element;
            }
            return null;
        }
    };
    String text = provider.getText(new StructuredSelection(adaptable));
    assertEquals("Artifact", text);
    Image image = provider.getImage(new StructuredSelection(adaptable));
    assertNotNull(image);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IArchimateElement(com.archimatetool.model.IArchimateElement) BeforeClass(org.junit.BeforeClass) Image(org.eclipse.swt.graphics.Image) Test(org.junit.Test)

Example 32 with IArchimateElement

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

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

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

the class TreeModelViewerDragDropHandlerTests method testCanDropObject.

@Test
public void testCanDropObject() {
    IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    // Null tree item is no good
    assertFalse(dragHandler.canDropObject(e1, null));
    // Cannot drop onto itself
    DropTargetEvent event = createMockDropTargetEvent(e1);
    assertFalse(dragHandler.canDropObject(e1, (TreeItem) event.item));
    // OK
    assertTrue(dragHandler.canDropObject(e2, (TreeItem) event.item));
// Can't test "If moving a folder check that target folder is not a descendant of the source folder"
// Because parent tree items are created by the system
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) IArchimateElement(com.archimatetool.model.IArchimateElement) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) Test(org.junit.Test)

Example 35 with IArchimateElement

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

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