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