Search in sources :

Example 1 with ManualAssociationAwareWorkingSetManager

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

the class AssignWorkingSetsAction method run.

@Override
public void run() {
    // fail if the action hasn't been initialized
    if (site == null) {
        return;
    }
    final Object[] selectionElements = getStructuredSelection().toArray();
    // get Iterable of selected project names
    Iterable<String> selectionProjectNames = Arrays.asList(selectionElements).stream().filter(item -> item instanceof IProject).map(item -> ((IProject) item).getName()).collect(Collectors.toList());
    // double-check that the active Working Sets Manager is {@link ManualAssociationAwareWorkingSetManager}
    if (!(broker.getActiveManager() instanceof ManualAssociationAwareWorkingSetManager)) {
        return;
    }
    // open the dialog
    SelectionDialog dialog = createDialog(Arrays.asList(((ManualAssociationAwareWorkingSetManager) broker.getActiveManager()).getWorkingSets()), selectionElements.length);
    dialog.open();
    // Abort if user didn't press OK
    if (dialog.getReturnCode() != Window.OK) {
        return;
    }
    // perform specified working set updates
    performWorkingSetUpdate(dialog.getResult(), selectionProjectNames);
}
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) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) ListSelectionDialog(org.eclipse.ui.dialogs.ListSelectionDialog) IProject(org.eclipse.core.resources.IProject)

Example 2 with ManualAssociationAwareWorkingSetManager

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

Aggregations

ArrayList (java.util.ArrayList)2 ManualAssociationAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager)2 ManualAssociationWorkingSet (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)2 WorkingSet (org.eclipse.n4js.ui.workingsets.WorkingSet)2 WorkingSetDiffBuilder (org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder)2 WorkingSetManager (org.eclipse.n4js.ui.workingsets.WorkingSetManager)2 Iterables (com.google.common.collect.Iterables)1 Inject (com.google.inject.Inject)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IProject (org.eclipse.core.resources.IProject)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Window (org.eclipse.jface.window.Window)1 WorkingSetLabelProvider (org.eclipse.n4js.ui.workingsets.WorkingSetLabelProvider)1 WorkingSetManagerBroker (org.eclipse.n4js.ui.workingsets.WorkingSetManagerBroker)1