Search in sources :

Example 1 with ProjectTypeWorkingSet

use of org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet 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 2 with ProjectTypeWorkingSet

use of org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet in project n4js by eclipse.

the class GHOLD_101_WorkingSetsTest_PluginUITest method testProjectTypeWorkingSetGrouping.

/**
 */
@Test
public void testProjectTypeWorkingSetGrouping() throws CoreException {
    final Multimap<ProjectType, String> typeNamesMapping = HashMultimap.create();
    typeNamesMapping.putAll(LIBRARY, newArrayList("L1", "L2", "L3"));
    typeNamesMapping.putAll(TEST, newArrayList("T1", "T2"));
    typeNamesMapping.putAll(RUNTIME_ENVIRONMENT, newArrayList("RE1", "RE2", "RE3", "RE4"));
    typeNamesMapping.putAll(RUNTIME_LIBRARY, newArrayList("RL1"));
    for (final Entry<ProjectType, Collection<String>> entry : typeNamesMapping.asMap().entrySet()) {
        for (final String projectName : entry.getValue()) {
            createN4JSProject(projectName, entry.getKey());
        }
    }
    final Collection<String> othersProjectNames = newArrayList("O1", "O2");
    for (final String projectName : othersProjectNames) {
        createJSProject(projectName);
    }
    activateWorkingSetManager(ProjectTypeAwareWorkingSetManager.class);
    commonViewer.expandToLevel(2);
    waitForIdleState();
    final 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);
    final List<ProjectTypeWorkingSet> workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
    assertEquals("Mismatching number of working sets.", expectedItemCount, workingSets.size());
    for (final TreeItem treeItem : treeItems) {
        final ProjectType type = ((ProjectTypeWorkingSet) treeItem.getData()).getType();
        final Collection<String> expectedProjectNames;
        if (null == type) {
            expectedProjectNames = othersProjectNames;
        } else {
            expectedProjectNames = typeNamesMapping.get(type);
        }
        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 : ProjectTypeWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet) TreeItem(org.eclipse.swt.widgets.TreeItem) ProjectType(org.eclipse.n4js.n4mf.ProjectType) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)2 ProjectType (org.eclipse.n4js.n4mf.ProjectType)2 ProjectTypeWorkingSet (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 Test (org.junit.Test)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 FluentIterable.from (com.google.common.collect.FluentIterable.from)1 HashMultimap (com.google.common.collect.HashMultimap)1 Iterables (com.google.common.collect.Iterables)1 Iterables.toArray (com.google.common.collect.Iterables.toArray)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Multimap (com.google.common.collect.Multimap)1 Inject (com.google.inject.Inject)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1