Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to access a selected file in the Navigator?
How to access a selected file in the Navigator? [message #42236] Wed, 21 May 2003 11:36 Go to next message
Eclipse UserFriend
Originally posted by: michael.renz.t-systems.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
Re: How to access a selected file in the Navigator? [message #42579 is a reply to message #42236] Wed, 21 May 2003 14:34 Go to previous message
Eclipse UserFriend
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
>
Previous Topic:[Howto] actually get Drag-and-Drop to work on a Viewer?
Next Topic:Configure access to read only CVS archive?
Goto Forum:
  


Current Time: Tue Jul 15 02:13:58 EDT 2025

Powered by FUDForum. Page generated in 0.05231 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top