Search in sources :

Example 1 with WorkingSetManager

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

use of org.eclipse.n4js.ui.workingsets.WorkingSetManager 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 3 with WorkingSetManager

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

Example 4 with WorkingSetManager

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

the class SelectWorkingSetDropDownAction method createMenuItems.

@Override
protected void createMenuItems(final Menu parent) {
    final Collection<WorkingSetManager> managers = workingSetManagerBroker.getWorkingSetManagers();
    for (final WorkingSetManager manager : managers) {
        final MenuItem item = new MenuItem(parent, CHECK);
        item.setText(manager.getLabel());
        item.setImage(manager.getImage().orNull());
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                workingSetManagerBroker.setActiveManager(manager);
            }
        });
        item.setSelection(workingSetManagerBroker.isActiveManager(manager));
    }
    final WorkingSetManager activeManager = workingSetManagerBroker.getActiveManager();
    if (null != activeManager) {
        createSeparator(parent);
        final MenuItem item = new MenuItem(parent, CHECK);
        item.setText("Configure " + activeManager.getLabel() + "...");
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                activeManager.configure();
                workingSetManagerBroker.refreshNavigator();
            }
        });
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager)

Example 5 with WorkingSetManager

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

Aggregations

WorkingSetManager (org.eclipse.n4js.ui.workingsets.WorkingSetManager)14 WorkingSet (org.eclipse.n4js.ui.workingsets.WorkingSet)13 ManualAssociationAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager)6 ManualAssociationWorkingSet (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)6 WorkingSetDiffBuilder (org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder)6 IProject (org.eclipse.core.resources.IProject)4 ProjectTypeAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager)4 TreeItem (org.eclipse.swt.widgets.TreeItem)4 Collection (java.util.Collection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 FluentIterable.from (com.google.common.collect.FluentIterable.from)2 HashMultimap (com.google.common.collect.HashMultimap)2 Iterables (com.google.common.collect.Iterables)2 Multimap (com.google.common.collect.Multimap)2 Inject (com.google.inject.Inject)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2