use of org.eclipse.ui.navigator.CommonDropAdapter in project n4js by eclipse.
the class GHOLD_101_WorkingSetsTest_PluginUITest method testDndSupport.
/**
*/
@Test
public void testDndSupport() throws CoreException {
final Collection<String> projectNames = newArrayList("A", "B", "C", "D", "E");
final IWorkspaceDescription workspaceDescription = ResourcesPlugin.getWorkspace().getDescription();
final boolean autoBuild = workspaceDescription.isAutoBuilding();
try {
// No need for the build at all.
workspaceDescription.setAutoBuilding(false);
for (final String projectName : projectNames) {
JavaProjectSetupUtil.createSimpleProject(projectName);
assertTrue("Project " + projectName + " is not accessible.", getProjectByName(projectName).isAccessible());
}
} finally {
workspaceDescription.setAutoBuilding(autoBuild);
}
activateWorkingSetManager(ManualAssociationAwareWorkingSetManager.class);
WorkingSetManager manager = broker.getActiveManager();
WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(manager);
List<WorkingSet> workingSets = newArrayList();
workingSets.add(new ManualAssociationWorkingSet(newArrayList(), "WS1", manager));
workingSets.add(new ManualAssociationWorkingSet(newArrayList(), "WS2", manager));
workingSets.add(new ManualAssociationWorkingSet(newArrayList(), "WS3", manager));
for (WorkingSet workingSet : workingSets) {
builder.add(workingSet);
}
workingSets.add(0, manager.getWorkingSets()[0]);
Diff<WorkingSet> diff = builder.build(Iterables.toArray(workingSets, WorkingSet.class), Iterables.toArray(workingSets, WorkingSet.class));
manager.updateState(diff);
waitForIdleState();
broker.refreshNavigator();
waitForIdleState();
commonViewer.expandToLevel(2);
waitForIdleState();
TreeItem[] treeItems = commonViewer.getTree().getItems();
final int expectedItemCount = workingSets.size();
assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
for (TreeItem item : treeItems) {
Object data = item.getData();
assertTrue("Expected instance of working set. Was: " + data, data instanceof WorkingSet);
WorkingSet workingSet = (WorkingSet) data;
if (WorkingSet.OTHERS_WORKING_SET_ID.equals(workingSet.getId())) {
assertEquals("Expected " + projectNames.size() + " elements. Got: " + item.getItemCount(), projectNames.size(), item.getItemCount());
} else {
assertEquals("Expected 0 elements. Got: " + item.getItemCount(), 0, item.getItemCount());
}
}
StructuredSelection selection = new StructuredSelection(getProjectsByName("A", "B", "C"));
commonViewer.setSelection(selection);
assertEquals(3, commonViewer.getTree().getSelection().length);
INavigatorDnDService dnDService = projectExplorer.getNavigatorContentService().getDnDService();
CommonDropAdapterAssistant[] dropAdapterAssistants = dnDService.findCommonDropAdapterAssistants(manager.getWorkingSets()[1], commonViewer.getStructuredSelection());
assertTrue(!Arrays2.isEmpty(dropAdapterAssistants));
N4JSProjectInWorkingSetDropAdapterAssistant[] n4DropAdapterAssistants = Arrays2.filter(dropAdapterAssistants, N4JSProjectInWorkingSetDropAdapterAssistant.class);
assertTrue(!Arrays2.isEmpty(n4DropAdapterAssistants));
N4JSProjectInWorkingSetDropAdapterAssistant assistant = n4DropAdapterAssistants[0];
CommonDropAdapter adapter = assistant.getCommonDropAdapter();
LocalSelectionTransfer.getTransfer().setSelection(commonViewer.getStructuredSelection());
assistant.handleDrop(adapter, null, manager.getWorkingSets()[1]);
waitForIdleState();
broker.refreshNavigator();
waitForIdleState();
commonViewer.expandToLevel(2);
waitForIdleState();
treeItems = commonViewer.getTree().getItems();
for (TreeItem item : treeItems) {
Object data = item.getData();
assertTrue("Expected instance of working set. Was: " + data, data instanceof WorkingSet);
WorkingSet workingSet = (WorkingSet) data;
if (WorkingSet.OTHERS_WORKING_SET_ID.equals(workingSet.getId())) {
assertEquals("Expected " + (projectNames.size() - 3) + " elements. Got: " + item.getItemCount(), projectNames.size() - 3, item.getItemCount());
} else if ("WS1".equals(workingSet.getId())) {
assertEquals("Expected 3 elements. Got: " + item.getItemCount(), 3, item.getItemCount());
} else {
assertEquals("Expected 0 elements. Got: " + item.getItemCount(), 0, item.getItemCount());
}
}
}
Aggregations