Search in sources :

Example 6 with WorkingSet

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

the class ShowHiddenWorkingSetsDropDownAction method createMenuItems.

@Override
protected void createMenuItems(final Menu parent) {
    final WorkingSetManager manager = workingSetManagerBroker.getActiveManager();
    final WorkingSet[] allWorkingSets = manager.getAllWorkingSets();
    final WorkingSet[] workingSets = manager.getWorkingSets();
    for (final WorkingSet workingSet : allWorkingSets) {
        if (!Arrays.contains(workingSets, workingSet)) {
            final MenuItem item = new MenuItem(parent, PUSH);
            item.setText(workingSet.getName());
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    showWorkingSet(manager, workingSet);
                }
            });
        }
    }
    createSeparator(parent);
    final MenuItem item = new MenuItem(parent, CHECK);
    item.setText(SHOW_ALL_HIDDEN_WORKING_SETS);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Iterable<WorkingSet> difference = difference(newHashSet(allWorkingSets), newHashSet(workingSets));
            final WorkingSet[] toShow = Iterables.toArray(difference, WorkingSet.class);
            showWorkingSet(manager, toShow);
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager)

Example 7 with WorkingSet

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

the class N4JSNavigatorActionProvider method setContext.

@Override
public void setContext(final ActionContext context) {
    super.setContext(context);
    projectGroup.setContext(context);
    // context is null if disposal of the provider is triggered
    if (null != context) {
        StructuredSelection selection = (StructuredSelection) context.getSelection();
        List<Object> selectedElements = Arrays.asList(selection.toArray());
        selectionContainsWorkingSet = selectedElements.stream().anyMatch(element -> element instanceof WorkingSet);
        // try to minimize number of context updates for working set action provider
        if (selectionContainsWorkingSet) {
            workingSetActionProvider.setContext(context);
        }
        assignWorkingSetsAction.selectionChanged(selection);
    }
}
Also used : ICommonActionExtensionSite(org.eclipse.ui.navigator.ICommonActionExtensionSite) IContextMenuConstants(org.eclipse.jdt.ui.IContextMenuConstants) Arrays(java.util.Arrays) CommonActionProvider(org.eclipse.ui.navigator.CommonActionProvider) AssignWorkingSetsAction(org.eclipse.n4js.ui.workingsets.internal.AssignWorkingSetsAction) Inject(com.google.inject.Inject) IActionBars(org.eclipse.ui.IActionBars) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) N4JSWorkingSetActionProvider(org.eclipse.n4js.ui.workingsets.internal.N4JSWorkingSetActionProvider) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) N4JSProjectActionGroup(org.eclipse.n4js.ui.workingsets.internal.N4JSProjectActionGroup) ActionContext(org.eclipse.ui.actions.ActionContext) List(java.util.List) IMenuManager(org.eclipse.jface.action.IMenuManager) IViewPart(org.eclipse.ui.IViewPart) ICommonViewerWorkbenchSite(org.eclipse.ui.navigator.ICommonViewerWorkbenchSite) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet)

Example 8 with WorkingSet

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

the class N4JSProjectExplorerProblemsDecorator method computeAdornmentFlags.

/**
 * Increased visibility for testing purposes.
 *
 * <p>
 * {@inheritDoc}
 */
@Override
@VisibleForTesting
public int computeAdornmentFlags(final Object obj) {
    if (!(obj instanceof WorkingSet)) {
        return super.computeAdornmentFlags(obj);
    }
    final WorkingSet workingSet = (WorkingSet) obj;
    final IAdaptable[] elements = workingSet.getElements();
    int result = 0;
    for (int i = 0; i < elements.length; i++) {
        final IAdaptable element = elements[i];
        final int flags = super.computeAdornmentFlags(element);
        if ((flags & BUILDPATH_ERROR) != 0) {
            return BUILDPATH_ERROR;
        }
        result |= flags;
    }
    if ((result & ERROR) != 0) {
        return ERROR;
    } else if ((result & WARNING) != 0) {
        return WARNING;
    } else {
        return NO_ADORNMENT;
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with WorkingSet

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

the class GHOLD_101_WorkingSetsTest_PluginUITest method testWorkingSetIsTheSingleRootInNavaigator.

/**
 */
@Test
public void testWorkingSetIsTheSingleRootInNavaigator() {
    activateWorkingSetManager(ManualAssociationAwareWorkingSetManager.class);
    final TreeItem[] treeItems = commonViewer.getTree().getItems();
    assertTrue("Expected exactly one item in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == 1);
    final Object data = treeItems[0].getData();
    assertTrue("Expected " + WorkingSet.class + " input in navigator. Was " + data, data instanceof WorkingSet);
    final WorkingSet workingSet = (WorkingSet) treeItems[0].getData();
    assertTrue("Expected working set with ID: " + OTHERS_WORKING_SET_ID + ". Was " + workingSet.getId(), OTHERS_WORKING_SET_ID.equals(workingSet.getId()));
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) 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 10 with WorkingSet

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

the class GHOLD_101_WorkingSetsTest_PluginUITest method testMarkerSupportForWorkingSets.

/**
 */
@Test
public void testMarkerSupportForWorkingSets() throws CoreException, IOException {
    final IProject project = createN4JSProject("P1", LIBRARY);
    createTestFile(project.getFolder("src"), "A", "class a { }");
    final IFile moduleFile = project.getFolder("src").getFile("A.n4js");
    assertTrue("File is not accessible under src/A.n4js", moduleFile.isAccessible());
    // line 1: Class names should start with upper case letter.
    assertMarkers("Expected exactly one validation issue.", project, 1);
    activateWorkingSetManager(ManualAssociationAwareWorkingSetManager.class);
    final TreeItem[] treeItems = commonViewer.getTree().getItems();
    assertTrue("Expected exactly one item in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == 1);
    final Object data = treeItems[0].getData();
    assertTrue("Expected " + WorkingSet.class + " input in navigator. Was " + data, data instanceof WorkingSet);
    final WorkingSet workingSet = (WorkingSet) treeItems[0].getData();
    assertTrue("Expected working set with ID: " + OTHERS_WORKING_SET_ID + ". Was " + workingSet.getId(), OTHERS_WORKING_SET_ID.equals(workingSet.getId()));
    final N4JSProjectExplorerProblemsDecorator decorator = new N4JSProjectExplorerProblemsDecorator();
    int adornmentFlag = decorator.computeAdornmentFlags(workingSet);
    assertEquals("Adornment mismatch.", WARNING, adornmentFlag);
    try (final InputStream is = new StringInputStream("someBrokenContent")) {
        moduleFile.setContents(is, IResource.FORCE, null);
    }
    waitForAutoBuild();
    // line 1: Couldn't resolve reference to IdentifiableElement 'someBrokenContent'
    assertMarkers("Expected exactly one validation issue.", project, 1);
    adornmentFlag = decorator.computeAdornmentFlags(workingSet);
    assertEquals("Adornment mismatch.", ERROR, adornmentFlag);
    try (final InputStream is = new StringInputStream("class A { }")) {
        moduleFile.setContents(is, IResource.FORCE, null);
    }
    waitForAutoBuild();
    assertMarkers("Expected exactly zero validation issues.", project, 0);
    adornmentFlag = decorator.computeAdornmentFlags(workingSet);
    assertEquals("Adornment mismatch.", NO_ADORNMENT, adornmentFlag);
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IFile(org.eclipse.core.resources.IFile) TreeItem(org.eclipse.swt.widgets.TreeItem) StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) 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) IProject(org.eclipse.core.resources.IProject) N4JSProjectExplorerProblemsDecorator(org.eclipse.n4js.ui.navigator.N4JSProjectExplorerProblemsDecorator) 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