Search in sources :

Example 16 with WorkingSet

use of org.eclipse.n4js.ui.workingsets.WorkingSet in project n4js by eclipse.

the class N4JSProjectInWorkingSetDropAdapterAssistant method handleDrop.

@Override
public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent dropTargetEvent, Object target) {
    WorkingSet oldTarget = (WorkingSet) target;
    WorkingSetManager manager = oldTarget.getWorkingSetManager();
    List<WorkingSet> allItems = newArrayList(manager.getAllWorkingSets());
    List<WorkingSet> visibleItems = newArrayList(manager.getWorkingSets());
    WorkingSetDiffBuilder diffBuilder = new WorkingSetDiffBuilder(manager);
    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection instanceof ITreeSelection) {
        ManualAssociationWorkingSet oldSource = null;
        for (TreePath path : ((ITreeSelection) selection).getPaths()) {
            IProject project = ((IAdaptable) path.getLastSegment()).getAdapter(IProject.class);
            if (project != null) {
                if (!(target instanceof ManualAssociationWorkingSet)) {
                    return CANCEL_STATUS;
                }
                if (!ManualAssociationAwareWorkingSetManager.class.getName().equals(manager.getId())) {
                    return CANCEL_STATUS;
                }
                if (!workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
                    Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
                    projectNames.add(project.getName());
                    ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
                    int allIndex = indexOfById(oldTarget, allItems);
                    allItems.remove(allIndex);
                    allItems.add(allIndex, newTarget);
                    int visibleIndex = indexOfById(oldTarget, visibleItems);
                    if (visibleIndex >= 0) {
                        visibleItems.remove(visibleIndex);
                        visibleItems.add(visibleIndex, newTarget);
                    }
                    diffBuilder.edit(oldTarget, newTarget);
                    oldTarget = newTarget;
                }
                // Check if our top-level element is a working set so that we can perform a move
                if (path.getFirstSegment() instanceof ManualAssociationWorkingSet) {
                    if (oldSource == null) {
                        oldSource = ((ManualAssociationWorkingSet) path.getFirstSegment());
                    }
                    if (oldSource != null && !OTHERS_WORKING_SET_ID.equals(oldSource.getId())) {
                        Collection<String> projectNames = newHashSet(oldSource.getAssociatedProjectNames());
                        projectNames.remove(project.getName());
                        ManualAssociationWorkingSet newSource = new ManualAssociationWorkingSet(projectNames, oldSource.getId(), manager);
                        int allIndex = indexOfById(oldSource, allItems);
                        allItems.remove(allIndex);
                        allItems.add(allIndex, newSource);
                        int visibleIndex = indexOfById(oldSource, visibleItems);
                        if (visibleIndex >= 0) {
                            visibleItems.remove(visibleIndex);
                            visibleItems.add(visibleIndex, newSource);
                        }
                        diffBuilder.edit(oldSource, newSource);
                        oldSource = newSource;
                    }
                }
            } else if (path.getLastSegment() instanceof WorkingSet) {
                WorkingSet movedWorkingSet = (WorkingSet) path.getLastSegment();
                int sourceVisibleIndex = indexOfById(movedWorkingSet, visibleItems);
                int sourceAllIndex = indexOfById(movedWorkingSet, allItems);
                if (sourceVisibleIndex == -1 || sourceAllIndex == -1) {
                    return CANCEL_STATUS;
                }
                final Object currentTarget = getCommonDropAdapter().getCurrentTarget();
                if (currentTarget instanceof WorkingSet) {
                    int targetVisibleIndex = indexOfById((WorkingSet) currentTarget, visibleItems);
                    int targetAllIndex = indexOfById((WorkingSet) currentTarget, allItems);
                    if (targetVisibleIndex == -1 || targetAllIndex == -1) {
                        return CANCEL_STATUS;
                    }
                    if (getCommonDropAdapter().getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) {
                        targetVisibleIndex++;
                        targetAllIndex++;
                    }
                    WorkingSet visibleRemoved = visibleItems.remove(sourceVisibleIndex);
                    visibleItems.add(sourceVisibleIndex >= targetVisibleIndex ? targetVisibleIndex : targetVisibleIndex - 1, visibleRemoved);
                    WorkingSet allRemoved = allItems.remove(sourceAllIndex);
                    allItems.add(sourceAllIndex >= targetAllIndex ? targetAllIndex : targetAllIndex - 1, allRemoved);
                } else {
                    return CANCEL_STATUS;
                }
            }
        }
    } else if (selection instanceof IStructuredSelection) {
        for (Object item : ((IStructuredSelection) selection).toArray()) {
            IProject project = ((IAdaptable) item).getAdapter(IProject.class);
            if (project != null && !workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
                Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
                projectNames.add(project.getName());
                ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
                allItems.remove(oldTarget);
                allItems.add(newTarget);
                if (visibleItems.remove(oldTarget)) {
                    visibleItems.add(newTarget);
                }
                diffBuilder.edit(oldTarget, newTarget);
                oldTarget = newTarget;
            }
        }
    }
    WorkingSet[] newItems = Iterables.toArray(visibleItems, WorkingSet.class);
    WorkingSet[] newAllItems = Iterables.toArray(allItems, WorkingSet.class);
    Diff<WorkingSet> diff = diffBuilder.build(newItems, newAllItems);
    if (!diff.isEmpty()) {
        manager.updateState(diff);
        manager.saveState(new NullProgressMonitor());
        workingSetManagerBroker.refreshNavigator();
    }
    return OK_STATUS;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) IProject(org.eclipse.core.resources.IProject) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) TreePath(org.eclipse.jface.viewers.TreePath) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ISelection(org.eclipse.jface.viewers.ISelection) Collection(java.util.Collection) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)

Example 17 with WorkingSet

use of org.eclipse.n4js.ui.workingsets.WorkingSet 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)

Example 18 with WorkingSet

use of org.eclipse.n4js.ui.workingsets.WorkingSet in project n4js by eclipse.

the class GHOLD_101_WorkingSetsTest_PluginUITest method testHideShowWorkingSets.

/**
 */
@Test
public void testHideShowWorkingSets() {
    activateWorkingSetManager(ProjectTypeAwareWorkingSetManager.class);
    TreeItem[] treeItems = commonViewer.getTree().getItems();
    final int expectedItemCount = ProjectType.values().length + 1;
    assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
    List<ProjectTypeWorkingSet> workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
    assertEquals("Mismatching number of working sets.", expectedItemCount, workingSets.size());
    List<ProjectTypeWorkingSet> workingSetsToHide = workingSets;
    final HideWorkingSetAction hideAction = new HideWorkingSetAction();
    commonViewer.setSelection(new StructuredSelection(workingSets.toArray()));
    waitForIdleState();
    treeItems = commonViewer.getTree().getItems();
    final List<ProjectTypeWorkingSet> selectedWorkingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
    assertEquals(workingSetsToHide, selectedWorkingSets);
    hideAction.selectionChanged(commonViewer.getStructuredSelection());
    waitForIdleState();
    assertFalse("Expected disabled action.", hideAction.isEnabled());
    workingSetsToHide = newArrayList(workingSets.subList(0, 3));
    commonViewer.setSelection(new StructuredSelection(workingSetsToHide.toArray()));
    hideAction.selectionChanged(commonViewer.getStructuredSelection());
    waitForIdleState();
    assertTrue("Expected enabled action.", hideAction.isEnabled());
    hideAction.run();
    waitForIdleState();
    treeItems = commonViewer.getTree().getItems();
    workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
    assertEquals("Mismatching number of working sets.", expectedItemCount - workingSetsToHide.size(), workingSets.size());
    for (final WorkingSet workingSet : workingSetsToHide) {
        assertTrue("Working set must not be visible in the navigator: " + workingSet, !workingSets.contains(workingSet));
    }
    IContributionItem showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
    assertNotNull("Expected visible toolbar item, since there are hidden working sets.", showHiddenWorkingSetsItem);
    assertTrue("Expected a type of " + ActionContributionItem.class, showHiddenWorkingSetsItem instanceof ActionContributionItem);
    final IAction action = ((ActionContributionItem) showHiddenWorkingSetsItem).getAction();
    assertTrue("Expected a type of " + ShowHiddenWorkingSetsDropDownAction.class, action instanceof ShowHiddenWorkingSetsDropDownAction);
    final ShowHiddenWorkingSetsDropDownAction showHiddenWorkingSetsAction = (ShowHiddenWorkingSetsDropDownAction) action;
    Menu menu = showHiddenWorkingSetsAction.getMenu(commonViewer.getControl());
    assertTrue("Expected " + workingSetsToHide.size() + " menu item plus a separator plus an item for showing all hidden elements.", workingSetsToHide.size() + 2 == menu.getItemCount());
    menu.getItem(0).notifyListeners(SWT.Selection, null);
    waitForIdleState();
    workingSetsToHide.remove(0);
    treeItems = commonViewer.getTree().getItems();
    workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
    assertEquals("Mismatching number of working sets.", expectedItemCount - workingSetsToHide.size(), workingSets.size());
    menu = showHiddenWorkingSetsAction.getMenu(commonViewer.getControl());
    assertTrue("Expected " + workingSetsToHide.size() + " menu item plus a separator plus an item for showing all hidden elements.", workingSetsToHide.size() + 2 == menu.getItemCount());
    menu.getItem(menu.getItemCount() - 1).notifyListeners(SWT.Selection, null);
    waitForIdleState();
    treeItems = commonViewer.getTree().getItems();
    assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
    showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
    assertNull("Expected not visible toolbar item, since all working sets are visible.", showHiddenWorkingSetsItem);
    treeItems = commonViewer.getTree().getItems();
    assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
    workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
    workingSetsToHide = newArrayList(workingSets.subList(0, 3));
    commonViewer.setSelection(new StructuredSelection(workingSetsToHide.toArray()));
    hideAction.selectionChanged(commonViewer.getStructuredSelection());
    waitForIdleState();
    assertTrue("Expected enabled action.", hideAction.isEnabled());
    hideAction.run();
    waitForIdleState();
    showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
    // This state will be reseted in tear down phase.
    assertNotNull("Expected visible toolbar item, since there are hidden working sets.", showHiddenWorkingSetsItem);
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Arrays(java.util.Arrays) Diff(org.eclipse.n4js.utils.Diff) N4JSProjectExplorerProblemsDecorator(org.eclipse.n4js.ui.navigator.N4JSProjectExplorerProblemsDecorator) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) Inject(com.google.inject.Inject) IAction(org.eclipse.jface.action.IAction) CoreException(org.eclipse.core.runtime.CoreException) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) WorkingSetManagerBrokerImpl(org.eclipse.n4js.ui.workingsets.WorkingSetManagerBrokerImpl) JavaProjectSetupUtil(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil) HashMultimap(com.google.common.collect.HashMultimap) HideWorkingSetAction(org.eclipse.n4js.ui.workingsets.internal.HideWorkingSetAction) Arrays.asList(java.util.Arrays.asList) FluentIterable.from(com.google.common.collect.FluentIterable.from) ProjectTypeAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager) ProjectNameFilterAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) CommonViewer(org.eclipse.ui.navigator.CommonViewer) PlatformUI(org.eclipse.ui.PlatformUI) Collection(java.util.Collection) WARNING(org.eclipse.n4js.ui.navigator.N4JSProjectExplorerProblemsDecorator.WARNING) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) SWT(org.eclipse.swt.SWT) Entry(java.util.Map.Entry) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) Pattern(java.util.regex.Pattern) Iterables.toArray(com.google.common.collect.Iterables.toArray) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) Iterables(com.google.common.collect.Iterables) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) BeforeClass(org.junit.BeforeClass) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) ProjectExplorer(org.eclipse.ui.navigator.resources.ProjectExplorer) Arrays2(org.eclipse.n4js.utils.collections.Arrays2) Multimap(com.google.common.collect.Multimap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectWorkingSetDropDownAction(org.eclipse.n4js.ui.navigator.internal.SelectWorkingSetDropDownAction) NO_ADORNMENT(org.eclipse.n4js.ui.navigator.N4JSProjectExplorerProblemsDecorator.NO_ADORNMENT) RUNTIME_ENVIRONMENT(org.eclipse.n4js.n4mf.ProjectType.RUNTIME_ENVIRONMENT) IProject(org.eclipse.core.resources.IProject) N4JSProjectInWorkingSetDropAdapterAssistant(org.eclipse.n4js.ui.workingsets.internal.N4JSProjectInWorkingSetDropAdapterAssistant) ShowHiddenWorkingSetsDropDownAction(org.eclipse.n4js.ui.navigator.internal.ShowHiddenWorkingSetsDropDownAction) ERROR(org.eclipse.n4js.ui.navigator.N4JSProjectExplorerProblemsDecorator.ERROR) CommonDropAdapter(org.eclipse.ui.navigator.CommonDropAdapter) IFile(org.eclipse.core.resources.IFile) Before(org.junit.Before) TEST(org.eclipse.n4js.n4mf.ProjectType.TEST) Pattern.compile(java.util.regex.Pattern.compile) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) LIBRARY(org.eclipse.n4js.n4mf.ProjectType.LIBRARY) IOException(java.io.IOException) Test(org.junit.Test) OTHERS_WORKING_SET_ID(org.eclipse.n4js.ui.workingsets.WorkingSet.OTHERS_WORKING_SET_ID) CommonDropAdapterAssistant(org.eclipse.ui.navigator.CommonDropAdapterAssistant) ProjectNameFilterWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet) TreeItem(org.eclipse.swt.widgets.TreeItem) ProjectType(org.eclipse.n4js.n4mf.ProjectType) ProjectTypeWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) INavigatorDnDService(org.eclipse.ui.navigator.INavigatorDnDService) IResource(org.eclipse.core.resources.IResource) IContributionItem(org.eclipse.jface.action.IContributionItem) IWorkbench(org.eclipse.ui.IWorkbench) Menu(org.eclipse.swt.widgets.Menu) RUNTIME_LIBRARY(org.eclipse.n4js.n4mf.ProjectType.RUNTIME_LIBRARY) InputStream(java.io.InputStream) IAction(org.eclipse.jface.action.IAction) TreeItem(org.eclipse.swt.widgets.TreeItem) IContributionItem(org.eclipse.jface.action.IContributionItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HideWorkingSetAction(org.eclipse.n4js.ui.workingsets.internal.HideWorkingSetAction) ProjectTypeWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) Menu(org.eclipse.swt.widgets.Menu) 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) ShowHiddenWorkingSetsDropDownAction(org.eclipse.n4js.ui.navigator.internal.ShowHiddenWorkingSetsDropDownAction) Test(org.junit.Test)

Example 19 with WorkingSet

use of org.eclipse.n4js.ui.workingsets.WorkingSet in project n4js by eclipse.

the class GHOLD_101_WorkingSetsTest_PluginUITest method testProjectNameFilterWorkingSetGrouping.

/**
 */
@Test
public void testProjectNameFilterWorkingSetGrouping() throws CoreException {
    final Multimap<String, String> filterNamesMapping = LinkedHashMultimap.create();
    filterNamesMapping.putAll(OTHERS_WORKING_SET_ID, newArrayList("org.eclipse.n4js.mangelhaft", "org.eclipse.n4js.mangelhaft.assert", "org.eclipse.n4js.mangelhaft.assert.test", "org.eclipse.n4js.mangelhaft.types", "eu.numberfour.mangelhaft.reporter.console", "eu.numberfour.mangelhaft.reporter.html", "org.eclipse.n4js.mangelhaft.reporter.ide", "org.eclipse.n4js.mangelhaft.reporter.ide.test", "eu.numberfour.mangelhaft.reporter.xunit", "eu.numberfour.mangelhaft.runner.html", "org.eclipse.n4js.mangelhaft.runner.ide", "eu.numberfour.mangelhaft.runner.node", "org.eclipse.n4js.mangelhaft.test"));
    filterNamesMapping.putAll(".*-runtime-.*", newArrayList("n4js-runtime-es2015", "n4js-runtime-esnext", "n4js-runtime-fetch", "n4js-runtime-html5", "n4js-runtime-n4", "n4js-runtime-n4-tests", "n4js-runtime-node", "n4js-runtime-node-tests", "n4js-runtime-v8"));
    filterNamesMapping.putAll(".*lib.*", newArrayList("org.eclipse.lib.format", "org.eclipse.lib.format.api", "org.eclipse.lib.format.api-tests", "org.eclipse.lib.i18n.api", "org.eclipse.lib.i18n.api-tests", "org.eclipse.lib.jtl", "org.eclipse.lib.jtl.api", "org.eclipse.lib.jtl.api-tests", "org.eclipse.lib.jtl.tests", "org.eclipse.lib.model.base", "org.eclipse.lib.model.base.api", "org.eclipse.lib.model.base.api-tests", "org.eclipse.lib.model.base.tests", "org.eclipse.lib.model.common", "org.eclipse.lib.model.common.api", "org.eclipse.lib.model.common.api-tests", "org.eclipse.lib.model.common.tests", "org.eclipse.lib.model.core", "org.eclipse.lib.model.core.api", "org.eclipse.lib.model.core.api-tests", "org.eclipse.lib.model.core.zoo.berlin", "org.eclipse.lib.model.gen", "org.eclipse.lib.model.gen.api", "org.eclipse.lib.model.gen.api-tests", "org.eclipse.lib.notificationCenter.api", "org.eclipse.lib.notificationCenter.api-tests", "org.eclipse.lib.npm-dependencies", "org.eclipse.lib.transaction", "org.eclipse.lib.transaction.api", "org.eclipse.lib.transaction.api-tests", "org.eclipse.lib.util"));
    filterNamesMapping.putAll(".*lib.*api.*", newArrayList("org.eclipse.lib.format.api", "org.eclipse.lib.format.api-tests", "org.eclipse.lib.i18n.api", "org.eclipse.lib.i18n.api-tests", "org.eclipse.lib.jtl.api", "org.eclipse.lib.jtl.api-tests", "org.eclipse.lib.model.base.api", "org.eclipse.lib.model.base.api-tests", "org.eclipse.lib.model.common.api", "org.eclipse.lib.model.common.api-tests", "org.eclipse.lib.model.core.api", "org.eclipse.lib.model.core.api-tests", "org.eclipse.lib.model.gen.api", "org.eclipse.lib.model.gen.api-tests", "org.eclipse.lib.notificationCenter.api", "org.eclipse.lib.notificationCenter.api-tests", "org.eclipse.lib.transaction.api", "org.eclipse.lib.transaction.api-tests"));
    filterNamesMapping.putAll(".*lib.*api.*test.*", newArrayList("org.eclipse.lib.format.api-tests", "org.eclipse.lib.i18n.api-tests", "org.eclipse.lib.jtl.api-tests", "org.eclipse.lib.model.base.api-tests", "org.eclipse.lib.model.common.api-tests", "org.eclipse.lib.model.core.api-tests", "org.eclipse.lib.model.gen.api-tests", "org.eclipse.lib.notificationCenter.api-tests", "org.eclipse.lib.transaction.api-tests"));
    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 : filterNamesMapping.values()) {
            JavaProjectSetupUtil.createSimpleProject(projectName);
        }
    } finally {
        workspaceDescription.setAutoBuilding(autoBuild);
    }
    activateWorkingSetManager(ProjectNameFilterAwareWorkingSetManager.class);
    final WorkingSetManager manager = broker.getActiveManager();
    final WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(manager);
    final List<WorkingSet> workingSets = newArrayList();
    final WorkingSet other = new ProjectNameFilterWorkingSet(compile(OTHERS_WORKING_SET_ID), OTHERS_WORKING_SET_ID, manager);
    builder.add(other);
    workingSets.add(other);
    for (final String workingSetId : filterNamesMapping.keySet()) {
        final WorkingSet workingSet = new ProjectNameFilterWorkingSet(compile(workingSetId), workingSetId, manager);
        builder.add(workingSet);
        workingSets.add(workingSet);
    }
    final Diff<WorkingSet> diff = builder.build(toArray(workingSets, WorkingSet.class), toArray(workingSets, WorkingSet.class));
    manager.updateState(diff);
    broker.refreshNavigator();
    waitForIdleState();
    commonViewer.expandToLevel(2);
    waitForIdleState();
    final TreeItem[] treeItems = commonViewer.getTree().getItems();
    final int expectedItemCount = filterNamesMapping.keySet().size();
    assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
    final List<ProjectNameFilterWorkingSet> workingSetsFromTree = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectNameFilterWorkingSet.class).toList();
    assertEquals("Mismatching number of working sets.", expectedItemCount, workingSetsFromTree.size());
    for (final TreeItem treeItem : treeItems) {
        final Pattern filter = ((ProjectNameFilterWorkingSet) treeItem.getData()).getFilter();
        final Collection<String> expectedProjectNames = filterNamesMapping.get(filter.pattern());
        assertEquals("Child item count mismatch: " + treeItem, expectedProjectNames.size(), treeItem.getItemCount());
        for (final TreeItem child : treeItem.getItems()) {
            final String childText = child.getText();
            assertTrue("Unexpected tree item label: " + childText + ". Expected any of: " + Iterables.toString(expectedProjectNames), expectedProjectNames.contains(childText));
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) TreeItem(org.eclipse.swt.widgets.TreeItem) 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) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) ProjectNameFilterWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet) 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

WorkingSet (org.eclipse.n4js.ui.workingsets.WorkingSet)19 WorkingSetManager (org.eclipse.n4js.ui.workingsets.WorkingSetManager)13 ManualAssociationWorkingSet (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)9 WorkingSetDiffBuilder (org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder)8 ManualAssociationAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager)7 IProject (org.eclipse.core.resources.IProject)6 ProjectNameFilterWorkingSet (org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet)5 ProjectTypeWorkingSet (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 Test (org.junit.Test)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Inject (com.google.inject.Inject)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 List (java.util.List)3 IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 ProjectNameFilterAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager)3 ProjectTypeAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager)3