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;
}
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;
}
}
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;
}
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()]));
}
}
}
}
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;
}
Aggregations