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);
}
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));
}
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));
}
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
}
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));
}
Aggregations