|
Re: How to access a selected file in the Navigator? [message #42579 is a reply to message #42236] |
Wed, 21 May 2003 14:34  |
Eclipse User |
|
|
|
Hi Michael,
a handling of the selection could maybe look like this.
ISelection selection selection =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSele ctionService().g
etSelection();
IStructeredSelection strucSelection = null;
if (selection instanceof IStructeredSelection) {
strucSelection = (IStructeredSelection)) selection;
if (strucSelection.size()==0){
//handle wrong selection
} else if (strucSelection.size()==1){
Object selectedObj = structSelection.getFirstElement();
if (selectedObj instanceof IFile) {
IFile selectedFile = (IFile) selectionObj;
//do something with the file
} else if (selectedObj instanceof CompilationUnit){
CompilationUnit selectedUnit = (CompilationUnit) selectedObj;
//do something with the compilation unit
}
} else{
Iterator iter = structSelection.iterator();
//do something with the multiple selection
}
} else {
//handle wrong selection
}
Note that a selection could be multiple and that if you are in the Java
perspective you got a CompilationUnit instead of a IFile if a Java file was
selected. In most cases it's not necessary to get the Workbench from the
PlatformUI, because inherited methods will give you the Workbench as a
parameter, but using PlatformUI it should always work.
Take Care
Michael
"Michael Renz" <michael.renz@t-systems.com> schrieb im Newsbeitrag
news:bag6e2$nch$1@rogue.oti.com...
> Hi,
> I want to access a file from the workspace which I have selected in the
> Navigator from my plug-in. How can I do that?
>
> Thanks,
> Mike
>
|
|
|
Powered by
FUDForum. Page generated in 0.06112 seconds