Search in sources :

Example 31 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project eclipse.platform.text by eclipse.

the class ScopePart method getStoredWorkingSets.

private IWorkingSet[] getStoredWorkingSets() {
    String[] lruWorkingSetNames = fSettingsStore.getArray(STORE_LRU_WORKING_SET_NAMES);
    IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
    if (lruWorkingSetNames != null) {
        Set<IWorkingSet> existingWorkingSets = new HashSet<>(lruWorkingSetNames.length);
        for (String lruWorkingSetName : lruWorkingSetNames) {
            IWorkingSet workingSet = getWorkingSet(workingSetManager, lruWorkingSetName);
            if (workingSet != null) {
                existingWorkingSets.add(workingSet);
            }
        }
        if (!existingWorkingSets.isEmpty()) {
            return existingWorkingSets.toArray(new IWorkingSet[existingWorkingSets.size()]);
        }
    } else {
        // Backward compatibility
        String workingSetName = fSettingsStore.get(STORE_LRU_WORKING_SET_NAME);
        if (workingSetName != null) {
            IWorkingSet workingSet = getWorkingSet(workingSetManager, workingSetName);
            if (workingSet != null) {
                return new IWorkingSet[] { workingSet };
            }
        }
    }
    return null;
}
Also used : IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSet(org.eclipse.ui.IWorkingSet) HashSet(java.util.HashSet)

Example 32 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project linuxtools by eclipse.

the class NewProjectCreationPage method getSelectedWorkingSet.

/**
 * Try our best to set the working sets field to something sensible based on the
 * current selection.
 */
private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
    if (!(selection instanceof ITreeSelection)) {
        return EMPTY_WORKING_SET_ARRAY;
    }
    ITreeSelection treeSelection = (ITreeSelection) selection;
    if (treeSelection.isEmpty()) {
        return EMPTY_WORKING_SET_ARRAY;
    }
    List<?> elements = treeSelection.toList();
    if (elements.size() == 1) {
        Object element = elements.get(0);
        TreePath[] paths = treeSelection.getPathsFor(element);
        if (paths.length != 1 || paths[0].getSegmentCount() == 0) {
            return EMPTY_WORKING_SET_ARRAY;
        }
        Object candidate = paths[0].getSegment(0);
        if (!(candidate instanceof IWorkingSet)) {
            return EMPTY_WORKING_SET_ARRAY;
        }
        IWorkingSet workingSetCandidate = (IWorkingSet) candidate;
        if (!workingSetCandidate.isAggregateWorkingSet()) {
            return new IWorkingSet[] { workingSetCandidate };
        }
        return EMPTY_WORKING_SET_ARRAY;
    }
    ArrayList<IWorkingSet> result = new ArrayList<>();
    for (Object element : elements) {
        if (element instanceof IWorkingSet && !((IWorkingSet) element).isAggregateWorkingSet()) {
            result.add((IWorkingSet) element);
        }
    }
    if (!result.isEmpty()) {
        return result.toArray(new IWorkingSet[result.size()]);
    } else {
        return EMPTY_WORKING_SET_ARRAY;
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 33 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project erlide_eclipse by erlang.

the class SearchUtil method getWorkingSetsScope.

public static ErlSearchScope getWorkingSetsScope(final IWorkingSet[] workingSets, final boolean addExternals, final boolean addOTP) throws CoreException {
    final ErlSearchScope result = new ErlSearchScope();
    final Set<String> externalModulePaths = new HashSet<>();
    if (workingSets == null) {
        return result;
    }
    for (final IWorkingSet ws : workingSets) {
        final IAdaptable[] elements = ws.getElements();
        for (final IAdaptable a : elements) {
            final IResource r = a.getAdapter(IResource.class);
            SearchCoreUtil.addResourceToScope(result, r);
            IParent parent = null;
            Object o = a.getAdapter(IErlElement.class);
            if (o instanceof IParent) {
                parent = (IParent) o;
            } else {
                o = a.getAdapter(IResource.class);
                if (o != null) {
                    final IResource resource = (IResource) o;
                    final IErlElement element = ErlangEngine.getInstance().getModel().findElement(resource);
                    if (element instanceof IParent) {
                        parent = (IParent) element;
                    }
                }
            }
            if (parent != null) {
                SearchCoreUtil.addExternalModules(parent, result, externalModulePaths, addExternals, addOTP);
            }
        }
    }
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) IParent(org.erlide.engine.model.IParent) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IWorkingSet(org.eclipse.ui.IWorkingSet) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 34 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project erlide_eclipse by erlang.

the class SearchUtil method restoreState.

private static void restoreState() {
    SearchUtil.fgLRUWorkingSets = new LRUWorkingSetsList(SearchUtil.LRU_WORKINGSET_LIST_SIZE);
    final IDialogSettings settingsStore = SearchUtil.getDialogStoreSection();
    for (int i = SearchUtil.LRU_WORKINGSET_LIST_SIZE - 1; i >= 0; i--) {
        final String[] lruWorkingSetNames = settingsStore.getArray(SearchUtil.STORE_LRU_WORKING_SET_NAMES + i);
        if (lruWorkingSetNames != null) {
            final Set<IWorkingSet> workingSets = new HashSet<>(2);
            for (String lruWorkingSetName : lruWorkingSetNames) {
                final IWorkingSet workingSet = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(lruWorkingSetName);
                if (workingSet != null) {
                    workingSets.add(workingSet);
                }
            }
            if (!workingSets.isEmpty()) {
                SearchUtil.fgLRUWorkingSets.add(workingSets.toArray(new IWorkingSet[workingSets.size()]));
            }
        }
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IWorkingSet(org.eclipse.ui.IWorkingSet) HashSet(java.util.HashSet)

Example 35 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project erlide_eclipse by erlang.

the class SearchUtil method queryWorkingSets.

public static IWorkingSet[] queryWorkingSets() throws InterruptedException {
    final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return null;
    }
    final Shell shell = activeWorkbenchWindow.getShell();
    if (shell == null) {
        return null;
    }
    final IWorkingSetSelectionDialog dialog = PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSetSelectionDialog(shell, true);
    if (dialog.open() != Window.OK) {
        throw new InterruptedException();
    }
    final IWorkingSet[] workingSets = dialog.getSelection();
    if (workingSets.length > 0) {
        return workingSets;
    }
    // 'no working set' selected
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) IWorkingSetSelectionDialog(org.eclipse.ui.dialogs.IWorkingSetSelectionDialog) IWorkingSet(org.eclipse.ui.IWorkingSet)

Aggregations

IWorkingSet (org.eclipse.ui.IWorkingSet)54 IWorkingSetManager (org.eclipse.ui.IWorkingSetManager)17 IAdaptable (org.eclipse.core.runtime.IAdaptable)15 IResource (org.eclipse.core.resources.IResource)10 IProject (org.eclipse.core.resources.IProject)9 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IWorkingSetSelectionDialog (org.eclipse.ui.dialogs.IWorkingSetSelectionDialog)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IWorkbench (org.eclipse.ui.IWorkbench)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Set (java.util.Set)2 IProjectDescription (org.eclipse.core.resources.IProjectDescription)2