Raven
Raven

Reputation: 3516

Eclipse selection is null

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?

Upvotes: 0

Views: 228

Answers (1)

greg-449
greg-449

Reputation: 111142

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.

Upvotes: 1

Related Questions