Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » how to convert an Ipath to an Ifile
how to convert an Ipath to an Ifile [message #168758] Wed, 10 December 2003 11:43 Go to next message
Eclipse UserFriend
Originally posted by: petchia.yahoo.com

I have a plugin I created for Eclipse that launches an external editor
using the IEditorLauncher interface. Apparently this interface changed in
3.0M4 to take an IPath object instead of an IFile object. How can I
convert the IPath into an IFile? I could easily convert IFile into IPath
however I would like to keep IFile since my code is already written around
it (ie. watching for file changes from other editors, opening an input
stream).

Regards,

-Bill
Re: how to convert an Ipath to an Ifile [message #168870 is a reply to message #168758] Wed, 10 December 2003 16:42 Go to previous message
Eclipse UserFriend
Probably the move to IPath is to support launching arbitrary files rather
than just files in the workspace, but I am speculating. An IPath is just a
high level data structure for manipulating paths, while an IFile is supposed
to represent a file resource in the workspace (although that is only the
case is the exists() method returns true).

To find a resource in the workspace who's actual location on disk is an
IPath use:

IWorkspaceRoot.findFilesForLocation(IPath location)

But if you are trying to launch the editor on a file that isn't in the
Eclipse workspace, you will need to be more careful.

Here are some utility functions that I have written and that I use:

public static IFile findFileResourceByLocation (String FileLocation)
{
IPath ResourcePath = new Path(FileLocation);
if (!ResourcePath.isAbsolute())
{
//this methods does not support relative paths
return null;
}
else
{
IFile[] Files =
getWorkspaceRoot().findFilesForLocation(ResourcePath);
return (Files.length > 0) ? Files[0] : null;
}
}

public static IFile[] findFileResourcesByLocation (String FileLocation)
{
IPath ResourcePath = new Path(FileLocation);
if (!ResourcePath.isAbsolute())
//this methods does not support relative paths
return new IFile[0];
else
return getWorkspaceRoot().findFilesForLocation(ResourcePath);
}

To call these with an IPath do something like (or change them to take
IPath's instead):

IPath p
findFileResourceByLocation(p.toOSString());


--
-----------------------------------------------
Patrick Baker
Stilo Corporation
pbaker@ca.stilo.com

"Hail, twin companionship, children of Mars."

This message, including any attachments, is for the sole use of the
intended recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure, copying, or
distribution is strictly prohibited. If you are not the intended
recipient(s) please contact the sender by reply email and destroy
all copies of the original message and any attachments.

"Bill Johnson" <petchia@yahoo.com> wrote in message
news:br7iep$hf7$1@eclipse.org...
> I have a plugin I created for Eclipse that launches an external editor
> using the IEditorLauncher interface. Apparently this interface changed in
> 3.0M4 to take an IPath object instead of an IFile object. How can I
> convert the IPath into an IFile? I could easily convert IFile into IPath
> however I would like to keep IFile since my code is already written around
> it (ie. watching for file changes from other editors, opening an input
> stream).
>
> Regards,
>
> -Bill
>
Previous Topic:building M5 fails
Next Topic:RPC plugin w/ two perspectives
Goto Forum:
  


Current Time: Wed Jun 18 14:00:34 EDT 2025

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

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

Back to the top