Search in sources :

Example 1 with WorkingSet

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

the class AssignWorkingSetsAction method createDialog.

/**
 * Creates the dialog for working set assignment.
 *
 * @param workingSets
 *            All the working set the user should be able to select from
 * @param numberOfSelectedProjects
 *            The number of selected projects
 */
private ListSelectionDialog createDialog(Collection<WorkingSet> workingSets, int numberOfSelectedProjects) {
    // Filter 'Other Projects' working set
    List<WorkingSet> selectableWorkingSets = workingSets.stream().filter(set -> !set.getId().equals(WorkingSet.OTHERS_WORKING_SET_ID)).collect(Collectors.toList());
    String message = String.format(DIALOG_SUBTITLE, numberOfSelectedProjects);
    ListSelectionDialog dialog = new NonEmptyListSelectionDialog(site.getShell(), selectableWorkingSets, ArrayContentProvider.getInstance(), WorkingSetLabelProvider.INSTANCE, message);
    dialog.setTitle(DIALOG_TITLE);
    return dialog;
}
Also used : ICommonActionExtensionSite(org.eclipse.ui.navigator.ICommonActionExtensionSite) Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) WorkingSetLabelProvider(org.eclipse.n4js.ui.workingsets.WorkingSetLabelProvider) Inject(com.google.inject.Inject) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) Arrays2(org.eclipse.n4js.utils.collections.Arrays2) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ICommonViewerSite(org.eclipse.ui.navigator.ICommonViewerSite) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) Shell(org.eclipse.swt.widgets.Shell) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) Collection(java.util.Collection) WorkingSetManagerBroker(org.eclipse.n4js.ui.workingsets.WorkingSetManagerBroker) SelectionListenerAction(org.eclipse.ui.actions.SelectionListenerAction) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Collectors(java.util.stream.Collectors) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) List(java.util.List) Window(org.eclipse.jface.window.Window) ListSelectionDialog(org.eclipse.ui.dialogs.ListSelectionDialog) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) Control(org.eclipse.swt.widgets.Control) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ListSelectionDialog(org.eclipse.ui.dialogs.ListSelectionDialog)

Example 2 with WorkingSet

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

the class AssignWorkingSetsAction method performWorkingSetUpdate.

/**
 * Performs the working sets update specified by the given dialog result.
 *
 * @param dialogResult
 *            The result of the list selection dialog.
 * @param selectionProjectNames
 *            A list of names of the selected projects
 * @returns {@code true} if the update was successfully performed. {@code false} otherwise.
 */
private boolean performWorkingSetUpdate(Object[] dialogResult, Iterable<String> selectionProjectNames) {
    if (dialogResult == null) {
        return false;
    }
    WorkingSetManager workingSetManager = broker.getActiveManager();
    if (!(workingSetManager instanceof ManualAssociationAwareWorkingSetManager)) {
        return false;
    }
    // get copies of the workspace working sets.
    List<WorkingSet> allWorkingSets = new ArrayList<>(Arrays.asList(workingSetManager.getAllWorkingSets()));
    List<WorkingSet> workingSets = new ArrayList<>(Arrays.asList(workingSetManager.getWorkingSets()));
    // build WorkingSet edit difference
    WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(workingSetManager);
    for (Object resultItem : dialogResult) {
        // abort if the dialog returned a non-working-set item
        if (!(resultItem instanceof ManualAssociationWorkingSet)) {
            return false;
        }
        ManualAssociationWorkingSet oldState = (ManualAssociationWorkingSet) resultItem;
        ManualAssociationWorkingSet newState = getWorkingSetWithAddedProjects(oldState, selectionProjectNames);
        // register working set edit
        builder.edit(oldState, newState);
        // replace working set with its new state
        replaceWorkingSet(workingSets, newState);
        replaceWorkingSet(allWorkingSets, newState);
    }
    // apply WorkingSet update and refresh UI
    workingSetManager.updateState(builder.build(workingSets, allWorkingSets));
    broker.refreshNavigator();
    return true;
}
Also used : WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ArrayList(java.util.ArrayList) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager)

Example 3 with WorkingSet

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

the class N4JSProjectActionGroup method evaluateSelection.

private int evaluateSelection(final Object[] array, final List<IProject> allOpenProjects) {
    int status = 0;
    for (int i = 0; i < array.length; i++) {
        final Object curr = array[i];
        if (curr instanceof IProject) {
            final IProject project = (IProject) curr;
            if (project.isOpen()) {
                allOpenProjects.add(project);
            } else {
                status |= CLOSED_PROJECTS_SELECTED;
            }
        } else {
            status |= NON_PROJECT_SELECTED;
            if (curr instanceof WorkingSet) {
                final int res = evaluateSelection(((WorkingSet) curr).getElements(), allOpenProjects);
                status |= res;
            }
        }
    }
    return status;
}
Also used : WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) IProject(org.eclipse.core.resources.IProject)

Example 4 with WorkingSet

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

the class N4JSProjectInWorkingSetDropAdapterAssistant method validateDrop.

@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
    // We don't currently support COPY or LINK
    if (operation != DND.DROP_MOVE) {
        return CANCEL_STATUS;
    }
    WorkingSet targetWorkingSet = null;
    if (target instanceof WorkingSet) {
        targetWorkingSet = (WorkingSet) target;
    }
    if (targetWorkingSet == null) {
        return CANCEL_STATUS;
    }
    if (!LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
        return CANCEL_STATUS;
    }
    // Verify that we have at least one project not already in the target
    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        for (Object item : ((IStructuredSelection) selection).toArray()) {
            if (item instanceof IAdaptable) {
                IProject project = ((IAdaptable) item).getAdapter(IProject.class);
                if (project != null && !workingSetContains(targetWorkingSet, project)) {
                    WorkingSetManager manager = ((WorkingSet) target).getWorkingSetManager();
                    if (ManualAssociationAwareWorkingSetManager.class.getName().equals(manager.getId())) {
                        return OK_STATUS;
                    }
                }
            }
        }
        // Or contains exactly one working set for rearrange purposes.
        final Object[] elements = ((IStructuredSelection) selection).toArray();
        if (elements.length == 1 && elements[0] instanceof WorkingSet) {
            getCommonDropAdapter().setExpandEnabled(false);
            getCommonDropAdapter().setFeedbackEnabled(true);
            return OK_STATUS;
        }
    }
    return CANCEL_STATUS;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) IProject(org.eclipse.core.resources.IProject) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager)

Example 5 with WorkingSet

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

the class N4JSResourceExtensionSorter method compareClass.

@Override
@SuppressWarnings({ "deprecation" })
protected int compareClass(Object e1, Object e2) {
    if (e1 instanceof ResourceNode && e2 instanceof ResourceNode) {
        final File f1 = ((ResourceNode) e1).getResource();
        final File f2 = ((ResourceNode) e2).getResource();
        if (f1.isFile() == f2.isFile()) {
            return getComparator().compare(f1.getName(), f2.getName());
        } else if (f1.isDirectory() && f2.isFile()) {
            return -1;
        } else if (f1.isFile() && f2.isDirectory()) {
            return 1;
        }
    } else if (e1 instanceof WorkingSet && e2 instanceof WorkingSet) {
        final WorkingSetManager workingSetManager = workingSetManagerBroker.getActiveManager();
        if (null != workingSetManager) {
            final WorkingSet ws1 = (WorkingSet) e1;
            final WorkingSet ws2 = (WorkingSet) e2;
            return workingSetManager.compare(ws1, ws2);
        }
    }
    return super.compareClass(e1, e2);
}
Also used : WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) File(java.io.File) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager)

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