Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » IFile device
IFile device [message #289610] Mon, 08 August 2005 17:18 Go to next message
Eclipse UserFriend
Originally posted by: no_email_please.hotmail.com

Is it possible to set the device of an IFile?
I'm converting a File to an IPath and the to an IFile but
when I do the last step, the device is set to null.

Here's what I do for this:
IFile myIFile =
ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( myIPath);

This file is external to the workspace, maybe that's why???

Any ideas?

Thanks
Nic
Re: IFile device [message #289612 is a reply to message #289610] Mon, 08 August 2005 18:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

You're probably mistaking IResource.getFullPath() as a file system path.
It is not. IResource.getLocation() is the correct way to get the file
system path of a resource.

getFileForLocation(file.getLocation()) will give you back the original
resource.
--


Nicolas Legare wrote:
> Is it possible to set the device of an IFile?
> I'm converting a File to an IPath and the to an IFile but
> when I do the last step, the device is set to null.
>
> Here's what I do for this:
> IFile myIFile =
> ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( myIPath);
>
> This file is external to the workspace, maybe that's why???
>
> Any ideas?
>
> Thanks
> Nic
>
>
Re: IFile device [message #289633 is a reply to message #289612] Tue, 09 August 2005 09:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no_email_please.hotmail.com

Thanks for replying John, unfortunately getLocation is part of IFile and
returns an IPath.
I don't quite understand how still helps me. I need an IFile with the device
set, you can see
that in the debugger.

Problem might be because the file resides outside of the workspace...

Nic


"John Arthorne" <john@eclipsefaq.org> wrote in message
news:dd8l5r$s5l$1@news.eclipse.org...
> You're probably mistaking IResource.getFullPath() as a file system path.
> It is not. IResource.getLocation() is the correct way to get the file
> system path of a resource.
>
> getFileForLocation(file.getLocation()) will give you back the original
> resource.
> --
>
>
> Nicolas Legare wrote:
> > Is it possible to set the device of an IFile?
> > I'm converting a File to an IPath and the to an IFile but
> > when I do the last step, the device is set to null.
> >
> > Here's what I do for this:
> > IFile myIFile =
> > ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( myIPath);
> >
> > This file is external to the workspace, maybe that's why???
> >
> > Any ideas?
> >
> > Thanks
> > Nic
> >
> >
Re: IFile device [message #289636 is a reply to message #289633] Tue, 09 August 2005 10:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

If you are running on windows, then IResource.getLocation() will return
you a path with the device set. If you look at an IFile object in the
debugger, you will see two fields: path and workspace. These fields
have NOTHING to do with the file system. The path field has no device
because it is a logical path that is used internally to find that file
in the workspace tree. That path object will never have a device
because it doesn't represent a path to a file on a device.
--

Nicolas Legare wrote:
> Thanks for replying John, unfortunately getLocation is part of IFile and
> returns an IPath.
> I don't quite understand how still helps me. I need an IFile with the device
> set, you can see
> that in the debugger.
>
> Problem might be because the file resides outside of the workspace...
>
> Nic
>
>
> "John Arthorne" <john@eclipsefaq.org> wrote in message
> news:dd8l5r$s5l$1@news.eclipse.org...
>
>>You're probably mistaking IResource.getFullPath() as a file system path.
>>It is not. IResource.getLocation() is the correct way to get the file
>>system path of a resource.
>>
>>getFileForLocation(file.getLocation()) will give you back the original
>>resource.
>>--
>>
>>
>>Nicolas Legare wrote:
>>
>>>Is it possible to set the device of an IFile?
>>>I'm converting a File to an IPath and the to an IFile but
>>>when I do the last step, the device is set to null.
>>>
>>>Here's what I do for this:
>>>IFile myIFile =
>>> ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( myIPath);
>>>
>>>This file is external to the workspace, maybe that's why???
>>>
>>>Any ideas?
>>>
>>>Thanks
>>>Nic
>>>
>>>
>
>
>
Re: IFile device [message #289649 is a reply to message #289636] Tue, 09 August 2005 11:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no_email_please.hotmail.com

Thanks again John,

Makes sense, but this is a complete bummer for me. I thought this was
why I get file not found when I try to open one of IBM's (Rational) editor
with an IFile.

Thanks
Nic

"John Arthorne" <john@eclipsefaq.org> wrote in message
news:ddad9g$qq4$1@news.eclipse.org...
> If you are running on windows, then IResource.getLocation() will return
> you a path with the device set. If you look at an IFile object in the
> debugger, you will see two fields: path and workspace. These fields
> have NOTHING to do with the file system. The path field has no device
> because it is a logical path that is used internally to find that file
> in the workspace tree. That path object will never have a device
> because it doesn't represent a path to a file on a device.
> --
>
> Nicolas Legare wrote:
> > Thanks for replying John, unfortunately getLocation is part of IFile and
> > returns an IPath.
> > I don't quite understand how still helps me. I need an IFile with the
device
> > set, you can see
> > that in the debugger.
> >
> > Problem might be because the file resides outside of the workspace...
> >
> > Nic
> >
> >
> > "John Arthorne" <john@eclipsefaq.org> wrote in message
> > news:dd8l5r$s5l$1@news.eclipse.org...
> >
> >>You're probably mistaking IResource.getFullPath() as a file system path.
> >>It is not. IResource.getLocation() is the correct way to get the file
> >>system path of a resource.
> >>
> >>getFileForLocation(file.getLocation()) will give you back the original
> >>resource.
> >>--
> >>
> >>
> >>Nicolas Legare wrote:
> >>
> >>>Is it possible to set the device of an IFile?
> >>>I'm converting a File to an IPath and the to an IFile but
> >>>when I do the last step, the device is set to null.
> >>>
> >>>Here's what I do for this:
> >>>IFile myIFile =
> >>> ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( myIPath);
> >>>
> >>>This file is external to the workspace, maybe that's why???
> >>>
> >>>Any ideas?
> >>>
> >>>Thanks
> >>>Nic
> >>>
> >>>
> >
> >
> >
Re: IFile device [message #289657 is a reply to message #289610] Tue, 09 August 2005 12:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

>
> This file is external to the workspace, maybe that's why???
>
> Any ideas?
>
> Thanks
> Nic
>
>

Well, that's part of the problem. It doesn't matter what you do, a file
external to the workspace cannot be made into an IFile. IFile's can only
be for files in the workspace.

--
Thanks,
Rich Kulp
Re: IFile device [message #289749 is a reply to message #289657] Wed, 10 August 2005 11:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

Rich Kulp wrote:
> Well, that's part of the problem. It doesn't matter what you do, a file
> external to the workspace cannot be made into an IFile. IFile's can only
> be for files in the workspace.
>

I think I misunderstood the problem. It sounded like he already had an
IFile object; by "external to the workspace" I thought he meant a linked
file or a file in a project whose location is external to the workspace.
The term "workspace" can mean the directory on disk
(c:\eclipse\workspace), or it can mean the API IWorkspace. By
definition every IFile belongs to the IWorkspace (IFile.getWorkspace()
never returns null), but an IFile's location on disk need not
necessarily be inside the c:\eclipse\workspace directory. The question
was ambiguous...
--
Re: IFile device [message #289755 is a reply to message #289749] Wed, 10 August 2005 11:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no_email_please.hotmail.com

Ok, well let me try to explain this a little better. I'm a little vague on
how all of these objects or interfaces work together.

Basically what I need to do is to allow eclipse (or in my case Rational)
to open a file passed in as a parameter on the command line. The software
doesn't do it by itself so I have to code this.

So far I have created a class which implements IStartup. And in the
earlyStartup method I can parse the command line parameters. Now
what's left is to get it to open a file whose outside of the workspace
(outside of the "workspace" folder on your hardrive). I did get it to
work with eclipse with this code (or something like it, I'm modifying
it so it may not work), myFilePath could be anywhere on the harddrive:

File file = new File(myFilePath);
IPath path = new Path(file.getAbsolutePath());
IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
IWorkbenchWindow window = myWorkbench.getActiveWorkbenchWindow();

try{
if (window != null){
IWorkbenchPage iwp = window.getActivePage();
System.out.println(iwp.getPerspective().getId());
org.eclipse.ui.ide.IDE.openEditor(iwp, ifile,
"org.eclipse.ui.DefaultTextEditor");
}
}catch(Exception e){
System.out.println(e);
}

Now when I move this code to Rational and try to get it to open a file
with their HTML input editor, I get file not found. So I started looking
through the different objects in the debugger and noticed that my IFile
didn't have the device set. So I thought that was it. I need to get this
populated...

After doing some more research on this forum I heard about a linked file.
Funny, you just mentioned it too. I can't seem to find much about it though.
Would this help me???

Thanks, really appreciate it.
Nic

"John Arthorne" <john@eclipsefaq.org> wrote in message
news:ddd683$th2$1@news.eclipse.org...
> Rich Kulp wrote:
> > Well, that's part of the problem. It doesn't matter what you do, a file
> > external to the workspace cannot be made into an IFile. IFile's can only
> > be for files in the workspace.
> >
>
> I think I misunderstood the problem. It sounded like he already had an
> IFile object; by "external to the workspace" I thought he meant a linked
> file or a file in a project whose location is external to the workspace.
> The term "workspace" can mean the directory on disk
> (c:\eclipse\workspace), or it can mean the API IWorkspace. By
> definition every IFile belongs to the IWorkspace (IFile.getWorkspace()
> never returns null), but an IFile's location on disk need not
> necessarily be inside the c:\eclipse\workspace directory. The question
> was ambiguous...
> --
Re: IFile device [message #289789 is a reply to message #289755] Wed, 10 August 2005 14:53 Go to previous message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

See IFile.createLink. This method will create a file whose contents are
at an arbitrary location on disk. This file must still belong to some
project though:

IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("Test");
IFile file = p.getFile("TestFile.txt");
file.createLink("c:\\temp\\SomePlaceOnDisk.txt", 0, null);
--

Nicolas Legare wrote:
> Ok, well let me try to explain this a little better. I'm a little vague on
> how all of these objects or interfaces work together.
>
> Basically what I need to do is to allow eclipse (or in my case Rational)
> to open a file passed in as a parameter on the command line. The software
> doesn't do it by itself so I have to code this.
>
> So far I have created a class which implements IStartup. And in the
> earlyStartup method I can parse the command line parameters. Now
> what's left is to get it to open a file whose outside of the workspace
> (outside of the "workspace" folder on your hardrive). I did get it to
> work with eclipse with this code (or something like it, I'm modifying
> it so it may not work), myFilePath could be anywhere on the harddrive:
>
> File file = new File(myFilePath);
> IPath path = new Path(file.getAbsolutePath());
> IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> IWorkbenchWindow window = myWorkbench.getActiveWorkbenchWindow();
>
> try{
> if (window != null){
> IWorkbenchPage iwp = window.getActivePage();
> System.out.println(iwp.getPerspective().getId());
> org.eclipse.ui.ide.IDE.openEditor(iwp, ifile,
> "org.eclipse.ui.DefaultTextEditor");
> }
> }catch(Exception e){
> System.out.println(e);
> }
>
> Now when I move this code to Rational and try to get it to open a file
> with their HTML input editor, I get file not found. So I started looking
> through the different objects in the debugger and noticed that my IFile
> didn't have the device set. So I thought that was it. I need to get this
> populated...
>
> After doing some more research on this forum I heard about a linked file.
> Funny, you just mentioned it too. I can't seem to find much about it though.
> Would this help me???
>
> Thanks, really appreciate it.
> Nic
>
> "John Arthorne" <john@eclipsefaq.org> wrote in message
> news:ddd683$th2$1@news.eclipse.org...
>
>>Rich Kulp wrote:
>>
>>>Well, that's part of the problem. It doesn't matter what you do, a file
>>>external to the workspace cannot be made into an IFile. IFile's can only
>>>be for files in the workspace.
>>>
>>
>>I think I misunderstood the problem. It sounded like he already had an
>>IFile object; by "external to the workspace" I thought he meant a linked
>>file or a file in a project whose location is external to the workspace.
>>The term "workspace" can mean the directory on disk
>>(c:\eclipse\workspace), or it can mean the API IWorkspace. By
>>definition every IFile belongs to the IWorkspace (IFile.getWorkspace()
>>never returns null), but an IFile's location on disk need not
>>necessarily be inside the c:\eclipse\workspace directory. The question
>>was ambiguous...
>>--
>
>
>
Previous Topic:Unable to find feature.xml
Next Topic:IFile in an IProject???
Goto Forum:
  


Current Time: Sun May 11 01:54:56 EDT 2025

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

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

Back to the top