Search in sources :

Example 6 with IWorkingSet

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

the class ScopePart method saveState.

/**
 * Saves the last recently used working sets,
 * if any.
 */
private void saveState() {
    if (fWorkingSets != null && fWorkingSets.length > 0) {
        String[] existingWorkingSetNames = new String[fWorkingSets.length];
        for (int i = 0; i < fWorkingSets.length; i++) {
            IWorkingSet curr = fWorkingSets[i];
            // use empty name for aggregateWS
            // $NON-NLS-1$
            existingWorkingSetNames[i] = curr.isAggregateWorkingSet() ? "" : curr.getName();
        }
        fSettingsStore.put(STORE_LRU_WORKING_SET_NAMES, existingWorkingSetNames);
    }
}
Also used : IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 7 with IWorkingSet

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

the class ScopePart method selectedResourcesFromContainer.

public static List<IResource> selectedResourcesFromContainer(ISearchPageContainer container) {
    if (container == null)
        return Collections.emptyList();
    ISelection selection = container.getSelection();
    List<IResource> resources = new ArrayList<>();
    if (!(selection instanceof IStructuredSelection) || selection.isEmpty()) {
        if (container.getActiveEditorInput() != null) {
            resources.add(container.getActiveEditorInput().getAdapter(IFile.class));
        }
        return resources;
    }
    Iterator<?> iter = ((IStructuredSelection) selection).iterator();
    while (iter.hasNext()) {
        Object curr = iter.next();
        if (curr instanceof IWorkingSet) {
            IWorkingSet workingSet = (IWorkingSet) curr;
            if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
                continue;
            }
            IAdaptable[] elements = workingSet.getElements();
            for (IAdaptable element : elements) {
                IResource resource = element.getAdapter(IResource.class);
                if (resource != null && resource.isAccessible()) {
                    resources.add(resource);
                }
            }
        } else if (curr instanceof LineElement) {
            IResource resource = ((LineElement) curr).getParent();
            if (resource != null && resource.isAccessible())
                resources.add(resource);
        } else if (curr instanceof IAdaptable) {
            IResource resource = ((IAdaptable) curr).getAdapter(IResource.class);
            if (resource != null && resource.isAccessible()) {
                resources.add(resource);
            }
        }
    }
    return resources;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) LineElement(org.eclipse.search.internal.ui.text.LineElement) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 8 with IWorkingSet

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

the class RPMNewProject method createProject.

protected void createProject(IProgressMonitor monitor) throws CoreException {
    RPMProjectCreator rpmProjectCreator = new RPMProjectCreator(namePage.getSelectedLayout());
    IProject project = rpmProjectCreator.create(namePage.getProjectName(), namePage.getLocationPath(), monitor);
    // Add new project to working sets, if requested
    IWorkingSet[] workingSets = namePage.getWorkingSets();
    if (workingSets.length > 0) {
        PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(project, workingSets);
    }
}
Also used : RPMProjectCreator(org.eclipse.linuxtools.rpm.core.RPMProjectCreator) IProject(org.eclipse.core.resources.IProject) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 9 with IWorkingSet

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

the class FilteredModulesSelectionDialog method fillViewMenu.

@Override
protected void fillViewMenu(final IMenuManager menuManager) {
    super.fillViewMenu(menuManager);
    workingSetFilterActionGroup = new WorkingSetFilterActionGroup(getShell(), new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            final String property = event.getProperty();
            if (WorkingSetFilterActionGroup.CHANGE_WORKING_SET.equals(property)) {
                IWorkingSet workingSet = (IWorkingSet) event.getNewValue();
                if (workingSet != null && !(workingSet.isAggregateWorkingSet() && workingSet.isEmpty())) {
                    workingSetFilter.setWorkingSet(workingSet);
                    setSubtitle(workingSet.getLabel());
                } else {
                    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    if (window != null) {
                        final IWorkbenchPage page = window.getActivePage();
                        workingSet = page.getAggregateWorkingSet();
                        if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
                            workingSet = null;
                        }
                    }
                    workingSetFilter.setWorkingSet(workingSet);
                    setSubtitle(null);
                }
                scheduleRefresh();
            }
        }
    });
    menuManager.add(new Separator());
    workingSetFilterActionGroup.fillContextMenu(menuManager);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) WorkingSetFilterActionGroup(org.eclipse.ui.actions.WorkingSetFilterActionGroup) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IWorkingSet(org.eclipse.ui.IWorkingSet) Separator(org.eclipse.jface.action.Separator)

Example 10 with IWorkingSet

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

the class SearchUtil method workingSetLabels.

private static String workingSetLabels(final IWorkingSet[] workingSets, final String s, final String surround) {
    final StringBuilder sb = new StringBuilder(s);
    int i = 0;
    for (final IWorkingSet ws : workingSets) {
        sb.append(surround).append(ws.getLabel()).append(surround).append(", ");
        i++;
        if (i == 2) {
            break;
        }
    }
    if (workingSets.length > 2) {
        return sb.append("... ").toString();
    }
    return sb.substring(0, sb.length() - 2);
}
Also used : 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