Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to get Project Path from File in Editor?
How to get Project Path from File in Editor? [message #330591] Mon, 04 August 2008 15:59 Go to next message
Eclipse UserFriend
Originally posted by: kevin.oberg.baesystems.com

Here is what I want to do:

Look at the file open in the active editor, then find out what project it
belongs to, then find the absolute path of said project. The path I am
referring to is the one that is displayed when you right-click a project=>
Properties => Resource => Location: absolute_path_i_need_here

I do not know how to get at that path, and all I have now is the active
editor itself.
Re: How to get Project Path from File in Editor? [message #330593 is a reply to message #330591] Mon, 04 August 2008 16:51 Go to previous messageGo to next message
Eclipse UserFriend
Kevin,

You could ask IEditorPart for the IEditorInput, test if it's an
IFileEditorInput, get the File, get the project, and then call
getLocation on the project. I file like I ought to ask why you'd want
the location since if you work directly with the underlying file system,
you're likely to get yourself into trouble...


Kevin Oberg wrote:
> Here is what I want to do:
>
> Look at the file open in the active editor, then find out what project
> it belongs to, then find the absolute path of said project. The path
> I am referring to is the one that is displayed when you right-click a
> project=> Properties => Resource => Location: absolute_path_i_need_here
>
> I do not know how to get at that path, and all I have now is the
> active editor itself.
>
Re: How to get Project Path from File in Editor? [message #330594 is a reply to message #330591] Mon, 04 August 2008 17:00 Go to previous messageGo to next message
Eclipse UserFriend
I use this code to get the active project.



IProject activeProject = null;
PlatformUI.getWorkbench().getDisplay().syncExec(
new Runnable() {
public void run() {
IWorkbenchWindow window = PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow();
if ( window != null ) {
IWorkbenchPage page = window.getActivePage();
if ( page != null ) {
IEditorPart editor = page.getActiveEditor();
if ( editor != null ) {
IEditorInput input = editor.getEditorInput();
if ( input instanceof IFileEditorInput ) {
IFileEditorInput fileInput = (IFileEditorInput) input;
activeProject = fileInput.getFile().getProject();
}
}
}
}
}
} );

-Jeevan
Re: How to get Project Path from File in Editor? [message #330618 is a reply to message #330593] Tue, 05 August 2008 14:38 Go to previous message
Eclipse UserFriend
Originally posted by: kevin.oberg.baesystems.com

Thank you much to both of you. In terms of why I want the location, I
need it in order to run some command line stuff on the files in question
among other things. My plug-in does quite a bit with the underlying file
system, but doesn't really use most of Eclipse's built-in stuff for that
stuff on account of I sub-classed most everything I need and ignored
everything I don't.
Previous Topic:IWorkbenchActivitySupport results in two sets of toolbar buttons?
Next Topic:One plugin exporting packages from jars inside itself
Goto Forum:
  


Current Time: Mon Apr 28 01:58:26 EDT 2025

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

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

Back to the top