Eclipse selection is null

224 Views Asked by At

In my eclipse plugin I need to get the selection in the package explorer.
I found out that this works like this:

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ISelectionService service = window.getSelectionService();
IStructuredSelection structured = (IStructuredSelection) service.getSelection("org.eclipse.jdt.ui.PackageExplorer");
Object selection = structured.getFirstElement();

This works fine in 99% of all cases but I recently ran into a case where the getSelection("org.eclipse.jdt.ui.PackageExplorer"); returns null although I can clearly see that I have something selected in the package explorer...

How can that be?

1

There are 1 best solutions below

0
greg-449 On BEST ANSWER

Check that the view is not the Project Explorer rather than Package Explorer. They can look very similar and both default to appearing in the same place.