Last active
December 17, 2015 21:09
-
-
Save kickroot/5673054 to your computer and use it in GitHub Desktop.
Getting the selected file from a context menu popup in Eclipse.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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