{
@Override
protected IContributionItem[] getContributionItems()
{
// Get the list of editors that can open a class file
IEditorRegistry registry = PlatformUI.getWorkbench()
.getEditorRegistry();
// Get the current selections and return if nothing is selected
Iterator<?> selections = getSelections(selService);
if (selections == null)
return new IContributionItem[0];
// Attempt to find a single root
final List<IJavaElement> elements = getSelectedElements(selService,
IJavaElement.class);
final Set<PackageFragmentRoot> roots = new HashSet<PackageFragmentRoot>();
if (elements.size() > 0)
{
for (IJavaElement element : elements)
{
PackageFragmentRoot root = SelectUtils.getRoot(element);
if (root != null)
{
roots.add(root);
}
}
}
// Check which classes are selected
final List<IClassFile> classes = getSelectedElements(selService,
IClassFile.class);
List<IContributionItem> list = new ArrayList<IContributionItem>();
if (classes.size() > 0)
{
// Add an action to open all selected classes
IEditorDescriptor jdtClassViewer = registry
.findEditor(Startup.JDT_EDITOR_ID);
IEditorDescriptor jdRealignClassViewer = registry
.findEditor(Startup.EDITOR_ID);
list.add(new ActionContributionItem(new OpenClassesAction(jdtClassViewer.getLabel(),
jdRealignClassViewer, classes)));
}