Skip to content

Instantly share code, notes, and snippets.

@kickroot
Last active December 17, 2015 21:09
Show Gist options
  • Save kickroot/5673054 to your computer and use it in GitHub Desktop.
Save kickroot/5673054 to your computer and use it in GitHub Desktop.
Getting the selected file from a context menu popup in Eclipse.
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
ISelectionService service = window.getSelectionService();
IStructuredSelection structured = (IStructuredSelection) service.getSelection();
Object obj = structured.getFirstElement();
if (obj instanceof IAdaptable) {
IResource res = (IResource) (((IAdaptable) obj).getAdapter(IResource.class));
// You've got it!
System.out.println(res.getLocation().toString());
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment