Java Code Examples for org.eclipse.ui.IWorkingSet#isAggregateWorkingSet()

The following examples show how to use org.eclipse.ui.IWorkingSet#isAggregateWorkingSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceUtils.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @param wset
 *            non null working set
 * @return non null set with work items, which may be empty
 */
public static Set<WorkItem> getResources(IWorkingSet wset) {
    Set<WorkItem> set = new HashSet<>();
    boolean aggregateWorkingSet = wset.isAggregateWorkingSet();
    // IAggregateWorkingSet was introduced in Eclipse 3.5
    if (aggregateWorkingSet && wset instanceof IAggregateWorkingSet) {
        IAggregateWorkingSet aggr = (IAggregateWorkingSet) wset;
        IWorkingSet[] sets = aggr.getComponents();
        for (IWorkingSet iWorkingSet : sets) {
            set.addAll(getResources(iWorkingSet));
        }
    } else {
        IAdaptable[] elements = wset.getElements();
        for (IAdaptable iAdaptable : elements) {
            WorkItem item = getWorkItem(iAdaptable);
            if (item != null) {
                set.add(item);
            }
        }
    }
    return set;
}
 
Example 2
Source File: EditWorkingSetAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Shell shell= getShell();
	IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
	IWorkingSet workingSet= fActionGroup.getWorkingSet();
	if (workingSet == null || workingSet.isAggregateWorkingSet()) {
		setEnabled(false);
		return;
	}
	IWorkingSetEditWizard wizard= manager.createWorkingSetEditWizard(workingSet);
	if (wizard == null) {
		String title= WorkingSetMessages.EditWorkingSetAction_error_nowizard_title;
		String message= WorkingSetMessages.EditWorkingSetAction_error_nowizard_message;
		MessageDialog.openError(shell, title, message);
		return;
	}
	WizardDialog dialog= new WizardDialog(shell, wizard);
 	dialog.create();
	if (dialog.open() == Window.OK)
		fActionGroup.setWorkingSet(wizard.getSelection(), true);
}
 
Example 3
Source File: WorkingSetModel.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tells whether the given working set is supported as top-level element
 * 
 * @param workingSet the working set to test
 * @return <code>true</code> if the given working set is supported as top-level element
 * @since 3.6
 */
public static boolean isSupportedAsTopLevelElement(IWorkingSet workingSet) {
	Object id= workingSet.getId();
	if (IWorkingSetIDs.OTHERS.equals(id) || IWorkingSetIDs.JAVA.equals(id) || IWorkingSetIDs.RESOURCE.equals(id))
		return true;

	if (!workingSet.isSelfUpdating() || workingSet.isAggregateWorkingSet())
		return false;

	IAdaptable[] elements= workingSet.getElements();
	for (int i= 0; i < elements.length; i++) {
		IAdaptable element= elements[i];
		IProject p= (IProject)element.getAdapter(IProject.class);
		if (p != null && p.exists())
			return true;
	}
	return false;
}
 
Example 4
Source File: ConfigureWorkingSetAssignementAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isValidWorkingSet(IWorkingSet set) {
	if (set.isAggregateWorkingSet() || !set.isSelfUpdating())
		return false;

	if (!set.isVisible())
		return false;

	if (!set.isEditable())
		return false;

	for (int i= 0; i < VALID_WORKING_SET_IDS.length; i++) {
		if (VALID_WORKING_SET_IDS[i].equals(set.getId()))
			return true;
	}

	return false;
}
 
Example 5
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IJavaSearchScope createJavaSearchScope(IWorkingSet workingSet, int includeMask) {
	Set<IJavaElement> javaElements= new HashSet<IJavaElement>(10);
	if (workingSet.isEmpty() && workingSet.isAggregateWorkingSet()) {
		return createWorkspaceScope(includeMask);
	}
	addJavaElements(javaElements, workingSet);
	return createJavaSearchScope(javaElements, includeMask);
}
 
Example 6
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addJavaElements(Set<IJavaElement> javaElements, IWorkingSet workingSet) {
	if (workingSet == null)
		return;

	if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
		try {
			IJavaProject[] projects= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
			javaElements.addAll(Arrays.asList(projects));
		} catch (JavaModelException e) {
			JavaPlugin.log(e);
		}
		return;
	}

	IAdaptable[] elements= workingSet.getElements();
	for (int i= 0; i < elements.length; i++) {
		IJavaElement javaElement=(IJavaElement) elements[i].getAdapter(IJavaElement.class);
		if (javaElement != null) {
			addJavaElements(javaElements, javaElement);
			continue;
		}
		IResource resource= (IResource)elements[i].getAdapter(IResource.class);
		if (resource != null) {
			addJavaElements(javaElements, resource);
		}

		// else we don't know what to do with it, ignore.
	}
}
 
Example 7
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void restoreDialog(IDialogSettings settings) {
	super.restoreDialog(settings);

	if (! BUG_184693) {
		boolean showContainer= settings.getBoolean(SHOW_CONTAINER_FOR_DUPLICATES);
		fShowContainerForDuplicatesAction.setChecked(showContainer);
		fTypeInfoLabelProvider.setContainerInfo(showContainer);
	} else {
		fTypeInfoLabelProvider.setContainerInfo(true);
	}

	if (fAllowScopeSwitching) {
		String setting= settings.get(WORKINGS_SET_SETTINGS);
		if (setting != null) {
			try {
				IMemento memento= XMLMemento.createReadRoot(new StringReader(setting));
				fFilterActionGroup.restoreState(memento);
			} catch (WorkbenchException e) {
				// don't do anything. Simply don't restore the settings
				JavaPlugin.log(e);
			}
		}
		IWorkingSet ws= fFilterActionGroup.getWorkingSet();
		if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
			setSearchScope(SearchEngine.createWorkspaceScope());
			setSubtitle(null);
		} else {
			setSearchScope(JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true));
			setSubtitle(ws.getLabel());
		}
	}

	// TypeNameMatch[] types = OpenTypeHistory.getInstance().getTypeInfos();
	//
	// for (int i = 0; i < types.length; i++) {
	// TypeNameMatch type = types[i];
	// accessedHistoryItem(type);
	// }
}
 
Example 8
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IJavaSearchScope createJavaSearchScope(IWorkingSet[] workingSets, int includeMask) {
	if (workingSets == null || workingSets.length < 1)
		return EMPTY_SCOPE;

	Set<IJavaElement> javaElements= new HashSet<IJavaElement>(workingSets.length * 10);
	for (int i= 0; i < workingSets.length; i++) {
		IWorkingSet workingSet= workingSets[i];
		if (workingSet.isEmpty() && workingSet.isAggregateWorkingSet()) {
			return createWorkspaceScope(includeMask);
		}
		addJavaElements(javaElements, workingSet);
	}
	return createJavaSearchScope(javaElements, includeMask);
}
 
Example 9
Source File: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isValidWorkingSet(IWorkingSet workingSet) {
	String id= workingSet.getId();
	if (!IWorkingSetIDs.JAVA.equals(id) && !IWorkingSetIDs.RESOURCE.equals(id))
		return false;

	if (workingSet.isAggregateWorkingSet())
		return false;

	return true;
}
 
Example 10
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static boolean isValidWorkingSet(IWorkingSet workingSet) {
	final String id = workingSet.getId();
	if (!IWorkingSetIDs.JAVA.equals(id) && !IWorkingSetIDs.RESOURCE.equals(id)) {
		return false;
	}

	if (workingSet.isAggregateWorkingSet()) {
		return false;
	}

	return true;
}
 
Example 11
Source File: WorkingSetActionProvider.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent event) {
	
	if (ignoreFilterChangeEvents)
		return;
	
	IWorkingSet newWorkingSet = (IWorkingSet) event.getNewValue();

	setWorkingSet(newWorkingSet);
	if (newWorkingSet != null) {
		if (!contentService.isActive(WorkingSetsContentProvider.EXTENSION_ID)) {
			contentService.getActivationService().activateExtensions(
					new String[] { WorkingSetsContentProvider.EXTENSION_ID }, false);
			contentService.getActivationService().persistExtensionActivations();
		}
		if (newWorkingSet.isAggregateWorkingSet()) {
			IAggregateWorkingSet agWs = (IAggregateWorkingSet) newWorkingSet;
			IWorkingSet[] comps = agWs.getComponents();
			if (comps.length > 1) {
				viewer.getCommonNavigator().setWorkingSetLabel(
						WorkbenchNavigatorMessages.actions_WorkingSetActionProvider_multipleWorkingSets);
			} else if (comps.length > 0) {
				viewer.getCommonNavigator().setWorkingSetLabel(comps[0].getLabel());
			} else {
				viewer.getCommonNavigator().setWorkingSetLabel(null);
			}
		} else
			viewer.getCommonNavigator().setWorkingSetLabel(workingSet.getLabel());
	} else {
		viewer.getCommonNavigator().setWorkingSetLabel(null);
	}

	viewer.getFrameList().reset();
}
 
Example 12
Source File: WorkingSetActionProvider.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set current active working set.
 * 
 * @param workingSet
 *            working set to be activated, may be <code>null</code>
 */
protected void setWorkingSet(IWorkingSet workingSet) {
	this.workingSet = workingSet;
	emptyWorkingSet = workingSet != null && workingSet.isAggregateWorkingSet() && workingSet.isEmpty();

       ignoreFilterChangeEvents = true;
       try {
       	workingSetActionGroup.setWorkingSet(workingSet);
       } finally {
       	ignoreFilterChangeEvents = false;
      	}		
	
	if (viewer != null) {
		setWorkingSetFilter(workingSet);
		if (workingSet == null || emptyWorkingSet
				|| !extensionStateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS)) {
			if (viewer.getInput() != originalViewerInput) {
				viewer.setInput(originalViewerInput);
			} else {
				viewer.refresh();
			}
		} else {
			if (!workingSet.isAggregateWorkingSet()) {
				IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
				viewer.setInput(workingSetManager.createAggregateWorkingSet(
						"", "", new IWorkingSet[] { workingSet })); //$NON-NLS-1$ //$NON-NLS-2$
			} else {
				viewer.setInput(workingSet);
			}
		}
	}
}
 
Example 13
Source File: WorkingSetsContentProvider.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public Object[] getChildren(Object parentElement) {
	if (parentElement instanceof IWorkingSet) {
		IWorkingSet workingSet = (IWorkingSet) parentElement;
		if (workingSet.isAggregateWorkingSet() && projectExplorer != null) {
			switch (projectExplorer.getRootMode()) {
				case ProjectExplorer.WORKING_SETS :
					return ((IAggregateWorkingSet) workingSet).getComponents();
				case ProjectExplorer.PROJECTS :
					return getWorkingSetElements(workingSet);
			}
		}
		return getWorkingSetElements(workingSet);
	}
	return NO_CHILDREN;
}
 
Example 14
Source File: WorkingSetActionProvider.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent event) {
	
	if (ignoreFilterChangeEvents)
		return;
	
	IWorkingSet newWorkingSet = (IWorkingSet) event.getNewValue();

	setWorkingSet(newWorkingSet);
	if (newWorkingSet != null) {
		if (!contentService.isActive(WorkingSetsContentProvider.EXTENSION_ID)) {
			contentService.getActivationService().activateExtensions(
					new String[] { WorkingSetsContentProvider.EXTENSION_ID }, false);
			contentService.getActivationService().persistExtensionActivations();
		}
		if (newWorkingSet.isAggregateWorkingSet()) {
			IAggregateWorkingSet agWs = (IAggregateWorkingSet) newWorkingSet;
			IWorkingSet[] comps = agWs.getComponents();
			if (comps.length > 1) {
				viewer.getCommonNavigator().setWorkingSetLabel(
						WorkbenchNavigatorMessages.actions_WorkingSetActionProvider_multipleWorkingSets);
			} else if (comps.length > 0) {
				viewer.getCommonNavigator().setWorkingSetLabel(comps[0].getLabel());
			} else {
				viewer.getCommonNavigator().setWorkingSetLabel(null);
			}
		} else
			viewer.getCommonNavigator().setWorkingSetLabel(workingSet.getLabel());
	} else {
		viewer.getCommonNavigator().setWorkingSetLabel(null);
	}

	viewer.getFrameList().reset();
}
 
Example 15
Source File: WorkingSetActionProvider.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set current active working set.
 * 
 * @param workingSet
 *            working set to be activated, may be <code>null</code>
 */
protected void setWorkingSet(IWorkingSet workingSet) {
	this.workingSet = workingSet;
	emptyWorkingSet = workingSet != null && workingSet.isAggregateWorkingSet() && workingSet.isEmpty();

       ignoreFilterChangeEvents = true;
       try {
       	workingSetActionGroup.setWorkingSet(workingSet);
       } finally {
       	ignoreFilterChangeEvents = false;
      	}		
	
	if (viewer != null) {
		setWorkingSetFilter(workingSet);
		if (workingSet == null || emptyWorkingSet
				|| !extensionStateModel.getBooleanProperty(WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS)) {
			if (viewer.getInput() != originalViewerInput) {
				viewer.setInput(originalViewerInput);
			} else {
				viewer.refresh();
			}
		} else {
			if (!workingSet.isAggregateWorkingSet()) {
				IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
				viewer.setInput(workingSetManager.createAggregateWorkingSet(
						"", "", new IWorkingSet[] { workingSet })); //$NON-NLS-1$ //$NON-NLS-2$
			} else {
				viewer.setInput(workingSet);
			}
		}
	}
}
 
Example 16
Source File: WorkingSetsContentProvider.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public Object[] getChildren(Object parentElement) {
	if (parentElement instanceof IWorkingSet) {
		IWorkingSet workingSet = (IWorkingSet) parentElement;
		if (workingSet.isAggregateWorkingSet() && projectExplorer != null) {
			switch (projectExplorer.getRootMode()) {
				case ProjectExplorer.WORKING_SETS :
					return ((IAggregateWorkingSet) workingSet).getComponents();
				case ProjectExplorer.PROJECTS :
					return getWorkingSetElements(workingSet);
			}
		}
		return getWorkingSetElements(workingSet);
	}
	return NO_CHILDREN;
}
 
Example 17
Source File: GlobalsTwoPanelElementSelector2.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * We need to add the action for the working set.
 */
@Override
protected void fillViewMenu(IMenuManager menuManager) {
    super.fillViewMenu(menuManager);

    workingSetFilterActionGroup = new WorkingSetFilterActionGroup(getShell(), new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            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 {
                    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

                    if (window != null) {
                        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);
}
 
Example 18
Source File: TypeSelectionComponent.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void fillViewMenu(IMenuManager viewMenu) {
	if (!fMultipleSelection) {
		ToggleStatusLineAction showStatusLineAction= new ToggleStatusLineAction();
		showStatusLineAction.setChecked(fSettings.getBoolean(SHOW_STATUS_LINE));
		viewMenu.add(showStatusLineAction);
	}
	FullyQualifyDuplicatesAction fullyQualifyDuplicatesAction= new FullyQualifyDuplicatesAction();
	fullyQualifyDuplicatesAction.setChecked(fSettings.getBoolean(FULLY_QUALIFY_DUPLICATES));
	viewMenu.add(fullyQualifyDuplicatesAction);
	if (fScope == null) {
		fFilterActionGroup= new WorkingSetFilterActionGroup(getShell(),
			JavaPlugin.getActivePage(),
			new IPropertyChangeListener() {
				public void propertyChange(PropertyChangeEvent event) {
					IWorkingSet ws= (IWorkingSet)event.getNewValue();
					if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
						fScope= SearchEngine.createWorkspaceScope();
						fTitleLabel.setText(null);
					} else {
						fScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true);
						fTitleLabel.setText(ws.getLabel());
					}
					fViewer.setSearchScope(fScope, true);
				}
			});
		String setting= fSettings.get(WORKINGS_SET_SETTINGS);
		if (setting != null) {
			try {
				IMemento memento= XMLMemento.createReadRoot(new StringReader(setting));
				fFilterActionGroup.restoreState(memento);
			} catch (WorkbenchException e) {
			}
		}
		IWorkingSet ws= fFilterActionGroup.getWorkingSet();
		if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
			fScope= SearchEngine.createWorkspaceScope();
			fTitleLabel.setText(null);
		} else {
			fScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true);
			fTitleLabel.setText(ws.getLabel());
		}
		fFilterActionGroup.fillViewMenu(viewMenu);
	}
}