Home » Eclipse Projects » Eclipse Platform » File to IFile
File to IFile [message #157401] |
Sun, 16 November 2003 03:34 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Hello,
Does anyone know how to map a java.io.file to an IFile? I create a file and
I want to make that file into a type IFile. Thanks in advance.
Raj
|
|
|
Re: File to IFile [message #157409 is a reply to message #157401] |
Sun, 16 November 2003 04:45 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: andrewip.shaw.ca
Hey Raj,
I've found a workaround that may help you out. Assuming you have an IFile
object called "someFile", you can map to a java.io.File object as follows:
java.io.File file = new java.io.File (someFile.getFullPath( ).toString( ) );
Hope that helps,
Andrew Ip
"Raj Chari" <rc316@shaw.ca> wrote in message
news:bp6r4v$jis$1@eclipse.org...
> Hello,
>
> Does anyone know how to map a java.io.file to an IFile? I create a file
and
> I want to make that file into a type IFile. Thanks in advance.
>
> Raj
>
>
|
|
|
Re: File to IFile [message #157417 is a reply to message #157409] |
Sun, 16 November 2003 04:58 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
I should make my question a little clearer.
I create a file, in some code, called sample.txt. I now want to give that
file an IFile handle, are there any suggestions on how to do it?
Thanks again
Raj
"Andrew Ip" <andrewip@shaw.ca> wrote in message
news:bp6vad$ms1$1@eclipse.org...
> Hey Raj,
>
> I've found a workaround that may help you out. Assuming you have an IFile
> object called "someFile", you can map to a java.io.File object as follows:
>
> java.io.File file = new java.io.File
(someFile.getFullPath( ).toString( ) );
>
> Hope that helps,
> Andrew Ip
>
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bp6r4v$jis$1@eclipse.org...
> > Hello,
> >
> > Does anyone know how to map a java.io.file to an IFile? I create a file
> and
> > I want to make that file into a type IFile. Thanks in advance.
> >
> > Raj
> >
> >
>
>
|
|
| |
Re: File to IFile [message #157707 is a reply to message #157663] |
Mon, 17 November 2003 14:52 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: richkulp.NO.SPAM.us.ibm.com
But remember, this only works for files that are in the workspace. If
the file is not in the workspace anywhere (i.e. some generic file
someplace else), you can't get an IFile to it.
--
Thanks, Rich Kulp
|
|
|
Re: File to IFile [message #158075 is a reply to message #157707] |
Tue, 18 November 2003 01:14 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
Well, you could create a linked file in the workspace that works as a
surrogate for the non-workspace file.
(Also, when going the other way, from IFile to File, you want to use
getLocation() not getFullPath().)
Bob
"Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
news:bpan7b$7rr$2@eclipse.org...
> But remember, this only works for files that are in the workspace. If
> the file is not in the workspace anywhere (i.e. some generic file
> someplace else), you can't get an IFile to it.
>
> --
> Thanks, Rich Kulp
>
>
|
|
|
Re: File to IFile [message #158160 is a reply to message #158075] |
Tue, 18 November 2003 08:15 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Hi Bob and Rich,
Thanks for your help. The thing is that the file I'm creating is done on
the fly as my plugin runs and so it's not in the workspace.
Basically, this is what I'm trying to do.
I'm trying to create a newsgroup client plugin for eclipse and I create a
view in which the messages are displayed in. When I double-click a message,
I would like to open it in the text editor.
The way I'm going about this is that I'm grabbing the information from the
doubleclick event and writing it into temp file and I want to display this
temp file in the editor. From what I've read and what I've tried, it seems
that this is not possible if this file is not associated in the workspace,
as you guys have pointed out.
In your opinion, is what I'm trying to do possible?
Thanks again,
Raj
"Bob Foster" <bob@objfac.com> wrote in message
news:bpbqol$kct$1@eclipse.org...
> Well, you could create a linked file in the workspace that works as a
> surrogate for the non-workspace file.
>
> (Also, when going the other way, from IFile to File, you want to use
> getLocation() not getFullPath().)
>
> Bob
>
> "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> news:bpan7b$7rr$2@eclipse.org...
> > But remember, this only works for files that are in the workspace. If
> > the file is not in the workspace anywhere (i.e. some generic file
> > someplace else), you can't get an IFile to it.
> >
> > --
> > Thanks, Rich Kulp
> >
> >
>
>
|
|
|
Re: File to IFile [message #158176 is a reply to message #158160] |
Tue, 18 November 2003 09:16 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: eclipse.tkilla.ch
Raj Chari wrote:
> Hi Bob and Rich,
>
> Thanks for your help. The thing is that the file I'm creating is done on
> the fly as my plugin runs and so it's not in the workspace.
> Basically, this is what I'm trying to do.
> I'm trying to create a newsgroup client plugin for eclipse and I create a
> view in which the messages are displayed in. When I double-click a message,
> I would like to open it in the text editor.
> The way I'm going about this is that I'm grabbing the information from the
> doubleclick event and writing it into temp file and I want to display this
> temp file in the editor. From what I've read and what I've tried, it seems
> that this is not possible if this file is not associated in the workspace,
> as you guys have pointed out.
> In your opinion, is what I'm trying to do possible?
You don't really need an IFile if you don't intend to store anything on
disk - you could just create your own IEditorInput and IDocumentProvider
and provider your message in as an instance of Document.
-tom
|
|
|
Re: File to IFile [message #158303 is a reply to message #158176] |
Tue, 18 November 2003 17:20 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Thanks Tom,
Do you know of any examples of how this is done? If so, could you point it
out to me?
Otherwise, I'll try to figure it out on my own. Thanks for your help
Raj
"Tom Eicher" <eclipse@tkilla.ch> wrote in message
news:bpcntt$gl8$1@eclipse.org...
> Raj Chari wrote:
> > Hi Bob and Rich,
> >
> > Thanks for your help. The thing is that the file I'm creating is done
on
> > the fly as my plugin runs and so it's not in the workspace.
> > Basically, this is what I'm trying to do.
> > I'm trying to create a newsgroup client plugin for eclipse and I create
a
> > view in which the messages are displayed in. When I double-click a
message,
> > I would like to open it in the text editor.
> > The way I'm going about this is that I'm grabbing the information from
the
> > doubleclick event and writing it into temp file and I want to display
this
> > temp file in the editor. From what I've read and what I've tried, it
seems
> > that this is not possible if this file is not associated in the
workspace,
> > as you guys have pointed out.
> > In your opinion, is what I'm trying to do possible?
>
> You don't really need an IFile if you don't intend to store anything on
> disk - you could just create your own IEditorInput and IDocumentProvider
> and provider your message in as an instance of Document.
>
> -tom
>
|
|
|
Re: File to IFile [message #158701 is a reply to message #158160] |
Wed, 19 November 2003 07:28 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
As long as the file is in the workspace, I think you can do it. Use the
..metadata area created for your plugin, which you can get the path of by
calling getStateLocation() in your plugin. toOSString() will get you a path
suitable for java.io.File and you're off and running. When you have a File
created there, call the following to get an IFile:
public IFile fileToIFile(File f) {
String p = f.getPath();
IPath path = new Path(p);
return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}
(I just typed that in; if it doesn't compile, fix it.) Then, I have this bit
of code lying around that will do the rest:
protected IEditorPart openEditor(IFile file, String editorId) {
IEditorPart editor = null;
IEditorInput input = new FileEditorInput(file);
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
if (page != null) {
editor = page.findEditor(input);
if (editor != null) {
page.bringToTop(editor);
}
else {
try {
editor = page.openEditor(input, editorId);
} catch (PartInitException e) {
//log the error or something
}
}
}
return editor;
}
I haven't tried exactly this case and there's probably shorter code to do it
(I try to avoid Eclipse's IResource, uh, stuff as much as I can), but that's
the general idea.
Bob
"Raj Chari" <rc316@shaw.ca> wrote in message
news:bpckbl$bvc$1@eclipse.org...
> Hi Bob and Rich,
>
> Thanks for your help. The thing is that the file I'm creating is done on
> the fly as my plugin runs and so it's not in the workspace.
> Basically, this is what I'm trying to do.
> I'm trying to create a newsgroup client plugin for eclipse and I create a
> view in which the messages are displayed in. When I double-click a
message,
> I would like to open it in the text editor.
> The way I'm going about this is that I'm grabbing the information from the
> doubleclick event and writing it into temp file and I want to display this
> temp file in the editor. From what I've read and what I've tried, it
seems
> that this is not possible if this file is not associated in the workspace,
> as you guys have pointed out.
> In your opinion, is what I'm trying to do possible?
> Thanks again,
>
> Raj
> "Bob Foster" <bob@objfac.com> wrote in message
> news:bpbqol$kct$1@eclipse.org...
> > Well, you could create a linked file in the workspace that works as a
> > surrogate for the non-workspace file.
> >
> > (Also, when going the other way, from IFile to File, you want to use
> > getLocation() not getFullPath().)
> >
> > Bob
> >
> > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > news:bpan7b$7rr$2@eclipse.org...
> > > But remember, this only works for files that are in the workspace. If
> > > the file is not in the workspace anywhere (i.e. some generic file
> > > someplace else), you can't get an IFile to it.
> > >
> > > --
> > > Thanks, Rich Kulp
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #158745 is a reply to message #158701] |
Wed, 19 November 2003 08:58 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Thank you so much Bob!
Raj
"Bob Foster" <bob@objfac.com> wrote in message
news:bpf514$940$1@eclipse.org...
> As long as the file is in the workspace, I think you can do it. Use the
> .metadata area created for your plugin, which you can get the path of by
> calling getStateLocation() in your plugin. toOSString() will get you a
path
> suitable for java.io.File and you're off and running. When you have a File
> created there, call the following to get an IFile:
>
> public IFile fileToIFile(File f) {
> String p = f.getPath();
> IPath path = new Path(p);
> return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> }
>
> (I just typed that in; if it doesn't compile, fix it.) Then, I have this
bit
> of code lying around that will do the rest:
>
> protected IEditorPart openEditor(IFile file, String editorId) {
> IEditorPart editor = null;
> IEditorInput input = new FileEditorInput(file);
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> if (page != null) {
> editor = page.findEditor(input);
> if (editor != null) {
> page.bringToTop(editor);
> }
> else {
> try {
> editor = page.openEditor(input, editorId);
> } catch (PartInitException e) {
> //log the error or something
> }
> }
> }
> return editor;
> }
>
> I haven't tried exactly this case and there's probably shorter code to do
it
> (I try to avoid Eclipse's IResource, uh, stuff as much as I can), but
that's
> the general idea.
>
> Bob
>
>
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bpckbl$bvc$1@eclipse.org...
> > Hi Bob and Rich,
> >
> > Thanks for your help. The thing is that the file I'm creating is done
on
> > the fly as my plugin runs and so it's not in the workspace.
> > Basically, this is what I'm trying to do.
> > I'm trying to create a newsgroup client plugin for eclipse and I create
a
> > view in which the messages are displayed in. When I double-click a
> message,
> > I would like to open it in the text editor.
> > The way I'm going about this is that I'm grabbing the information from
the
> > doubleclick event and writing it into temp file and I want to display
this
> > temp file in the editor. From what I've read and what I've tried, it
> seems
> > that this is not possible if this file is not associated in the
workspace,
> > as you guys have pointed out.
> > In your opinion, is what I'm trying to do possible?
> > Thanks again,
> >
> > Raj
> > "Bob Foster" <bob@objfac.com> wrote in message
> > news:bpbqol$kct$1@eclipse.org...
> > > Well, you could create a linked file in the workspace that works as a
> > > surrogate for the non-workspace file.
> > >
> > > (Also, when going the other way, from IFile to File, you want to use
> > > getLocation() not getFullPath().)
> > >
> > > Bob
> > >
> > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > news:bpan7b$7rr$2@eclipse.org...
> > > > But remember, this only works for files that are in the workspace.
If
> > > > the file is not in the workspace anywhere (i.e. some generic file
> > > > someplace else), you can't get an IFile to it.
> > > >
> > > > --
> > > > Thanks, Rich Kulp
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #159080 is a reply to message #158745] |
Wed, 19 November 2003 19:14 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Hi,
I just re-read your post and my problem lies in the fact that I'm creating
the file when I run my plugin, I have choice in where to store the file but
it's not registered in the workspace. Will this still work if the file is
not in the workspace. The other person suggested using IDocument and
IEditorInput and I'm not sure how to use this. Does anyone know how to use
the IEditorInput and IDocument as mentioned in a previous post? I'm looking
for examples to see how to use IDocument.
Thanks
Raj
"Raj Chari" <rc316@shaw.ca> wrote in message
news:bpfb7k$ff5$1@eclipse.org...
> Thank you so much Bob!
>
> Raj
> "Bob Foster" <bob@objfac.com> wrote in message
> news:bpf514$940$1@eclipse.org...
> > As long as the file is in the workspace, I think you can do it. Use the
> > .metadata area created for your plugin, which you can get the path of by
> > calling getStateLocation() in your plugin. toOSString() will get you a
> path
> > suitable for java.io.File and you're off and running. When you have a
File
> > created there, call the following to get an IFile:
> >
> > public IFile fileToIFile(File f) {
> > String p = f.getPath();
> > IPath path = new Path(p);
> > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > }
> >
> > (I just typed that in; if it doesn't compile, fix it.) Then, I have this
> bit
> > of code lying around that will do the rest:
> >
> > protected IEditorPart openEditor(IFile file, String editorId) {
> > IEditorPart editor = null;
> > IEditorInput input = new FileEditorInput(file);
> > IWorkbenchPage page =
> > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > if (page != null) {
> > editor = page.findEditor(input);
> > if (editor != null) {
> > page.bringToTop(editor);
> > }
> > else {
> > try {
> > editor = page.openEditor(input, editorId);
> > } catch (PartInitException e) {
> > //log the error or something
> > }
> > }
> > }
> > return editor;
> > }
> >
> > I haven't tried exactly this case and there's probably shorter code to
do
> it
> > (I try to avoid Eclipse's IResource, uh, stuff as much as I can), but
> that's
> > the general idea.
> >
> > Bob
> >
> >
> >
> > "Raj Chari" <rc316@shaw.ca> wrote in message
> > news:bpckbl$bvc$1@eclipse.org...
> > > Hi Bob and Rich,
> > >
> > > Thanks for your help. The thing is that the file I'm creating is done
> on
> > > the fly as my plugin runs and so it's not in the workspace.
> > > Basically, this is what I'm trying to do.
> > > I'm trying to create a newsgroup client plugin for eclipse and I
create
> a
> > > view in which the messages are displayed in. When I double-click a
> > message,
> > > I would like to open it in the text editor.
> > > The way I'm going about this is that I'm grabbing the information from
> the
> > > doubleclick event and writing it into temp file and I want to display
> this
> > > temp file in the editor. From what I've read and what I've tried, it
> > seems
> > > that this is not possible if this file is not associated in the
> workspace,
> > > as you guys have pointed out.
> > > In your opinion, is what I'm trying to do possible?
> > > Thanks again,
> > >
> > > Raj
> > > "Bob Foster" <bob@objfac.com> wrote in message
> > > news:bpbqol$kct$1@eclipse.org...
> > > > Well, you could create a linked file in the workspace that works as
a
> > > > surrogate for the non-workspace file.
> > > >
> > > > (Also, when going the other way, from IFile to File, you want to use
> > > > getLocation() not getFullPath().)
> > > >
> > > > Bob
> > > >
> > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > But remember, this only works for files that are in the workspace.
> If
> > > > > the file is not in the workspace anywhere (i.e. some generic file
> > > > > someplace else), you can't get an IFile to it.
> > > > >
> > > > > --
> > > > > Thanks, Rich Kulp
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #159251 is a reply to message #159080] |
Thu, 20 November 2003 07:14 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
I think you're headed off in the wrong direction. Please re-read my post
until you understand it. ;-}
Bob
"Raj Chari" <rc316@shaw.ca> wrote in message
news:bpgfbm$vfp$1@eclipse.org...
> Hi,
>
> I just re-read your post and my problem lies in the fact that I'm creating
> the file when I run my plugin, I have choice in where to store the file
but
> it's not registered in the workspace. Will this still work if the file is
> not in the workspace. The other person suggested using IDocument and
> IEditorInput and I'm not sure how to use this. Does anyone know how to
use
> the IEditorInput and IDocument as mentioned in a previous post? I'm
looking
> for examples to see how to use IDocument.
> Thanks
>
> Raj
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bpfb7k$ff5$1@eclipse.org...
> > Thank you so much Bob!
> >
> > Raj
> > "Bob Foster" <bob@objfac.com> wrote in message
> > news:bpf514$940$1@eclipse.org...
> > > As long as the file is in the workspace, I think you can do it. Use
the
> > > .metadata area created for your plugin, which you can get the path of
by
> > > calling getStateLocation() in your plugin. toOSString() will get you a
> > path
> > > suitable for java.io.File and you're off and running. When you have a
> File
> > > created there, call the following to get an IFile:
> > >
> > > public IFile fileToIFile(File f) {
> > > String p = f.getPath();
> > > IPath path = new Path(p);
> > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > }
> > >
> > > (I just typed that in; if it doesn't compile, fix it.) Then, I have
this
> > bit
> > > of code lying around that will do the rest:
> > >
> > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > IEditorPart editor = null;
> > > IEditorInput input = new FileEditorInput(file);
> > > IWorkbenchPage page =
> > > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > if (page != null) {
> > > editor = page.findEditor(input);
> > > if (editor != null) {
> > > page.bringToTop(editor);
> > > }
> > > else {
> > > try {
> > > editor = page.openEditor(input, editorId);
> > > } catch (PartInitException e) {
> > > //log the error or something
> > > }
> > > }
> > > }
> > > return editor;
> > > }
> > >
> > > I haven't tried exactly this case and there's probably shorter code to
> do
> > it
> > > (I try to avoid Eclipse's IResource, uh, stuff as much as I can), but
> > that's
> > > the general idea.
> > >
> > > Bob
> > >
> > >
> > >
> > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > news:bpckbl$bvc$1@eclipse.org...
> > > > Hi Bob and Rich,
> > > >
> > > > Thanks for your help. The thing is that the file I'm creating is
done
> > on
> > > > the fly as my plugin runs and so it's not in the workspace.
> > > > Basically, this is what I'm trying to do.
> > > > I'm trying to create a newsgroup client plugin for eclipse and I
> create
> > a
> > > > view in which the messages are displayed in. When I double-click a
> > > message,
> > > > I would like to open it in the text editor.
> > > > The way I'm going about this is that I'm grabbing the information
from
> > the
> > > > doubleclick event and writing it into temp file and I want to
display
> > this
> > > > temp file in the editor. From what I've read and what I've tried,
it
> > > seems
> > > > that this is not possible if this file is not associated in the
> > workspace,
> > > > as you guys have pointed out.
> > > > In your opinion, is what I'm trying to do possible?
> > > > Thanks again,
> > > >
> > > > Raj
> > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > news:bpbqol$kct$1@eclipse.org...
> > > > > Well, you could create a linked file in the workspace that works
as
> a
> > > > > surrogate for the non-workspace file.
> > > > >
> > > > > (Also, when going the other way, from IFile to File, you want to
use
> > > > > getLocation() not getFullPath().)
> > > > >
> > > > > Bob
> > > > >
> > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > But remember, this only works for files that are in the
workspace.
> > If
> > > > > > the file is not in the workspace anywhere (i.e. some generic
file
> > > > > > someplace else), you can't get an IFile to it.
> > > > > >
> > > > > > --
> > > > > > Thanks, Rich Kulp
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #159315 is a reply to message #158303] |
Thu, 20 November 2003 10:21 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: eclipse.tkilla.ch
Raj Chari wrote:
> Thanks Tom,
>
> Do you know of any examples of how this is done? If so, could you point it
> out to me?
> Otherwise, I'll try to figure it out on my own. Thanks for your help
You could use StorageDocumentProvider as the provider for your editor.
As input, implement your own instance of IStorageEditorInput and
IStorage (you could copy code from e.g. SystemFileStorage and
SystemFileEditorInput in PDE and modify it).
This way, you would be independent of whehter you write to a temporary
file or not. If do want to write a file, the other options given in the
thread might be a better option.
-tom
|
|
|
Re: File to IFile [message #159707 is a reply to message #159251] |
Thu, 20 November 2003 20:06 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Hi,
So I used your idea Bob and I wrote up the following code:
File myFile = new File("F:/ePost/workspace/test.txt");
FileWriter fw = new FileWriter(myFile);
fw.write(sb.toString());
fw.close();
file = fileToIFile(myFile);
openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
I wrote the two other functions that were suggested:
public IFile fileToIFile(File f) {
String p = f.getAbsolutePath();
IPath path = new Path(p);
return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}
protected IEditorPart openEditor(IFile file, String editorId) {
IEditorPart editor = null;
IEditorInput input = new FileEditorInput(file);
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
if (page != null) {
editor = page.findEditor(input);
if (editor != null) {
page.bringToTop(editor);
}
else {
try {
editor = page.openEditor(input, editorId);
} catch (PartInitException e) {
showMessage(e.getMessage());
}
}
}
return editor;
}
My output was that the file tried to open up in the editor and
in the texteditor, it said, "Resource /ePost/workspace/test.txt does not
exist."
Can someone tell me why this would happen and/or how this can be fixed?
Thanks again
Raj
"Bob Foster" <bob@objfac.com> wrote in message
news:bphok5$6us$1@eclipse.org...
> I think you're headed off in the wrong direction. Please re-read my post
> until you understand it. ;-}
>
> Bob
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bpgfbm$vfp$1@eclipse.org...
> > Hi,
> >
> > I just re-read your post and my problem lies in the fact that I'm
creating
> > the file when I run my plugin, I have choice in where to store the file
> but
> > it's not registered in the workspace. Will this still work if the file
is
> > not in the workspace. The other person suggested using IDocument and
> > IEditorInput and I'm not sure how to use this. Does anyone know how to
> use
> > the IEditorInput and IDocument as mentioned in a previous post? I'm
> looking
> > for examples to see how to use IDocument.
> > Thanks
> >
> > Raj
> >
> > "Raj Chari" <rc316@shaw.ca> wrote in message
> > news:bpfb7k$ff5$1@eclipse.org...
> > > Thank you so much Bob!
> > >
> > > Raj
> > > "Bob Foster" <bob@objfac.com> wrote in message
> > > news:bpf514$940$1@eclipse.org...
> > > > As long as the file is in the workspace, I think you can do it. Use
> the
> > > > .metadata area created for your plugin, which you can get the path
of
> by
> > > > calling getStateLocation() in your plugin. toOSString() will get you
a
> > > path
> > > > suitable for java.io.File and you're off and running. When you have
a
> > File
> > > > created there, call the following to get an IFile:
> > > >
> > > > public IFile fileToIFile(File f) {
> > > > String p = f.getPath();
> > > > IPath path = new Path(p);
> > > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > }
> > > >
> > > > (I just typed that in; if it doesn't compile, fix it.) Then, I have
> this
> > > bit
> > > > of code lying around that will do the rest:
> > > >
> > > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > > IEditorPart editor = null;
> > > > IEditorInput input = new FileEditorInput(file);
> > > > IWorkbenchPage page =
> > > >
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > if (page != null) {
> > > > editor = page.findEditor(input);
> > > > if (editor != null) {
> > > > page.bringToTop(editor);
> > > > }
> > > > else {
> > > > try {
> > > > editor = page.openEditor(input, editorId);
> > > > } catch (PartInitException e) {
> > > > //log the error or something
> > > > }
> > > > }
> > > > }
> > > > return editor;
> > > > }
> > > >
> > > > I haven't tried exactly this case and there's probably shorter code
to
> > do
> > > it
> > > > (I try to avoid Eclipse's IResource, uh, stuff as much as I can),
but
> > > that's
> > > > the general idea.
> > > >
> > > > Bob
> > > >
> > > >
> > > >
> > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > Hi Bob and Rich,
> > > > >
> > > > > Thanks for your help. The thing is that the file I'm creating is
> done
> > > on
> > > > > the fly as my plugin runs and so it's not in the workspace.
> > > > > Basically, this is what I'm trying to do.
> > > > > I'm trying to create a newsgroup client plugin for eclipse and I
> > create
> > > a
> > > > > view in which the messages are displayed in. When I double-click
a
> > > > message,
> > > > > I would like to open it in the text editor.
> > > > > The way I'm going about this is that I'm grabbing the information
> from
> > > the
> > > > > doubleclick event and writing it into temp file and I want to
> display
> > > this
> > > > > temp file in the editor. From what I've read and what I've tried,
> it
> > > > seems
> > > > > that this is not possible if this file is not associated in the
> > > workspace,
> > > > > as you guys have pointed out.
> > > > > In your opinion, is what I'm trying to do possible?
> > > > > Thanks again,
> > > > >
> > > > > Raj
> > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > Well, you could create a linked file in the workspace that works
> as
> > a
> > > > > > surrogate for the non-workspace file.
> > > > > >
> > > > > > (Also, when going the other way, from IFile to File, you want to
> use
> > > > > > getLocation() not getFullPath().)
> > > > > >
> > > > > > Bob
> > > > > >
> > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > But remember, this only works for files that are in the
> workspace.
> > > If
> > > > > > > the file is not in the workspace anywhere (i.e. some generic
> file
> > > > > > > someplace else), you can't get an IFile to it.
> > > > > > >
> > > > > > > --
> > > > > > > Thanks, Rich Kulp
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160044 is a reply to message #159707] |
Fri, 21 November 2003 14:40 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
Called my bluff, eh? ;-}
Well, first of all, does the file exist? Second, is it actually in a
workspace?
My actual idea was to store the files in your plugin folder inside
..metadata, which I know are ok to read and write, not just at the root of
some workspace, which I don't know are ok.
Anyway, check this stuff, do a little debugging, and if it isn't obvious
we'll go from there.
Bob
"Raj Chari" <rc316@shaw.ca> wrote in message news:bpj6ou$ke$1@eclipse.org...
> Hi,
>
> So I used your idea Bob and I wrote up the following code:
>
> File myFile = new File("F:/ePost/workspace/test.txt");
> FileWriter fw = new FileWriter(myFile);
> fw.write(sb.toString());
> fw.close();
> file = fileToIFile(myFile);
> openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
>
>
> I wrote the two other functions that were suggested:
>
> public IFile fileToIFile(File f) {
> String p = f.getAbsolutePath();
> IPath path = new Path(p);
> return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> }
>
> protected IEditorPart openEditor(IFile file, String editorId) {
> IEditorPart editor = null;
> IEditorInput input = new FileEditorInput(file);
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> if (page != null) {
> editor = page.findEditor(input);
> if (editor != null) {
> page.bringToTop(editor);
> }
> else {
> try {
> editor = page.openEditor(input, editorId);
> } catch (PartInitException e) {
> showMessage(e.getMessage());
> }
> }
> }
> return editor;
> }
>
> My output was that the file tried to open up in the editor and
> in the texteditor, it said, "Resource /ePost/workspace/test.txt does not
> exist."
> Can someone tell me why this would happen and/or how this can be fixed?
> Thanks again
>
> Raj
>
> "Bob Foster" <bob@objfac.com> wrote in message
> news:bphok5$6us$1@eclipse.org...
> > I think you're headed off in the wrong direction. Please re-read my post
> > until you understand it. ;-}
> >
> > Bob
> >
> > "Raj Chari" <rc316@shaw.ca> wrote in message
> > news:bpgfbm$vfp$1@eclipse.org...
> > > Hi,
> > >
> > > I just re-read your post and my problem lies in the fact that I'm
> creating
> > > the file when I run my plugin, I have choice in where to store the
file
> > but
> > > it's not registered in the workspace. Will this still work if the
file
> is
> > > not in the workspace. The other person suggested using IDocument and
> > > IEditorInput and I'm not sure how to use this. Does anyone know how
to
> > use
> > > the IEditorInput and IDocument as mentioned in a previous post? I'm
> > looking
> > > for examples to see how to use IDocument.
> > > Thanks
> > >
> > > Raj
> > >
> > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > news:bpfb7k$ff5$1@eclipse.org...
> > > > Thank you so much Bob!
> > > >
> > > > Raj
> > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > news:bpf514$940$1@eclipse.org...
> > > > > As long as the file is in the workspace, I think you can do it.
Use
> > the
> > > > > .metadata area created for your plugin, which you can get the path
> of
> > by
> > > > > calling getStateLocation() in your plugin. toOSString() will get
you
> a
> > > > path
> > > > > suitable for java.io.File and you're off and running. When you
have
> a
> > > File
> > > > > created there, call the following to get an IFile:
> > > > >
> > > > > public IFile fileToIFile(File f) {
> > > > > String p = f.getPath();
> > > > > IPath path = new Path(p);
> > > > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > }
> > > > >
> > > > > (I just typed that in; if it doesn't compile, fix it.) Then, I
have
> > this
> > > > bit
> > > > > of code lying around that will do the rest:
> > > > >
> > > > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > > > IEditorPart editor = null;
> > > > > IEditorInput input = new FileEditorInput(file);
> > > > > IWorkbenchPage page =
> > > > >
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > if (page != null) {
> > > > > editor = page.findEditor(input);
> > > > > if (editor != null) {
> > > > > page.bringToTop(editor);
> > > > > }
> > > > > else {
> > > > > try {
> > > > > editor = page.openEditor(input, editorId);
> > > > > } catch (PartInitException e) {
> > > > > //log the error or something
> > > > > }
> > > > > }
> > > > > }
> > > > > return editor;
> > > > > }
> > > > >
> > > > > I haven't tried exactly this case and there's probably shorter
code
> to
> > > do
> > > > it
> > > > > (I try to avoid Eclipse's IResource, uh, stuff as much as I can),
> but
> > > > that's
> > > > > the general idea.
> > > > >
> > > > > Bob
> > > > >
> > > > >
> > > > >
> > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > Hi Bob and Rich,
> > > > > >
> > > > > > Thanks for your help. The thing is that the file I'm creating
is
> > done
> > > > on
> > > > > > the fly as my plugin runs and so it's not in the workspace.
> > > > > > Basically, this is what I'm trying to do.
> > > > > > I'm trying to create a newsgroup client plugin for eclipse and I
> > > create
> > > > a
> > > > > > view in which the messages are displayed in. When I
double-click
> a
> > > > > message,
> > > > > > I would like to open it in the text editor.
> > > > > > The way I'm going about this is that I'm grabbing the
information
> > from
> > > > the
> > > > > > doubleclick event and writing it into temp file and I want to
> > display
> > > > this
> > > > > > temp file in the editor. From what I've read and what I've
tried,
> > it
> > > > > seems
> > > > > > that this is not possible if this file is not associated in the
> > > > workspace,
> > > > > > as you guys have pointed out.
> > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > Thanks again,
> > > > > >
> > > > > > Raj
> > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > Well, you could create a linked file in the workspace that
works
> > as
> > > a
> > > > > > > surrogate for the non-workspace file.
> > > > > > >
> > > > > > > (Also, when going the other way, from IFile to File, you want
to
> > use
> > > > > > > getLocation() not getFullPath().)
> > > > > > >
> > > > > > > Bob
> > > > > > >
> > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > But remember, this only works for files that are in the
> > workspace.
> > > > If
> > > > > > > > the file is not in the workspace anywhere (i.e. some generic
> > file
> > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > >
> > > > > > > > --
> > > > > > > > Thanks, Rich Kulp
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160055 is a reply to message #159707] |
Fri, 21 November 2003 14:41 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
Called my bluff, eh? ;-}
Well, first of all, does the file exist? Second, is it actually in a
workspace?
My actual idea was to store the files in your plugin folder inside
..metadata, which I know are ok to read and write, not just at the root of
some workspace, which I don't know are ok.
Anyway, check this stuff, do a little debugging, and if it isn't obvious
we'll go from there.
Bob
"Raj Chari" <rc316@shaw.ca> wrote in message news:bpj6ou$ke$1@eclipse.org...
> Hi,
>
> So I used your idea Bob and I wrote up the following code:
>
> File myFile = new File("F:/ePost/workspace/test.txt");
> FileWriter fw = new FileWriter(myFile);
> fw.write(sb.toString());
> fw.close();
> file = fileToIFile(myFile);
> openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
>
>
> I wrote the two other functions that were suggested:
>
> public IFile fileToIFile(File f) {
> String p = f.getAbsolutePath();
> IPath path = new Path(p);
> return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> }
>
> protected IEditorPart openEditor(IFile file, String editorId) {
> IEditorPart editor = null;
> IEditorInput input = new FileEditorInput(file);
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> if (page != null) {
> editor = page.findEditor(input);
> if (editor != null) {
> page.bringToTop(editor);
> }
> else {
> try {
> editor = page.openEditor(input, editorId);
> } catch (PartInitException e) {
> showMessage(e.getMessage());
> }
> }
> }
> return editor;
> }
>
> My output was that the file tried to open up in the editor and
> in the texteditor, it said, "Resource /ePost/workspace/test.txt does not
> exist."
> Can someone tell me why this would happen and/or how this can be fixed?
> Thanks again
>
> Raj
>
> "Bob Foster" <bob@objfac.com> wrote in message
> news:bphok5$6us$1@eclipse.org...
> > I think you're headed off in the wrong direction. Please re-read my post
> > until you understand it. ;-}
> >
> > Bob
> >
> > "Raj Chari" <rc316@shaw.ca> wrote in message
> > news:bpgfbm$vfp$1@eclipse.org...
> > > Hi,
> > >
> > > I just re-read your post and my problem lies in the fact that I'm
> creating
> > > the file when I run my plugin, I have choice in where to store the
file
> > but
> > > it's not registered in the workspace. Will this still work if the
file
> is
> > > not in the workspace. The other person suggested using IDocument and
> > > IEditorInput and I'm not sure how to use this. Does anyone know how
to
> > use
> > > the IEditorInput and IDocument as mentioned in a previous post? I'm
> > looking
> > > for examples to see how to use IDocument.
> > > Thanks
> > >
> > > Raj
> > >
> > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > news:bpfb7k$ff5$1@eclipse.org...
> > > > Thank you so much Bob!
> > > >
> > > > Raj
> > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > news:bpf514$940$1@eclipse.org...
> > > > > As long as the file is in the workspace, I think you can do it.
Use
> > the
> > > > > .metadata area created for your plugin, which you can get the path
> of
> > by
> > > > > calling getStateLocation() in your plugin. toOSString() will get
you
> a
> > > > path
> > > > > suitable for java.io.File and you're off and running. When you
have
> a
> > > File
> > > > > created there, call the following to get an IFile:
> > > > >
> > > > > public IFile fileToIFile(File f) {
> > > > > String p = f.getPath();
> > > > > IPath path = new Path(p);
> > > > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > }
> > > > >
> > > > > (I just typed that in; if it doesn't compile, fix it.) Then, I
have
> > this
> > > > bit
> > > > > of code lying around that will do the rest:
> > > > >
> > > > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > > > IEditorPart editor = null;
> > > > > IEditorInput input = new FileEditorInput(file);
> > > > > IWorkbenchPage page =
> > > > >
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > if (page != null) {
> > > > > editor = page.findEditor(input);
> > > > > if (editor != null) {
> > > > > page.bringToTop(editor);
> > > > > }
> > > > > else {
> > > > > try {
> > > > > editor = page.openEditor(input, editorId);
> > > > > } catch (PartInitException e) {
> > > > > //log the error or something
> > > > > }
> > > > > }
> > > > > }
> > > > > return editor;
> > > > > }
> > > > >
> > > > > I haven't tried exactly this case and there's probably shorter
code
> to
> > > do
> > > > it
> > > > > (I try to avoid Eclipse's IResource, uh, stuff as much as I can),
> but
> > > > that's
> > > > > the general idea.
> > > > >
> > > > > Bob
> > > > >
> > > > >
> > > > >
> > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > Hi Bob and Rich,
> > > > > >
> > > > > > Thanks for your help. The thing is that the file I'm creating
is
> > done
> > > > on
> > > > > > the fly as my plugin runs and so it's not in the workspace.
> > > > > > Basically, this is what I'm trying to do.
> > > > > > I'm trying to create a newsgroup client plugin for eclipse and I
> > > create
> > > > a
> > > > > > view in which the messages are displayed in. When I
double-click
> a
> > > > > message,
> > > > > > I would like to open it in the text editor.
> > > > > > The way I'm going about this is that I'm grabbing the
information
> > from
> > > > the
> > > > > > doubleclick event and writing it into temp file and I want to
> > display
> > > > this
> > > > > > temp file in the editor. From what I've read and what I've
tried,
> > it
> > > > > seems
> > > > > > that this is not possible if this file is not associated in the
> > > > workspace,
> > > > > > as you guys have pointed out.
> > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > Thanks again,
> > > > > >
> > > > > > Raj
> > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > Well, you could create a linked file in the workspace that
works
> > as
> > > a
> > > > > > > surrogate for the non-workspace file.
> > > > > > >
> > > > > > > (Also, when going the other way, from IFile to File, you want
to
> > use
> > > > > > > getLocation() not getFullPath().)
> > > > > > >
> > > > > > > Bob
> > > > > > >
> > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > But remember, this only works for files that are in the
> > workspace.
> > > > If
> > > > > > > > the file is not in the workspace anywhere (i.e. some generic
> > file
> > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > >
> > > > > > > > --
> > > > > > > > Thanks, Rich Kulp
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160215 is a reply to message #160055] |
Fri, 21 November 2003 17:57 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Well,
The file does exist but it's not in the workspace. I think this problem
can be solved by adding the file to the workspace using the appropriate
commands and then maybe calling this code although, I have no idea of how to
add a file to the workpace by using java code. I've got a rough idea, but
if anyone has a clear idea of how to do it, your help would be greatly
appreciated.
Thanks
Raj
"Bob Foster" <bob@objfac.com> wrote in message
news:bpl74v$3h5$1@eclipse.org...
> Called my bluff, eh? ;-}
>
> Well, first of all, does the file exist? Second, is it actually in a
> workspace?
>
> My actual idea was to store the files in your plugin folder inside
> .metadata, which I know are ok to read and write, not just at the root of
> some workspace, which I don't know are ok.
>
> Anyway, check this stuff, do a little debugging, and if it isn't obvious
> we'll go from there.
>
> Bob
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
news:bpj6ou$ke$1@eclipse.org...
> > Hi,
> >
> > So I used your idea Bob and I wrote up the following code:
> >
> > File myFile = new File("F:/ePost/workspace/test.txt");
> > FileWriter fw = new FileWriter(myFile);
> > fw.write(sb.toString());
> > fw.close();
> > file = fileToIFile(myFile);
> > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> >
> >
> > I wrote the two other functions that were suggested:
> >
> > public IFile fileToIFile(File f) {
> > String p = f.getAbsolutePath();
> > IPath path = new Path(p);
> > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > }
> >
> > protected IEditorPart openEditor(IFile file, String editorId) {
> > IEditorPart editor = null;
> > IEditorInput input = new FileEditorInput(file);
> > IWorkbenchPage page =
> > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > if (page != null) {
> > editor = page.findEditor(input);
> > if (editor != null) {
> > page.bringToTop(editor);
> > }
> > else {
> > try {
> > editor = page.openEditor(input, editorId);
> > } catch (PartInitException e) {
> > showMessage(e.getMessage());
> > }
> > }
> > }
> > return editor;
> > }
> >
> > My output was that the file tried to open up in the editor and
> > in the texteditor, it said, "Resource /ePost/workspace/test.txt does not
> > exist."
> > Can someone tell me why this would happen and/or how this can be fixed?
> > Thanks again
> >
> > Raj
> >
> > "Bob Foster" <bob@objfac.com> wrote in message
> > news:bphok5$6us$1@eclipse.org...
> > > I think you're headed off in the wrong direction. Please re-read my
post
> > > until you understand it. ;-}
> > >
> > > Bob
> > >
> > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > news:bpgfbm$vfp$1@eclipse.org...
> > > > Hi,
> > > >
> > > > I just re-read your post and my problem lies in the fact that I'm
> > creating
> > > > the file when I run my plugin, I have choice in where to store the
> file
> > > but
> > > > it's not registered in the workspace. Will this still work if the
> file
> > is
> > > > not in the workspace. The other person suggested using IDocument
and
> > > > IEditorInput and I'm not sure how to use this. Does anyone know how
> to
> > > use
> > > > the IEditorInput and IDocument as mentioned in a previous post? I'm
> > > looking
> > > > for examples to see how to use IDocument.
> > > > Thanks
> > > >
> > > > Raj
> > > >
> > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > news:bpfb7k$ff5$1@eclipse.org...
> > > > > Thank you so much Bob!
> > > > >
> > > > > Raj
> > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > news:bpf514$940$1@eclipse.org...
> > > > > > As long as the file is in the workspace, I think you can do it.
> Use
> > > the
> > > > > > .metadata area created for your plugin, which you can get the
path
> > of
> > > by
> > > > > > calling getStateLocation() in your plugin. toOSString() will get
> you
> > a
> > > > > path
> > > > > > suitable for java.io.File and you're off and running. When you
> have
> > a
> > > > File
> > > > > > created there, call the following to get an IFile:
> > > > > >
> > > > > > public IFile fileToIFile(File f) {
> > > > > > String p = f.getPath();
> > > > > > IPath path = new Path(p);
> > > > > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > }
> > > > > >
> > > > > > (I just typed that in; if it doesn't compile, fix it.) Then, I
> have
> > > this
> > > > > bit
> > > > > > of code lying around that will do the rest:
> > > > > >
> > > > > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > > > > IEditorPart editor = null;
> > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > IWorkbenchPage page =
> > > > > >
> > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > if (page != null) {
> > > > > > editor = page.findEditor(input);
> > > > > > if (editor != null) {
> > > > > > page.bringToTop(editor);
> > > > > > }
> > > > > > else {
> > > > > > try {
> > > > > > editor = page.openEditor(input, editorId);
> > > > > > } catch (PartInitException e) {
> > > > > > //log the error or something
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > > return editor;
> > > > > > }
> > > > > >
> > > > > > I haven't tried exactly this case and there's probably shorter
> code
> > to
> > > > do
> > > > > it
> > > > > > (I try to avoid Eclipse's IResource, uh, stuff as much as I
can),
> > but
> > > > > that's
> > > > > > the general idea.
> > > > > >
> > > > > > Bob
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > > Hi Bob and Rich,
> > > > > > >
> > > > > > > Thanks for your help. The thing is that the file I'm creating
> is
> > > done
> > > > > on
> > > > > > > the fly as my plugin runs and so it's not in the workspace.
> > > > > > > Basically, this is what I'm trying to do.
> > > > > > > I'm trying to create a newsgroup client plugin for eclipse and
I
> > > > create
> > > > > a
> > > > > > > view in which the messages are displayed in. When I
> double-click
> > a
> > > > > > message,
> > > > > > > I would like to open it in the text editor.
> > > > > > > The way I'm going about this is that I'm grabbing the
> information
> > > from
> > > > > the
> > > > > > > doubleclick event and writing it into temp file and I want to
> > > display
> > > > > this
> > > > > > > temp file in the editor. From what I've read and what I've
> tried,
> > > it
> > > > > > seems
> > > > > > > that this is not possible if this file is not associated in
the
> > > > > workspace,
> > > > > > > as you guys have pointed out.
> > > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > > Thanks again,
> > > > > > >
> > > > > > > Raj
> > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > > Well, you could create a linked file in the workspace that
> works
> > > as
> > > > a
> > > > > > > > surrogate for the non-workspace file.
> > > > > > > >
> > > > > > > > (Also, when going the other way, from IFile to File, you
want
> to
> > > use
> > > > > > > > getLocation() not getFullPath().)
> > > > > > > >
> > > > > > > > Bob
> > > > > > > >
> > > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > > But remember, this only works for files that are in the
> > > workspace.
> > > > > If
> > > > > > > > > the file is not in the workspace anywhere (i.e. some
generic
> > > file
> > > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > Thanks, Rich Kulp
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160451 is a reply to message #160215] |
Sat, 22 November 2003 05:31 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
Previously, I wrote:
Use the .metadata area created for your plugin, which you can get the path
of by calling getStateLocation() in your plugin [class].
The rest of the paragraph tells how to use the path to make a file.
Bob
"Raj Chari" <rc316@shaw.ca> wrote in message
news:bpljho$kpv$1@eclipse.org...
> Well,
>
> The file does exist but it's not in the workspace. I think this problem
> can be solved by adding the file to the workspace using the appropriate
> commands and then maybe calling this code although, I have no idea of how
to
> add a file to the workpace by using java code. I've got a rough idea, but
> if anyone has a clear idea of how to do it, your help would be greatly
> appreciated.
> Thanks
>
> Raj
> "Bob Foster" <bob@objfac.com> wrote in message
> news:bpl74v$3h5$1@eclipse.org...
> > Called my bluff, eh? ;-}
> >
> > Well, first of all, does the file exist? Second, is it actually in a
> > workspace?
> >
> > My actual idea was to store the files in your plugin folder inside
> > .metadata, which I know are ok to read and write, not just at the root
of
> > some workspace, which I don't know are ok.
> >
> > Anyway, check this stuff, do a little debugging, and if it isn't obvious
> > we'll go from there.
> >
> > Bob
> >
> > "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bpj6ou$ke$1@eclipse.org...
> > > Hi,
> > >
> > > So I used your idea Bob and I wrote up the following code:
> > >
> > > File myFile = new File("F:/ePost/workspace/test.txt");
> > > FileWriter fw = new FileWriter(myFile);
> > > fw.write(sb.toString());
> > > fw.close();
> > > file = fileToIFile(myFile);
> > > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> > >
> > >
> > > I wrote the two other functions that were suggested:
> > >
> > > public IFile fileToIFile(File f) {
> > > String p = f.getAbsolutePath();
> > > IPath path = new Path(p);
> > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > }
> > >
> > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > IEditorPart editor = null;
> > > IEditorInput input = new FileEditorInput(file);
> > > IWorkbenchPage page =
> > > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > if (page != null) {
> > > editor = page.findEditor(input);
> > > if (editor != null) {
> > > page.bringToTop(editor);
> > > }
> > > else {
> > > try {
> > > editor = page.openEditor(input, editorId);
> > > } catch (PartInitException e) {
> > > showMessage(e.getMessage());
> > > }
> > > }
> > > }
> > > return editor;
> > > }
> > >
> > > My output was that the file tried to open up in the editor and
> > > in the texteditor, it said, "Resource /ePost/workspace/test.txt does
not
> > > exist."
> > > Can someone tell me why this would happen and/or how this can be
fixed?
> > > Thanks again
> > >
> > > Raj
> > >
> > > "Bob Foster" <bob@objfac.com> wrote in message
> > > news:bphok5$6us$1@eclipse.org...
> > > > I think you're headed off in the wrong direction. Please re-read my
> post
> > > > until you understand it. ;-}
> > > >
> > > > Bob
> > > >
> > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > news:bpgfbm$vfp$1@eclipse.org...
> > > > > Hi,
> > > > >
> > > > > I just re-read your post and my problem lies in the fact that I'm
> > > creating
> > > > > the file when I run my plugin, I have choice in where to store the
> > file
> > > > but
> > > > > it's not registered in the workspace. Will this still work if the
> > file
> > > is
> > > > > not in the workspace. The other person suggested using IDocument
> and
> > > > > IEditorInput and I'm not sure how to use this. Does anyone know
how
> > to
> > > > use
> > > > > the IEditorInput and IDocument as mentioned in a previous post?
I'm
> > > > looking
> > > > > for examples to see how to use IDocument.
> > > > > Thanks
> > > > >
> > > > > Raj
> > > > >
> > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > news:bpfb7k$ff5$1@eclipse.org...
> > > > > > Thank you so much Bob!
> > > > > >
> > > > > > Raj
> > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > news:bpf514$940$1@eclipse.org...
> > > > > > > As long as the file is in the workspace, I think you can do
it.
> > Use
> > > > the
> > > > > > > .metadata area created for your plugin, which you can get the
> path
> > > of
> > > > by
> > > > > > > calling getStateLocation() in your plugin. toOSString() will
get
> > you
> > > a
> > > > > > path
> > > > > > > suitable for java.io.File and you're off and running. When you
> > have
> > > a
> > > > > File
> > > > > > > created there, call the following to get an IFile:
> > > > > > >
> > > > > > > public IFile fileToIFile(File f) {
> > > > > > > String p = f.getPath();
> > > > > > > IPath path = new Path(p);
> > > > > > > return
ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > }
> > > > > > >
> > > > > > > (I just typed that in; if it doesn't compile, fix it.) Then, I
> > have
> > > > this
> > > > > > bit
> > > > > > > of code lying around that will do the rest:
> > > > > > >
> > > > > > > protected IEditorPart openEditor(IFile file, String editorId)
{
> > > > > > > IEditorPart editor = null;
> > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > IWorkbenchPage page =
> > > > > > >
> > > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > if (page != null) {
> > > > > > > editor = page.findEditor(input);
> > > > > > > if (editor != null) {
> > > > > > > page.bringToTop(editor);
> > > > > > > }
> > > > > > > else {
> > > > > > > try {
> > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > } catch (PartInitException e) {
> > > > > > > //log the error or something
> > > > > > > }
> > > > > > > }
> > > > > > > }
> > > > > > > return editor;
> > > > > > > }
> > > > > > >
> > > > > > > I haven't tried exactly this case and there's probably shorter
> > code
> > > to
> > > > > do
> > > > > > it
> > > > > > > (I try to avoid Eclipse's IResource, uh, stuff as much as I
> can),
> > > but
> > > > > > that's
> > > > > > > the general idea.
> > > > > > >
> > > > > > > Bob
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > > > Hi Bob and Rich,
> > > > > > > >
> > > > > > > > Thanks for your help. The thing is that the file I'm
creating
> > is
> > > > done
> > > > > > on
> > > > > > > > the fly as my plugin runs and so it's not in the workspace.
> > > > > > > > Basically, this is what I'm trying to do.
> > > > > > > > I'm trying to create a newsgroup client plugin for eclipse
and
> I
> > > > > create
> > > > > > a
> > > > > > > > view in which the messages are displayed in. When I
> > double-click
> > > a
> > > > > > > message,
> > > > > > > > I would like to open it in the text editor.
> > > > > > > > The way I'm going about this is that I'm grabbing the
> > information
> > > > from
> > > > > > the
> > > > > > > > doubleclick event and writing it into temp file and I want
to
> > > > display
> > > > > > this
> > > > > > > > temp file in the editor. From what I've read and what I've
> > tried,
> > > > it
> > > > > > > seems
> > > > > > > > that this is not possible if this file is not associated in
> the
> > > > > > workspace,
> > > > > > > > as you guys have pointed out.
> > > > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > > > Thanks again,
> > > > > > > >
> > > > > > > > Raj
> > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > > > Well, you could create a linked file in the workspace that
> > works
> > > > as
> > > > > a
> > > > > > > > > surrogate for the non-workspace file.
> > > > > > > > >
> > > > > > > > > (Also, when going the other way, from IFile to File, you
> want
> > to
> > > > use
> > > > > > > > > getLocation() not getFullPath().)
> > > > > > > > >
> > > > > > > > > Bob
> > > > > > > > >
> > > > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
> > > > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > > > But remember, this only works for files that are in the
> > > > workspace.
> > > > > > If
> > > > > > > > > > the file is not in the workspace anywhere (i.e. some
> generic
> > > > file
> > > > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > Thanks, Rich Kulp
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160468 is a reply to message #160451] |
Sat, 22 November 2003 09:06 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Can you explain what it is to use the metatdata? I'm not understanding what
you're trying to say. So, are you saying when I create my java.io.file, I
should create the file in the .metadata directory? Sorry to be so dense..
Thanks
Raj
"Bob Foster" <bob@objfac.com> wrote in message
news:bpmra9$t34$1@eclipse.org...
> Previously, I wrote:
>
> Use the .metadata area created for your plugin, which you can get the path
> of by calling getStateLocation() in your plugin [class].
>
> The rest of the paragraph tells how to use the path to make a file.
>
> Bob
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bpljho$kpv$1@eclipse.org...
> > Well,
> >
> > The file does exist but it's not in the workspace. I think this
problem
> > can be solved by adding the file to the workspace using the appropriate
> > commands and then maybe calling this code although, I have no idea of
how
> to
> > add a file to the workpace by using java code. I've got a rough idea,
but
> > if anyone has a clear idea of how to do it, your help would be greatly
> > appreciated.
> > Thanks
> >
> > Raj
> > "Bob Foster" <bob@objfac.com> wrote in message
> > news:bpl74v$3h5$1@eclipse.org...
> > > Called my bluff, eh? ;-}
> > >
> > > Well, first of all, does the file exist? Second, is it actually in a
> > > workspace?
> > >
> > > My actual idea was to store the files in your plugin folder inside
> > > .metadata, which I know are ok to read and write, not just at the root
> of
> > > some workspace, which I don't know are ok.
> > >
> > > Anyway, check this stuff, do a little debugging, and if it isn't
obvious
> > > we'll go from there.
> > >
> > > Bob
> > >
> > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > news:bpj6ou$ke$1@eclipse.org...
> > > > Hi,
> > > >
> > > > So I used your idea Bob and I wrote up the following code:
> > > >
> > > > File myFile = new File("F:/ePost/workspace/test.txt");
> > > > FileWriter fw = new FileWriter(myFile);
> > > > fw.write(sb.toString());
> > > > fw.close();
> > > > file = fileToIFile(myFile);
> > > > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> > > >
> > > >
> > > > I wrote the two other functions that were suggested:
> > > >
> > > > public IFile fileToIFile(File f) {
> > > > String p = f.getAbsolutePath();
> > > > IPath path = new Path(p);
> > > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > }
> > > >
> > > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > > IEditorPart editor = null;
> > > > IEditorInput input = new FileEditorInput(file);
> > > > IWorkbenchPage page =
> > > >
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > if (page != null) {
> > > > editor = page.findEditor(input);
> > > > if (editor != null) {
> > > > page.bringToTop(editor);
> > > > }
> > > > else {
> > > > try {
> > > > editor = page.openEditor(input, editorId);
> > > > } catch (PartInitException e) {
> > > > showMessage(e.getMessage());
> > > > }
> > > > }
> > > > }
> > > > return editor;
> > > > }
> > > >
> > > > My output was that the file tried to open up in the editor and
> > > > in the texteditor, it said, "Resource /ePost/workspace/test.txt does
> not
> > > > exist."
> > > > Can someone tell me why this would happen and/or how this can be
> fixed?
> > > > Thanks again
> > > >
> > > > Raj
> > > >
> > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > news:bphok5$6us$1@eclipse.org...
> > > > > I think you're headed off in the wrong direction. Please re-read
my
> > post
> > > > > until you understand it. ;-}
> > > > >
> > > > > Bob
> > > > >
> > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > news:bpgfbm$vfp$1@eclipse.org...
> > > > > > Hi,
> > > > > >
> > > > > > I just re-read your post and my problem lies in the fact that
I'm
> > > > creating
> > > > > > the file when I run my plugin, I have choice in where to store
the
> > > file
> > > > > but
> > > > > > it's not registered in the workspace. Will this still work if
the
> > > file
> > > > is
> > > > > > not in the workspace. The other person suggested using
IDocument
> > and
> > > > > > IEditorInput and I'm not sure how to use this. Does anyone know
> how
> > > to
> > > > > use
> > > > > > the IEditorInput and IDocument as mentioned in a previous post?
> I'm
> > > > > looking
> > > > > > for examples to see how to use IDocument.
> > > > > > Thanks
> > > > > >
> > > > > > Raj
> > > > > >
> > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > news:bpfb7k$ff5$1@eclipse.org...
> > > > > > > Thank you so much Bob!
> > > > > > >
> > > > > > > Raj
> > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > news:bpf514$940$1@eclipse.org...
> > > > > > > > As long as the file is in the workspace, I think you can do
> it.
> > > Use
> > > > > the
> > > > > > > > .metadata area created for your plugin, which you can get
the
> > path
> > > > of
> > > > > by
> > > > > > > > calling getStateLocation() in your plugin. toOSString() will
> get
> > > you
> > > > a
> > > > > > > path
> > > > > > > > suitable for java.io.File and you're off and running. When
you
> > > have
> > > > a
> > > > > > File
> > > > > > > > created there, call the following to get an IFile:
> > > > > > > >
> > > > > > > > public IFile fileToIFile(File f) {
> > > > > > > > String p = f.getPath();
> > > > > > > > IPath path = new Path(p);
> > > > > > > > return
> ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > > }
> > > > > > > >
> > > > > > > > (I just typed that in; if it doesn't compile, fix it.) Then,
I
> > > have
> > > > > this
> > > > > > > bit
> > > > > > > > of code lying around that will do the rest:
> > > > > > > >
> > > > > > > > protected IEditorPart openEditor(IFile file, String
editorId)
> {
> > > > > > > > IEditorPart editor = null;
> > > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > > IWorkbenchPage page =
> > > > > > > >
> > > >
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > > if (page != null) {
> > > > > > > > editor = page.findEditor(input);
> > > > > > > > if (editor != null) {
> > > > > > > > page.bringToTop(editor);
> > > > > > > > }
> > > > > > > > else {
> > > > > > > > try {
> > > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > > } catch (PartInitException e) {
> > > > > > > > //log the error or something
> > > > > > > > }
> > > > > > > > }
> > > > > > > > }
> > > > > > > > return editor;
> > > > > > > > }
> > > > > > > >
> > > > > > > > I haven't tried exactly this case and there's probably
shorter
> > > code
> > > > to
> > > > > > do
> > > > > > > it
> > > > > > > > (I try to avoid Eclipse's IResource, uh, stuff as much as I
> > can),
> > > > but
> > > > > > > that's
> > > > > > > > the general idea.
> > > > > > > >
> > > > > > > > Bob
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > > > > Hi Bob and Rich,
> > > > > > > > >
> > > > > > > > > Thanks for your help. The thing is that the file I'm
> creating
> > > is
> > > > > done
> > > > > > > on
> > > > > > > > > the fly as my plugin runs and so it's not in the
workspace.
> > > > > > > > > Basically, this is what I'm trying to do.
> > > > > > > > > I'm trying to create a newsgroup client plugin for eclipse
> and
> > I
> > > > > > create
> > > > > > > a
> > > > > > > > > view in which the messages are displayed in. When I
> > > double-click
> > > > a
> > > > > > > > message,
> > > > > > > > > I would like to open it in the text editor.
> > > > > > > > > The way I'm going about this is that I'm grabbing the
> > > information
> > > > > from
> > > > > > > the
> > > > > > > > > doubleclick event and writing it into temp file and I want
> to
> > > > > display
> > > > > > > this
> > > > > > > > > temp file in the editor. From what I've read and what
I've
> > > tried,
> > > > > it
> > > > > > > > seems
> > > > > > > > > that this is not possible if this file is not associated
in
> > the
> > > > > > > workspace,
> > > > > > > > > as you guys have pointed out.
> > > > > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > > > > Thanks again,
> > > > > > > > >
> > > > > > > > > Raj
> > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > > > > Well, you could create a linked file in the workspace
that
> > > works
> > > > > as
> > > > > > a
> > > > > > > > > > surrogate for the non-workspace file.
> > > > > > > > > >
> > > > > > > > > > (Also, when going the other way, from IFile to File, you
> > want
> > > to
> > > > > use
> > > > > > > > > > getLocation() not getFullPath().)
> > > > > > > > > >
> > > > > > > > > > Bob
> > > > > > > > > >
> > > > > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in
message
> > > > > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > > > > But remember, this only works for files that are in
the
> > > > > workspace.
> > > > > > > If
> > > > > > > > > > > the file is not in the workspace anywhere (i.e. some
> > generic
> > > > > file
> > > > > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > > Thanks, Rich Kulp
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160498 is a reply to message #160468] |
Sat, 22 November 2003 12:48 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
Maybe I've been cryptic. Every plugin is allocated a folder in the
..metadata/.plugins folder of each workspace. This folder is writeable and
AFAIK IFile-accessible. If your plugin's id is org.sample.myplug, that will
be the folder name. But you don't need to know that. getStateLocation() gets
it for you. You should be able to create a sub-folder there, write your temp
files into it and open those files in editors. More clear?
(I've gone a bit out on a limb because I don't know what sort of knucklehead
code there is in Eclipse that might assume/require that every file is in a
project - I believe Search makes this assumption - but I think that's the
simplest solution to what you want to do so I suggest you try it. If it
doesn't work, there are other options, which involve creating a new project
to put the files into. This is quite easy to do; a few lines of code. But
since the project would be user-visible, it's not such a good solution.
Hence, I have suggested this path.)
Bob
"Raj Chari" <rc316@shaw.ca> wrote in message
news:bpn8r0$831$1@eclipse.org...
> Can you explain what it is to use the metatdata? I'm not understanding
what
> you're trying to say. So, are you saying when I create my java.io.file, I
> should create the file in the .metadata directory? Sorry to be so dense..
> Thanks
>
> Raj
> "Bob Foster" <bob@objfac.com> wrote in message
> news:bpmra9$t34$1@eclipse.org...
> > Previously, I wrote:
> >
> > Use the .metadata area created for your plugin, which you can get the
path
> > of by calling getStateLocation() in your plugin [class].
> >
> > The rest of the paragraph tells how to use the path to make a file.
> >
> > Bob
> >
> > "Raj Chari" <rc316@shaw.ca> wrote in message
> > news:bpljho$kpv$1@eclipse.org...
> > > Well,
> > >
> > > The file does exist but it's not in the workspace. I think this
> problem
> > > can be solved by adding the file to the workspace using the
appropriate
> > > commands and then maybe calling this code although, I have no idea of
> how
> > to
> > > add a file to the workpace by using java code. I've got a rough idea,
> but
> > > if anyone has a clear idea of how to do it, your help would be
greatly
> > > appreciated.
> > > Thanks
> > >
> > > Raj
> > > "Bob Foster" <bob@objfac.com> wrote in message
> > > news:bpl74v$3h5$1@eclipse.org...
> > > > Called my bluff, eh? ;-}
> > > >
> > > > Well, first of all, does the file exist? Second, is it actually in a
> > > > workspace?
> > > >
> > > > My actual idea was to store the files in your plugin folder inside
> > > > .metadata, which I know are ok to read and write, not just at the
root
> > of
> > > > some workspace, which I don't know are ok.
> > > >
> > > > Anyway, check this stuff, do a little debugging, and if it isn't
> obvious
> > > > we'll go from there.
> > > >
> > > > Bob
> > > >
> > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > news:bpj6ou$ke$1@eclipse.org...
> > > > > Hi,
> > > > >
> > > > > So I used your idea Bob and I wrote up the following code:
> > > > >
> > > > > File myFile = new File("F:/ePost/workspace/test.txt");
> > > > > FileWriter fw = new FileWriter(myFile);
> > > > > fw.write(sb.toString());
> > > > > fw.close();
> > > > > file = fileToIFile(myFile);
> > > > > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> > > > >
> > > > >
> > > > > I wrote the two other functions that were suggested:
> > > > >
> > > > > public IFile fileToIFile(File f) {
> > > > > String p = f.getAbsolutePath();
> > > > > IPath path = new Path(p);
> > > > > return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > }
> > > > >
> > > > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > > > IEditorPart editor = null;
> > > > > IEditorInput input = new FileEditorInput(file);
> > > > > IWorkbenchPage page =
> > > > >
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > if (page != null) {
> > > > > editor = page.findEditor(input);
> > > > > if (editor != null) {
> > > > > page.bringToTop(editor);
> > > > > }
> > > > > else {
> > > > > try {
> > > > > editor = page.openEditor(input, editorId);
> > > > > } catch (PartInitException e) {
> > > > > showMessage(e.getMessage());
> > > > > }
> > > > > }
> > > > > }
> > > > > return editor;
> > > > > }
> > > > >
> > > > > My output was that the file tried to open up in the editor and
> > > > > in the texteditor, it said, "Resource /ePost/workspace/test.txt
does
> > not
> > > > > exist."
> > > > > Can someone tell me why this would happen and/or how this can be
> > fixed?
> > > > > Thanks again
> > > > >
> > > > > Raj
> > > > >
> > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > news:bphok5$6us$1@eclipse.org...
> > > > > > I think you're headed off in the wrong direction. Please re-read
> my
> > > post
> > > > > > until you understand it. ;-}
> > > > > >
> > > > > > Bob
> > > > > >
> > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > news:bpgfbm$vfp$1@eclipse.org...
> > > > > > > Hi,
> > > > > > >
> > > > > > > I just re-read your post and my problem lies in the fact that
> I'm
> > > > > creating
> > > > > > > the file when I run my plugin, I have choice in where to store
> the
> > > > file
> > > > > > but
> > > > > > > it's not registered in the workspace. Will this still work if
> the
> > > > file
> > > > > is
> > > > > > > not in the workspace. The other person suggested using
> IDocument
> > > and
> > > > > > > IEditorInput and I'm not sure how to use this. Does anyone
know
> > how
> > > > to
> > > > > > use
> > > > > > > the IEditorInput and IDocument as mentioned in a previous
post?
> > I'm
> > > > > > looking
> > > > > > > for examples to see how to use IDocument.
> > > > > > > Thanks
> > > > > > >
> > > > > > > Raj
> > > > > > >
> > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > news:bpfb7k$ff5$1@eclipse.org...
> > > > > > > > Thank you so much Bob!
> > > > > > > >
> > > > > > > > Raj
> > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > news:bpf514$940$1@eclipse.org...
> > > > > > > > > As long as the file is in the workspace, I think you can
do
> > it.
> > > > Use
> > > > > > the
> > > > > > > > > .metadata area created for your plugin, which you can get
> the
> > > path
> > > > > of
> > > > > > by
> > > > > > > > > calling getStateLocation() in your plugin. toOSString()
will
> > get
> > > > you
> > > > > a
> > > > > > > > path
> > > > > > > > > suitable for java.io.File and you're off and running. When
> you
> > > > have
> > > > > a
> > > > > > > File
> > > > > > > > > created there, call the following to get an IFile:
> > > > > > > > >
> > > > > > > > > public IFile fileToIFile(File f) {
> > > > > > > > > String p = f.getPath();
> > > > > > > > > IPath path = new Path(p);
> > > > > > > > > return
> > ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > (I just typed that in; if it doesn't compile, fix it.)
Then,
> I
> > > > have
> > > > > > this
> > > > > > > > bit
> > > > > > > > > of code lying around that will do the rest:
> > > > > > > > >
> > > > > > > > > protected IEditorPart openEditor(IFile file, String
> editorId)
> > {
> > > > > > > > > IEditorPart editor = null;
> > > > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > > > IWorkbenchPage page =
> > > > > > > > >
> > > > >
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > > > if (page != null) {
> > > > > > > > > editor = page.findEditor(input);
> > > > > > > > > if (editor != null) {
> > > > > > > > > page.bringToTop(editor);
> > > > > > > > > }
> > > > > > > > > else {
> > > > > > > > > try {
> > > > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > > > } catch (PartInitException e) {
> > > > > > > > > //log the error or something
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > return editor;
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > I haven't tried exactly this case and there's probably
> shorter
> > > > code
> > > > > to
> > > > > > > do
> > > > > > > > it
> > > > > > > > > (I try to avoid Eclipse's IResource, uh, stuff as much as
I
> > > can),
> > > > > but
> > > > > > > > that's
> > > > > > > > > the general idea.
> > > > > > > > >
> > > > > > > > > Bob
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > > > > > Hi Bob and Rich,
> > > > > > > > > >
> > > > > > > > > > Thanks for your help. The thing is that the file I'm
> > creating
> > > > is
> > > > > > done
> > > > > > > > on
> > > > > > > > > > the fly as my plugin runs and so it's not in the
> workspace.
> > > > > > > > > > Basically, this is what I'm trying to do.
> > > > > > > > > > I'm trying to create a newsgroup client plugin for
eclipse
> > and
> > > I
> > > > > > > create
> > > > > > > > a
> > > > > > > > > > view in which the messages are displayed in. When I
> > > > double-click
> > > > > a
> > > > > > > > > message,
> > > > > > > > > > I would like to open it in the text editor.
> > > > > > > > > > The way I'm going about this is that I'm grabbing the
> > > > information
> > > > > > from
> > > > > > > > the
> > > > > > > > > > doubleclick event and writing it into temp file and I
want
> > to
> > > > > > display
> > > > > > > > this
> > > > > > > > > > temp file in the editor. From what I've read and what
> I've
> > > > tried,
> > > > > > it
> > > > > > > > > seems
> > > > > > > > > > that this is not possible if this file is not associated
> in
> > > the
> > > > > > > > workspace,
> > > > > > > > > > as you guys have pointed out.
> > > > > > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > > > > > Thanks again,
> > > > > > > > > >
> > > > > > > > > > Raj
> > > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > > > > > Well, you could create a linked file in the workspace
> that
> > > > works
> > > > > > as
> > > > > > > a
> > > > > > > > > > > surrogate for the non-workspace file.
> > > > > > > > > > >
> > > > > > > > > > > (Also, when going the other way, from IFile to File,
you
> > > want
> > > > to
> > > > > > use
> > > > > > > > > > > getLocation() not getFullPath().)
> > > > > > > > > > >
> > > > > > > > > > > Bob
> > > > > > > > > > >
> > > > > > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in
> message
> > > > > > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > > > > > But remember, this only works for files that are in
> the
> > > > > > workspace.
> > > > > > > > If
> > > > > > > > > > > > the file is not in the workspace anywhere (i.e. some
> > > generic
> > > > > > file
> > > > > > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > > > > > >
> > > > > > > > > > > > --
> > > > > > > > > > > > Thanks, Rich Kulp
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160596 is a reply to message #160498] |
Sat, 22 November 2003 21:48 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
Hello,
I put in the following code as mentioned before to use the metadata
directory.
IPath filePath = ePostPlugin.getDefault().getStateLocation();
String fileNamePath = filePath.toOSString();
File myFile = new File(fileNamePath + "/" + "test.epo");
FileWriter fw = new FileWriter(myFile);
fw.write(sb.toString());
fw.close();
file = fileToIFile(myFile);
openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
I still get the same problem with resource not found error showing up in the
editor. Where should we go from here?
Thanks again,
Raj
"Bob Foster" <bob@objfac.com> wrote in message
news:bpnkuj$ieb$1@eclipse.org...
> Maybe I've been cryptic. Every plugin is allocated a folder in the
> .metadata/.plugins folder of each workspace. This folder is writeable and
> AFAIK IFile-accessible. If your plugin's id is org.sample.myplug, that
will
> be the folder name. But you don't need to know that. getStateLocation()
gets
> it for you. You should be able to create a sub-folder there, write your
temp
> files into it and open those files in editors. More clear?
>
> (I've gone a bit out on a limb because I don't know what sort of
knucklehead
> code there is in Eclipse that might assume/require that every file is in a
> project - I believe Search makes this assumption - but I think that's the
> simplest solution to what you want to do so I suggest you try it. If it
> doesn't work, there are other options, which involve creating a new
project
> to put the files into. This is quite easy to do; a few lines of code. But
> since the project would be user-visible, it's not such a good solution.
> Hence, I have suggested this path.)
>
> Bob
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bpn8r0$831$1@eclipse.org...
> > Can you explain what it is to use the metatdata? I'm not understanding
> what
> > you're trying to say. So, are you saying when I create my java.io.file,
I
> > should create the file in the .metadata directory? Sorry to be so
dense..
> > Thanks
> >
> > Raj
> > "Bob Foster" <bob@objfac.com> wrote in message
> > news:bpmra9$t34$1@eclipse.org...
> > > Previously, I wrote:
> > >
> > > Use the .metadata area created for your plugin, which you can get the
> path
> > > of by calling getStateLocation() in your plugin [class].
> > >
> > > The rest of the paragraph tells how to use the path to make a file.
> > >
> > > Bob
> > >
> > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > news:bpljho$kpv$1@eclipse.org...
> > > > Well,
> > > >
> > > > The file does exist but it's not in the workspace. I think this
> > problem
> > > > can be solved by adding the file to the workspace using the
> appropriate
> > > > commands and then maybe calling this code although, I have no idea
of
> > how
> > > to
> > > > add a file to the workpace by using java code. I've got a rough
idea,
> > but
> > > > if anyone has a clear idea of how to do it, your help would be
> greatly
> > > > appreciated.
> > > > Thanks
> > > >
> > > > Raj
> > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > news:bpl74v$3h5$1@eclipse.org...
> > > > > Called my bluff, eh? ;-}
> > > > >
> > > > > Well, first of all, does the file exist? Second, is it actually in
a
> > > > > workspace?
> > > > >
> > > > > My actual idea was to store the files in your plugin folder inside
> > > > > .metadata, which I know are ok to read and write, not just at the
> root
> > > of
> > > > > some workspace, which I don't know are ok.
> > > > >
> > > > > Anyway, check this stuff, do a little debugging, and if it isn't
> > obvious
> > > > > we'll go from there.
> > > > >
> > > > > Bob
> > > > >
> > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > news:bpj6ou$ke$1@eclipse.org...
> > > > > > Hi,
> > > > > >
> > > > > > So I used your idea Bob and I wrote up the following code:
> > > > > >
> > > > > > File myFile = new File("F:/ePost/workspace/test.txt");
> > > > > > FileWriter fw = new FileWriter(myFile);
> > > > > > fw.write(sb.toString());
> > > > > > fw.close();
> > > > > > file = fileToIFile(myFile);
> > > > > > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> > > > > >
> > > > > >
> > > > > > I wrote the two other functions that were suggested:
> > > > > >
> > > > > > public IFile fileToIFile(File f) {
> > > > > > String p = f.getAbsolutePath();
> > > > > > IPath path = new Path(p);
> > > > > > return
ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > }
> > > > > >
> > > > > > protected IEditorPart openEditor(IFile file, String editorId) {
> > > > > > IEditorPart editor = null;
> > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > IWorkbenchPage page =
> > > > > >
> > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > if (page != null) {
> > > > > > editor = page.findEditor(input);
> > > > > > if (editor != null) {
> > > > > > page.bringToTop(editor);
> > > > > > }
> > > > > > else {
> > > > > > try {
> > > > > > editor = page.openEditor(input, editorId);
> > > > > > } catch (PartInitException e) {
> > > > > > showMessage(e.getMessage());
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > > return editor;
> > > > > > }
> > > > > >
> > > > > > My output was that the file tried to open up in the editor and
> > > > > > in the texteditor, it said, "Resource /ePost/workspace/test.txt
> does
> > > not
> > > > > > exist."
> > > > > > Can someone tell me why this would happen and/or how this can be
> > > fixed?
> > > > > > Thanks again
> > > > > >
> > > > > > Raj
> > > > > >
> > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > news:bphok5$6us$1@eclipse.org...
> > > > > > > I think you're headed off in the wrong direction. Please
re-read
> > my
> > > > post
> > > > > > > until you understand it. ;-}
> > > > > > >
> > > > > > > Bob
> > > > > > >
> > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > news:bpgfbm$vfp$1@eclipse.org...
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I just re-read your post and my problem lies in the fact
that
> > I'm
> > > > > > creating
> > > > > > > > the file when I run my plugin, I have choice in where to
store
> > the
> > > > > file
> > > > > > > but
> > > > > > > > it's not registered in the workspace. Will this still work
if
> > the
> > > > > file
> > > > > > is
> > > > > > > > not in the workspace. The other person suggested using
> > IDocument
> > > > and
> > > > > > > > IEditorInput and I'm not sure how to use this. Does anyone
> know
> > > how
> > > > > to
> > > > > > > use
> > > > > > > > the IEditorInput and IDocument as mentioned in a previous
> post?
> > > I'm
> > > > > > > looking
> > > > > > > > for examples to see how to use IDocument.
> > > > > > > > Thanks
> > > > > > > >
> > > > > > > > Raj
> > > > > > > >
> > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > news:bpfb7k$ff5$1@eclipse.org...
> > > > > > > > > Thank you so much Bob!
> > > > > > > > >
> > > > > > > > > Raj
> > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > news:bpf514$940$1@eclipse.org...
> > > > > > > > > > As long as the file is in the workspace, I think you can
> do
> > > it.
> > > > > Use
> > > > > > > the
> > > > > > > > > > .metadata area created for your plugin, which you can
get
> > the
> > > > path
> > > > > > of
> > > > > > > by
> > > > > > > > > > calling getStateLocation() in your plugin. toOSString()
> will
> > > get
> > > > > you
> > > > > > a
> > > > > > > > > path
> > > > > > > > > > suitable for java.io.File and you're off and running.
When
> > you
> > > > > have
> > > > > > a
> > > > > > > > File
> > > > > > > > > > created there, call the following to get an IFile:
> > > > > > > > > >
> > > > > > > > > > public IFile fileToIFile(File f) {
> > > > > > > > > > String p = f.getPath();
> > > > > > > > > > IPath path = new Path(p);
> > > > > > > > > > return
> > > ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > (I just typed that in; if it doesn't compile, fix it.)
> Then,
> > I
> > > > > have
> > > > > > > this
> > > > > > > > > bit
> > > > > > > > > > of code lying around that will do the rest:
> > > > > > > > > >
> > > > > > > > > > protected IEditorPart openEditor(IFile file, String
> > editorId)
> > > {
> > > > > > > > > > IEditorPart editor = null;
> > > > > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > > > > IWorkbenchPage page =
> > > > > > > > > >
> > > > > >
> > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > > > > if (page != null) {
> > > > > > > > > > editor = page.findEditor(input);
> > > > > > > > > > if (editor != null) {
> > > > > > > > > > page.bringToTop(editor);
> > > > > > > > > > }
> > > > > > > > > > else {
> > > > > > > > > > try {
> > > > > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > > > > } catch (PartInitException e) {
> > > > > > > > > > //log the error or something
> > > > > > > > > > }
> > > > > > > > > > }
> > > > > > > > > > }
> > > > > > > > > > return editor;
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > I haven't tried exactly this case and there's probably
> > shorter
> > > > > code
> > > > > > to
> > > > > > > > do
> > > > > > > > > it
> > > > > > > > > > (I try to avoid Eclipse's IResource, uh, stuff as much
as
> I
> > > > can),
> > > > > > but
> > > > > > > > > that's
> > > > > > > > > > the general idea.
> > > > > > > > > >
> > > > > > > > > > Bob
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > > > > > > Hi Bob and Rich,
> > > > > > > > > > >
> > > > > > > > > > > Thanks for your help. The thing is that the file I'm
> > > creating
> > > > > is
> > > > > > > done
> > > > > > > > > on
> > > > > > > > > > > the fly as my plugin runs and so it's not in the
> > workspace.
> > > > > > > > > > > Basically, this is what I'm trying to do.
> > > > > > > > > > > I'm trying to create a newsgroup client plugin for
> eclipse
> > > and
> > > > I
> > > > > > > > create
> > > > > > > > > a
> > > > > > > > > > > view in which the messages are displayed in. When I
> > > > > double-click
> > > > > > a
> > > > > > > > > > message,
> > > > > > > > > > > I would like to open it in the text editor.
> > > > > > > > > > > The way I'm going about this is that I'm grabbing the
> > > > > information
> > > > > > > from
> > > > > > > > > the
> > > > > > > > > > > doubleclick event and writing it into temp file and I
> want
> > > to
> > > > > > > display
> > > > > > > > > this
> > > > > > > > > > > temp file in the editor. From what I've read and what
> > I've
> > > > > tried,
> > > > > > > it
> > > > > > > > > > seems
> > > > > > > > > > > that this is not possible if this file is not
associated
> > in
> > > > the
> > > > > > > > > workspace,
> > > > > > > > > > > as you guys have pointed out.
> > > > > > > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > > > > > > Thanks again,
> > > > > > > > > > >
> > > > > > > > > > > Raj
> > > > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > > > > > > Well, you could create a linked file in the
workspace
> > that
> > > > > works
> > > > > > > as
> > > > > > > > a
> > > > > > > > > > > > surrogate for the non-workspace file.
> > > > > > > > > > > >
> > > > > > > > > > > > (Also, when going the other way, from IFile to File,
> you
> > > > want
> > > > > to
> > > > > > > use
> > > > > > > > > > > > getLocation() not getFullPath().)
> > > > > > > > > > > >
> > > > > > > > > > > > Bob
> > > > > > > > > > > >
> > > > > > > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in
> > message
> > > > > > > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > > > > > > But remember, this only works for files that are
in
> > the
> > > > > > > workspace.
> > > > > > > > > If
> > > > > > > > > > > > > the file is not in the workspace anywhere (i.e.
some
> > > > generic
> > > > > > > file
> > > > > > > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --
> > > > > > > > > > > > > Thanks, Rich Kulp
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160675 is a reply to message #160596] |
Sun, 23 November 2003 05:21 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: bob.objfac.com
Well, you remember when I said I'd never tried this? ;-} It looks like
workspaceroot's getFile() will return null if the file isn't in a project,
so I'm really surprised you got anything as civil as file not found. I would
have expected NullPointerException.
I'm not an expert on these crappy IPath/IFile things, but I can't see an
easy way to make what I suggested work without a project. If someone else
does, feel free to jump in.
There are two other ways to open something in an editor:
- Use IStorage, but these aren't editable unless you replace the storage
provider (editing won't work with .java files and I don't truly know what
kinds of files it will work with). See Ed Burnett's fileopen plugin for
working code: http://sourceforge.net/project/showfiles.php?group_id=73634
- Use linked files and a project to contain them, as is done by Matt
Conway's filedrag plugin. You can read the code by downloading the plugin
from http://sourceforge.net/projects/sunshade. This works just fine with
existing editors.
- Eclipse 3.0 is doing something (?) to make external files editable. Can
you wait? ;-}
That's it. I'm out of "helpful" advice. Good luck.
Bob
"Raj Chari" <rc316@shaw.ca> wrote in message
news:bpolg7$gg3$1@eclipse.org...
> Hello,
>
> I put in the following code as mentioned before to use the metadata
> directory.
>
> IPath filePath = ePostPlugin.getDefault().getStateLocation();
>
> String fileNamePath = filePath.toOSString();
>
> File myFile = new File(fileNamePath + "/" + "test.epo");
>
> FileWriter fw = new FileWriter(myFile);
>
> fw.write(sb.toString());
>
> fw.close();
>
> file = fileToIFile(myFile);
>
> openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
>
> I still get the same problem with resource not found error showing up in
the
> editor. Where should we go from here?
> Thanks again,
>
> Raj
>
> "Bob Foster" <bob@objfac.com> wrote in message
> news:bpnkuj$ieb$1@eclipse.org...
> > Maybe I've been cryptic. Every plugin is allocated a folder in the
> > .metadata/.plugins folder of each workspace. This folder is writeable
and
> > AFAIK IFile-accessible. If your plugin's id is org.sample.myplug, that
> will
> > be the folder name. But you don't need to know that. getStateLocation()
> gets
> > it for you. You should be able to create a sub-folder there, write your
> temp
> > files into it and open those files in editors. More clear?
> >
> > (I've gone a bit out on a limb because I don't know what sort of
> knucklehead
> > code there is in Eclipse that might assume/require that every file is in
a
> > project - I believe Search makes this assumption - but I think that's
the
> > simplest solution to what you want to do so I suggest you try it. If it
> > doesn't work, there are other options, which involve creating a new
> project
> > to put the files into. This is quite easy to do; a few lines of code.
But
> > since the project would be user-visible, it's not such a good solution.
> > Hence, I have suggested this path.)
> >
> > Bob
> >
> > "Raj Chari" <rc316@shaw.ca> wrote in message
> > news:bpn8r0$831$1@eclipse.org...
> > > Can you explain what it is to use the metatdata? I'm not
understanding
> > what
> > > you're trying to say. So, are you saying when I create my
java.io.file,
> I
> > > should create the file in the .metadata directory? Sorry to be so
> dense..
> > > Thanks
> > >
> > > Raj
> > > "Bob Foster" <bob@objfac.com> wrote in message
> > > news:bpmra9$t34$1@eclipse.org...
> > > > Previously, I wrote:
> > > >
> > > > Use the .metadata area created for your plugin, which you can get
the
> > path
> > > > of by calling getStateLocation() in your plugin [class].
> > > >
> > > > The rest of the paragraph tells how to use the path to make a file.
> > > >
> > > > Bob
> > > >
> > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > news:bpljho$kpv$1@eclipse.org...
> > > > > Well,
> > > > >
> > > > > The file does exist but it's not in the workspace. I think this
> > > problem
> > > > > can be solved by adding the file to the workspace using the
> > appropriate
> > > > > commands and then maybe calling this code although, I have no idea
> of
> > > how
> > > > to
> > > > > add a file to the workpace by using java code. I've got a rough
> idea,
> > > but
> > > > > if anyone has a clear idea of how to do it, your help would be
> > greatly
> > > > > appreciated.
> > > > > Thanks
> > > > >
> > > > > Raj
> > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > news:bpl74v$3h5$1@eclipse.org...
> > > > > > Called my bluff, eh? ;-}
> > > > > >
> > > > > > Well, first of all, does the file exist? Second, is it actually
in
> a
> > > > > > workspace?
> > > > > >
> > > > > > My actual idea was to store the files in your plugin folder
inside
> > > > > > .metadata, which I know are ok to read and write, not just at
the
> > root
> > > > of
> > > > > > some workspace, which I don't know are ok.
> > > > > >
> > > > > > Anyway, check this stuff, do a little debugging, and if it isn't
> > > obvious
> > > > > > we'll go from there.
> > > > > >
> > > > > > Bob
> > > > > >
> > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > news:bpj6ou$ke$1@eclipse.org...
> > > > > > > Hi,
> > > > > > >
> > > > > > > So I used your idea Bob and I wrote up the following code:
> > > > > > >
> > > > > > > File myFile = new File("F:/ePost/workspace/test.txt");
> > > > > > > FileWriter fw = new FileWriter(myFile);
> > > > > > > fw.write(sb.toString());
> > > > > > > fw.close();
> > > > > > > file = fileToIFile(myFile);
> > > > > > > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> > > > > > >
> > > > > > >
> > > > > > > I wrote the two other functions that were suggested:
> > > > > > >
> > > > > > > public IFile fileToIFile(File f) {
> > > > > > > String p = f.getAbsolutePath();
> > > > > > > IPath path = new Path(p);
> > > > > > > return
> ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > }
> > > > > > >
> > > > > > > protected IEditorPart openEditor(IFile file, String editorId)
{
> > > > > > > IEditorPart editor = null;
> > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > IWorkbenchPage page =
> > > > > > >
> > > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > if (page != null) {
> > > > > > > editor = page.findEditor(input);
> > > > > > > if (editor != null) {
> > > > > > > page.bringToTop(editor);
> > > > > > > }
> > > > > > > else {
> > > > > > > try {
> > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > } catch (PartInitException e) {
> > > > > > > showMessage(e.getMessage());
> > > > > > > }
> > > > > > > }
> > > > > > > }
> > > > > > > return editor;
> > > > > > > }
> > > > > > >
> > > > > > > My output was that the file tried to open up in the editor and
> > > > > > > in the texteditor, it said, "Resource
/ePost/workspace/test.txt
> > does
> > > > not
> > > > > > > exist."
> > > > > > > Can someone tell me why this would happen and/or how this can
be
> > > > fixed?
> > > > > > > Thanks again
> > > > > > >
> > > > > > > Raj
> > > > > > >
> > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > news:bphok5$6us$1@eclipse.org...
> > > > > > > > I think you're headed off in the wrong direction. Please
> re-read
> > > my
> > > > > post
> > > > > > > > until you understand it. ;-}
> > > > > > > >
> > > > > > > > Bob
> > > > > > > >
> > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > news:bpgfbm$vfp$1@eclipse.org...
> > > > > > > > > Hi,
> > > > > > > > >
> > > > > > > > > I just re-read your post and my problem lies in the fact
> that
> > > I'm
> > > > > > > creating
> > > > > > > > > the file when I run my plugin, I have choice in where to
> store
> > > the
> > > > > > file
> > > > > > > > but
> > > > > > > > > it's not registered in the workspace. Will this still
work
> if
> > > the
> > > > > > file
> > > > > > > is
> > > > > > > > > not in the workspace. The other person suggested using
> > > IDocument
> > > > > and
> > > > > > > > > IEditorInput and I'm not sure how to use this. Does
anyone
> > know
> > > > how
> > > > > > to
> > > > > > > > use
> > > > > > > > > the IEditorInput and IDocument as mentioned in a previous
> > post?
> > > > I'm
> > > > > > > > looking
> > > > > > > > > for examples to see how to use IDocument.
> > > > > > > > > Thanks
> > > > > > > > >
> > > > > > > > > Raj
> > > > > > > > >
> > > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > > news:bpfb7k$ff5$1@eclipse.org...
> > > > > > > > > > Thank you so much Bob!
> > > > > > > > > >
> > > > > > > > > > Raj
> > > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > > news:bpf514$940$1@eclipse.org...
> > > > > > > > > > > As long as the file is in the workspace, I think you
can
> > do
> > > > it.
> > > > > > Use
> > > > > > > > the
> > > > > > > > > > > .metadata area created for your plugin, which you can
> get
> > > the
> > > > > path
> > > > > > > of
> > > > > > > > by
> > > > > > > > > > > calling getStateLocation() in your plugin.
toOSString()
> > will
> > > > get
> > > > > > you
> > > > > > > a
> > > > > > > > > > path
> > > > > > > > > > > suitable for java.io.File and you're off and running.
> When
> > > you
> > > > > > have
> > > > > > > a
> > > > > > > > > File
> > > > > > > > > > > created there, call the following to get an IFile:
> > > > > > > > > > >
> > > > > > > > > > > public IFile fileToIFile(File f) {
> > > > > > > > > > > String p = f.getPath();
> > > > > > > > > > > IPath path = new Path(p);
> > > > > > > > > > > return
> > > > ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > (I just typed that in; if it doesn't compile, fix it.)
> > Then,
> > > I
> > > > > > have
> > > > > > > > this
> > > > > > > > > > bit
> > > > > > > > > > > of code lying around that will do the rest:
> > > > > > > > > > >
> > > > > > > > > > > protected IEditorPart openEditor(IFile file, String
> > > editorId)
> > > > {
> > > > > > > > > > > IEditorPart editor = null;
> > > > > > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > > > > > IWorkbenchPage page =
> > > > > > > > > > >
> > > > > > >
> > > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > > > > > if (page != null) {
> > > > > > > > > > > editor = page.findEditor(input);
> > > > > > > > > > > if (editor != null) {
> > > > > > > > > > > page.bringToTop(editor);
> > > > > > > > > > > }
> > > > > > > > > > > else {
> > > > > > > > > > > try {
> > > > > > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > > > > > } catch (PartInitException e) {
> > > > > > > > > > > //log the error or something
> > > > > > > > > > > }
> > > > > > > > > > > }
> > > > > > > > > > > }
> > > > > > > > > > > return editor;
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > I haven't tried exactly this case and there's probably
> > > shorter
> > > > > > code
> > > > > > > to
> > > > > > > > > do
> > > > > > > > > > it
> > > > > > > > > > > (I try to avoid Eclipse's IResource, uh, stuff as much
> as
> > I
> > > > > can),
> > > > > > > but
> > > > > > > > > > that's
> > > > > > > > > > > the general idea.
> > > > > > > > > > >
> > > > > > > > > > > Bob
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > > > > > > > Hi Bob and Rich,
> > > > > > > > > > > >
> > > > > > > > > > > > Thanks for your help. The thing is that the file
I'm
> > > > creating
> > > > > > is
> > > > > > > > done
> > > > > > > > > > on
> > > > > > > > > > > > the fly as my plugin runs and so it's not in the
> > > workspace.
> > > > > > > > > > > > Basically, this is what I'm trying to do.
> > > > > > > > > > > > I'm trying to create a newsgroup client plugin for
> > eclipse
> > > > and
> > > > > I
> > > > > > > > > create
> > > > > > > > > > a
> > > > > > > > > > > > view in which the messages are displayed in. When I
> > > > > > double-click
> > > > > > > a
> > > > > > > > > > > message,
> > > > > > > > > > > > I would like to open it in the text editor.
> > > > > > > > > > > > The way I'm going about this is that I'm grabbing
the
> > > > > > information
> > > > > > > > from
> > > > > > > > > > the
> > > > > > > > > > > > doubleclick event and writing it into temp file and
I
> > want
> > > > to
> > > > > > > > display
> > > > > > > > > > this
> > > > > > > > > > > > temp file in the editor. From what I've read and
what
> > > I've
> > > > > > tried,
> > > > > > > > it
> > > > > > > > > > > seems
> > > > > > > > > > > > that this is not possible if this file is not
> associated
> > > in
> > > > > the
> > > > > > > > > > workspace,
> > > > > > > > > > > > as you guys have pointed out.
> > > > > > > > > > > > In your opinion, is what I'm trying to do possible?
> > > > > > > > > > > > Thanks again,
> > > > > > > > > > > >
> > > > > > > > > > > > Raj
> > > > > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > > > > > > > Well, you could create a linked file in the
> workspace
> > > that
> > > > > > works
> > > > > > > > as
> > > > > > > > > a
> > > > > > > > > > > > > surrogate for the non-workspace file.
> > > > > > > > > > > > >
> > > > > > > > > > > > > (Also, when going the other way, from IFile to
File,
> > you
> > > > > want
> > > > > > to
> > > > > > > > use
> > > > > > > > > > > > > getLocation() not getFullPath().)
> > > > > > > > > > > > >
> > > > > > > > > > > > > Bob
> > > > > > > > > > > > >
> > > > > > > > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in
> > > message
> > > > > > > > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > > > > > > > But remember, this only works for files that are
> in
> > > the
> > > > > > > > workspace.
> > > > > > > > > > If
> > > > > > > > > > > > > > the file is not in the workspace anywhere (i.e.
> some
> > > > > generic
> > > > > > > > file
> > > > > > > > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --
> > > > > > > > > > > > > > Thanks, Rich Kulp
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: File to IFile [message #160685 is a reply to message #160675] |
Sun, 23 November 2003 06:23 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: rc316.shaw.ca
thanks for all your help bob
Raj
"Bob Foster" <bob@objfac.com> wrote in message
news:bppf3t$4nd$1@eclipse.org...
> Well, you remember when I said I'd never tried this? ;-} It looks like
> workspaceroot's getFile() will return null if the file isn't in a project,
> so I'm really surprised you got anything as civil as file not found. I
would
> have expected NullPointerException.
>
> I'm not an expert on these crappy IPath/IFile things, but I can't see an
> easy way to make what I suggested work without a project. If someone else
> does, feel free to jump in.
>
> There are two other ways to open something in an editor:
>
> - Use IStorage, but these aren't editable unless you replace the storage
> provider (editing won't work with .java files and I don't truly know what
> kinds of files it will work with). See Ed Burnett's fileopen plugin for
> working code: http://sourceforge.net/project/showfiles.php?group_id=73634
>
> - Use linked files and a project to contain them, as is done by Matt
> Conway's filedrag plugin. You can read the code by downloading the plugin
> from http://sourceforge.net/projects/sunshade. This works just fine with
> existing editors.
>
> - Eclipse 3.0 is doing something (?) to make external files editable. Can
> you wait? ;-}
>
> That's it. I'm out of "helpful" advice. Good luck.
>
> Bob
>
> "Raj Chari" <rc316@shaw.ca> wrote in message
> news:bpolg7$gg3$1@eclipse.org...
> > Hello,
> >
> > I put in the following code as mentioned before to use the metadata
> > directory.
> >
> > IPath filePath = ePostPlugin.getDefault().getStateLocation();
> >
> > String fileNamePath = filePath.toOSString();
> >
> > File myFile = new File(fileNamePath + "/" + "test.epo");
> >
> > FileWriter fw = new FileWriter(myFile);
> >
> > fw.write(sb.toString());
> >
> > fw.close();
> >
> > file = fileToIFile(myFile);
> >
> > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> >
> > I still get the same problem with resource not found error showing up in
> the
> > editor. Where should we go from here?
> > Thanks again,
> >
> > Raj
> >
> > "Bob Foster" <bob@objfac.com> wrote in message
> > news:bpnkuj$ieb$1@eclipse.org...
> > > Maybe I've been cryptic. Every plugin is allocated a folder in the
> > > .metadata/.plugins folder of each workspace. This folder is writeable
> and
> > > AFAIK IFile-accessible. If your plugin's id is org.sample.myplug, that
> > will
> > > be the folder name. But you don't need to know that.
getStateLocation()
> > gets
> > > it for you. You should be able to create a sub-folder there, write
your
> > temp
> > > files into it and open those files in editors. More clear?
> > >
> > > (I've gone a bit out on a limb because I don't know what sort of
> > knucklehead
> > > code there is in Eclipse that might assume/require that every file is
in
> a
> > > project - I believe Search makes this assumption - but I think that's
> the
> > > simplest solution to what you want to do so I suggest you try it. If
it
> > > doesn't work, there are other options, which involve creating a new
> > project
> > > to put the files into. This is quite easy to do; a few lines of code.
> But
> > > since the project would be user-visible, it's not such a good
solution.
> > > Hence, I have suggested this path.)
> > >
> > > Bob
> > >
> > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > news:bpn8r0$831$1@eclipse.org...
> > > > Can you explain what it is to use the metatdata? I'm not
> understanding
> > > what
> > > > you're trying to say. So, are you saying when I create my
> java.io.file,
> > I
> > > > should create the file in the .metadata directory? Sorry to be so
> > dense..
> > > > Thanks
> > > >
> > > > Raj
> > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > news:bpmra9$t34$1@eclipse.org...
> > > > > Previously, I wrote:
> > > > >
> > > > > Use the .metadata area created for your plugin, which you can get
> the
> > > path
> > > > > of by calling getStateLocation() in your plugin [class].
> > > > >
> > > > > The rest of the paragraph tells how to use the path to make a
file.
> > > > >
> > > > > Bob
> > > > >
> > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > news:bpljho$kpv$1@eclipse.org...
> > > > > > Well,
> > > > > >
> > > > > > The file does exist but it's not in the workspace. I think
this
> > > > problem
> > > > > > can be solved by adding the file to the workspace using the
> > > appropriate
> > > > > > commands and then maybe calling this code although, I have no
idea
> > of
> > > > how
> > > > > to
> > > > > > add a file to the workpace by using java code. I've got a rough
> > idea,
> > > > but
> > > > > > if anyone has a clear idea of how to do it, your help would be
> > > greatly
> > > > > > appreciated.
> > > > > > Thanks
> > > > > >
> > > > > > Raj
> > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > news:bpl74v$3h5$1@eclipse.org...
> > > > > > > Called my bluff, eh? ;-}
> > > > > > >
> > > > > > > Well, first of all, does the file exist? Second, is it
actually
> in
> > a
> > > > > > > workspace?
> > > > > > >
> > > > > > > My actual idea was to store the files in your plugin folder
> inside
> > > > > > > .metadata, which I know are ok to read and write, not just at
> the
> > > root
> > > > > of
> > > > > > > some workspace, which I don't know are ok.
> > > > > > >
> > > > > > > Anyway, check this stuff, do a little debugging, and if it
isn't
> > > > obvious
> > > > > > > we'll go from there.
> > > > > > >
> > > > > > > Bob
> > > > > > >
> > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > news:bpj6ou$ke$1@eclipse.org...
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > So I used your idea Bob and I wrote up the following code:
> > > > > > > >
> > > > > > > > File myFile = new File("F:/ePost/workspace/test.txt");
> > > > > > > > FileWriter fw = new FileWriter(myFile);
> > > > > > > > fw.write(sb.toString());
> > > > > > > > fw.close();
> > > > > > > > file = fileToIFile(myFile);
> > > > > > > > openEditor(file, IWorkbenchConstants.DEFAULT_EDITOR_ID);
> > > > > > > >
> > > > > > > >
> > > > > > > > I wrote the two other functions that were suggested:
> > > > > > > >
> > > > > > > > public IFile fileToIFile(File f) {
> > > > > > > > String p = f.getAbsolutePath();
> > > > > > > > IPath path = new Path(p);
> > > > > > > > return
> > ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > > }
> > > > > > > >
> > > > > > > > protected IEditorPart openEditor(IFile file, String
editorId)
> {
> > > > > > > > IEditorPart editor = null;
> > > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > > IWorkbenchPage page =
> > > > > > > >
> > > >
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > > if (page != null) {
> > > > > > > > editor = page.findEditor(input);
> > > > > > > > if (editor != null) {
> > > > > > > > page.bringToTop(editor);
> > > > > > > > }
> > > > > > > > else {
> > > > > > > > try {
> > > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > > } catch (PartInitException e) {
> > > > > > > > showMessage(e.getMessage());
> > > > > > > > }
> > > > > > > > }
> > > > > > > > }
> > > > > > > > return editor;
> > > > > > > > }
> > > > > > > >
> > > > > > > > My output was that the file tried to open up in the editor
and
> > > > > > > > in the texteditor, it said, "Resource
> /ePost/workspace/test.txt
> > > does
> > > > > not
> > > > > > > > exist."
> > > > > > > > Can someone tell me why this would happen and/or how this
can
> be
> > > > > fixed?
> > > > > > > > Thanks again
> > > > > > > >
> > > > > > > > Raj
> > > > > > > >
> > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > news:bphok5$6us$1@eclipse.org...
> > > > > > > > > I think you're headed off in the wrong direction. Please
> > re-read
> > > > my
> > > > > > post
> > > > > > > > > until you understand it. ;-}
> > > > > > > > >
> > > > > > > > > Bob
> > > > > > > > >
> > > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > > news:bpgfbm$vfp$1@eclipse.org...
> > > > > > > > > > Hi,
> > > > > > > > > >
> > > > > > > > > > I just re-read your post and my problem lies in the fact
> > that
> > > > I'm
> > > > > > > > creating
> > > > > > > > > > the file when I run my plugin, I have choice in where to
> > store
> > > > the
> > > > > > > file
> > > > > > > > > but
> > > > > > > > > > it's not registered in the workspace. Will this still
> work
> > if
> > > > the
> > > > > > > file
> > > > > > > > is
> > > > > > > > > > not in the workspace. The other person suggested using
> > > > IDocument
> > > > > > and
> > > > > > > > > > IEditorInput and I'm not sure how to use this. Does
> anyone
> > > know
> > > > > how
> > > > > > > to
> > > > > > > > > use
> > > > > > > > > > the IEditorInput and IDocument as mentioned in a
previous
> > > post?
> > > > > I'm
> > > > > > > > > looking
> > > > > > > > > > for examples to see how to use IDocument.
> > > > > > > > > > Thanks
> > > > > > > > > >
> > > > > > > > > > Raj
> > > > > > > > > >
> > > > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > > > news:bpfb7k$ff5$1@eclipse.org...
> > > > > > > > > > > Thank you so much Bob!
> > > > > > > > > > >
> > > > > > > > > > > Raj
> > > > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > > > news:bpf514$940$1@eclipse.org...
> > > > > > > > > > > > As long as the file is in the workspace, I think you
> can
> > > do
> > > > > it.
> > > > > > > Use
> > > > > > > > > the
> > > > > > > > > > > > .metadata area created for your plugin, which you
can
> > get
> > > > the
> > > > > > path
> > > > > > > > of
> > > > > > > > > by
> > > > > > > > > > > > calling getStateLocation() in your plugin.
> toOSString()
> > > will
> > > > > get
> > > > > > > you
> > > > > > > > a
> > > > > > > > > > > path
> > > > > > > > > > > > suitable for java.io.File and you're off and
running.
> > When
> > > > you
> > > > > > > have
> > > > > > > > a
> > > > > > > > > > File
> > > > > > > > > > > > created there, call the following to get an IFile:
> > > > > > > > > > > >
> > > > > > > > > > > > public IFile fileToIFile(File f) {
> > > > > > > > > > > > String p = f.getPath();
> > > > > > > > > > > > IPath path = new Path(p);
> > > > > > > > > > > > return
> > > > > ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > > (I just typed that in; if it doesn't compile, fix
it.)
> > > Then,
> > > > I
> > > > > > > have
> > > > > > > > > this
> > > > > > > > > > > bit
> > > > > > > > > > > > of code lying around that will do the rest:
> > > > > > > > > > > >
> > > > > > > > > > > > protected IEditorPart openEditor(IFile file, String
> > > > editorId)
> > > > > {
> > > > > > > > > > > > IEditorPart editor = null;
> > > > > > > > > > > > IEditorInput input = new FileEditorInput(file);
> > > > > > > > > > > > IWorkbenchPage page =
> > > > > > > > > > > >
> > > > > > > >
> > > >
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> > > > > > > > > > > > if (page != null) {
> > > > > > > > > > > > editor = page.findEditor(input);
> > > > > > > > > > > > if (editor != null) {
> > > > > > > > > > > > page.bringToTop(editor);
> > > > > > > > > > > > }
> > > > > > > > > > > > else {
> > > > > > > > > > > > try {
> > > > > > > > > > > > editor = page.openEditor(input, editorId);
> > > > > > > > > > > > } catch (PartInitException e) {
> > > > > > > > > > > > //log the error or something
> > > > > > > > > > > > }
> > > > > > > > > > > > }
> > > > > > > > > > > > }
> > > > > > > > > > > > return editor;
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > > I haven't tried exactly this case and there's
probably
> > > > shorter
> > > > > > > code
> > > > > > > > to
> > > > > > > > > > do
> > > > > > > > > > > it
> > > > > > > > > > > > (I try to avoid Eclipse's IResource, uh, stuff as
much
> > as
> > > I
> > > > > > can),
> > > > > > > > but
> > > > > > > > > > > that's
> > > > > > > > > > > > the general idea.
> > > > > > > > > > > >
> > > > > > > > > > > > Bob
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > "Raj Chari" <rc316@shaw.ca> wrote in message
> > > > > > > > > > > > news:bpckbl$bvc$1@eclipse.org...
> > > > > > > > > > > > > Hi Bob and Rich,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Thanks for your help. The thing is that the file
> I'm
> > > > > creating
> > > > > > > is
> > > > > > > > > done
> > > > > > > > > > > on
> > > > > > > > > > > > > the fly as my plugin runs and so it's not in the
> > > > workspace.
> > > > > > > > > > > > > Basically, this is what I'm trying to do.
> > > > > > > > > > > > > I'm trying to create a newsgroup client plugin for
> > > eclipse
> > > > > and
> > > > > > I
> > > > > > > > > > create
> > > > > > > > > > > a
> > > > > > > > > > > > > view in which the messages are displayed in. When
I
> > > > > > > double-click
> > > > > > > > a
> > > > > > > > > > > > message,
> > > > > > > > > > > > > I would like to open it in the text editor.
> > > > > > > > > > > > > The way I'm going about this is that I'm grabbing
> the
> > > > > > > information
> > > > > > > > > from
> > > > > > > > > > > the
> > > > > > > > > > > > > doubleclick event and writing it into temp file
and
> I
> > > want
> > > > > to
> > > > > > > > > display
> > > > > > > > > > > this
> > > > > > > > > > > > > temp file in the editor. From what I've read and
> what
> > > > I've
> > > > > > > tried,
> > > > > > > > > it
> > > > > > > > > > > > seems
> > > > > > > > > > > > > that this is not possible if this file is not
> > associated
> > > > in
> > > > > > the
> > > > > > > > > > > workspace,
> > > > > > > > > > > > > as you guys have pointed out.
> > > > > > > > > > > > > In your opinion, is what I'm trying to do
possible?
> > > > > > > > > > > > > Thanks again,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Raj
> > > > > > > > > > > > > "Bob Foster" <bob@objfac.com> wrote in message
> > > > > > > > > > > > > news:bpbqol$kct$1@eclipse.org...
> > > > > > > > > > > > > > Well, you could create a linked file in the
> > workspace
> > > > that
> > > > > > > works
> > > > > > > > > as
> > > > > > > > > > a
> > > > > > > > > > > > > > surrogate for the non-workspace file.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > (Also, when going the other way, from IFile to
> File,
> > > you
> > > > > > want
> > > > > > > to
> > > > > > > > > use
> > > > > > > > > > > > > > getLocation() not getFullPath().)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Bob
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > "Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote
in
>
> > > > message
> > > > > > > > > > > > > > news:bpan7b$7rr$2@eclipse.org...
> > > > > > > > > > > > > > > But remember, this only works for files that
are
> > in
> > > > the
> > > > > > > > > workspace.
> > > > > > > > > > > If
> > > > > > > > > > > > > > > the file is not in the workspace anywhere
(i.e.
> > some
> > > > > > generic
> > > > > > > > > file
> > > > > > > > > > > > > > > someplace else), you can't get an IFile to it.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --
> > > > > > > > > > > > > > > Thanks, Rich Kulp
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
|
|
|
Goto Forum:
Current Time: Sat Aug 17 02:31:23 GMT 2024
Powered by FUDForum. Page generated in 0.05989 seconds
|