Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 19: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 20:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33224
Registered: July 2009
Senior Member
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.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to get Project Path from File in Editor? [message #330594 is a reply to message #330591] Mon, 04 August 2008 21:00 Go to previous messageGo to next message
jeevan is currently offline jeevanFriend
Messages: 20
Registered: July 2009
Junior Member
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 18: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: Sun Oct 06 14:17:42 GMT 2024

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

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

Back to the top