Search in sources :

Example 6 with CommonDropAdapterAssistant

use of org.eclipse.ui.navigator.CommonDropAdapterAssistant 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());
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) CommonDropAdapter(org.eclipse.ui.navigator.CommonDropAdapter) N4JSProjectInWorkingSetDropAdapterAssistant(org.eclipse.n4js.ui.workingsets.internal.N4JSProjectInWorkingSetDropAdapterAssistant) ProjectTypeAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager) ProjectNameFilterAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) INavigatorDnDService(org.eclipse.ui.navigator.INavigatorDnDService) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) CommonDropAdapterAssistant(org.eclipse.ui.navigator.CommonDropAdapterAssistant) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ProjectNameFilterWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet) ProjectTypeWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) Test(org.junit.Test)

Aggregations

CommonDropAdapterAssistant (org.eclipse.ui.navigator.CommonDropAdapterAssistant)6 INavigatorDnDService (org.eclipse.ui.navigator.INavigatorDnDService)3 RepositoryDropAssistant (org.talend.mdm.repository.core.dnd.RepositoryDropAssistant)2 IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)1 IStatus (org.eclipse.core.runtime.IStatus)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ManualAssociationAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager)1 ManualAssociationWorkingSet (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)1 ProjectNameFilterAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager)1 ProjectNameFilterWorkingSet (org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet)1 ProjectTypeAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager)1 ProjectTypeWorkingSet (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet)1 WorkingSet (org.eclipse.n4js.ui.workingsets.WorkingSet)1 WorkingSetDiffBuilder (org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder)1 WorkingSetManager (org.eclipse.n4js.ui.workingsets.WorkingSetManager)1 N4JSProjectInWorkingSetDropAdapterAssistant (org.eclipse.n4js.ui.workingsets.internal.N4JSProjectInWorkingSetDropAdapterAssistant)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 NavigatorSafeRunnable (org.eclipse.ui.internal.navigator.NavigatorSafeRunnable)1 CommonDropAdapter (org.eclipse.ui.navigator.CommonDropAdapter)1