Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Get IResource of currently open file?
Get IResource of currently open file? [message #40195] Tue, 20 May 2003 11:20 Go to next message
Eclipse UserFriend
Hi,

I have implemented an action that performs an analysis of a JUnit test
case (more of that later this week, I hope...). Now, the user presses the
button and I'd like to get the IResource of the file that is currently
open in the editor. So far, I do it by using an
IJavaSearchResultsCollector -- that means that I am "simply" searching for
the file name of the currently active workbench window. Now, I am pretty
sure that there is an easier way, but I was probably too blind to find
it...
Do you know, how I can retrieve the IResource of the currently active
workbench page?

Thanks for your help,
Philipp
Re: Get IResource of currently open file? [message #42123 is a reply to message #40195] Wed, 21 May 2003 10:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: John_Arthorne.oti.com_

You can use IWorkbenchPage.getActiveEditor or getEditors(), then you can
ask the editors for their IEditorInput. If the editor is operating on
an IFile (and there is no guarantee that it is), then you can cast
IEditorInput to IFileEditorInput to get access to the file via
IFileEditorInput.getFile().
--


Philipp Bouillon wrote:
> Hi,
>
> I have implemented an action that performs an analysis of a JUnit test
> case (more of that later this week, I hope...). Now, the user presses the
> button and I'd like to get the IResource of the file that is currently
> open in the editor. So far, I do it by using an
> IJavaSearchResultsCollector -- that means that I am "simply" searching for
> the file name of the currently active workbench window. Now, I am pretty
> sure that there is an easier way, but I was probably too blind to find
> it...
> Do you know, how I can retrieve the IResource of the currently active
> workbench page?
>
> Thanks for your help,
> Philipp
>
Re: Get IResource of currently open file? [message #43713 is a reply to message #42123] Thu, 22 May 2003 07:44 Go to previous messageGo to next message
Eclipse UserFriend
Thanks!
Now, if the editor is not operating on an IFile, what other classes could
it in fact operate on?
Can I assume that any written JUnit test (or java program) which is not a
class file, but a .java file is an IFile?
In other words: Can I assume that if the editor is not operating on an
IFile, that no java source file is currently edited in the active window?

Philipp

> You can use IWorkbenchPage.getActiveEditor or getEditors(), then you can
> ask the editors for their IEditorInput. If the editor is operating on
> an IFile (and there is no guarantee that it is), then you can cast
> IEditorInput to IFileEditorInput to get access to the file via
> IFileEditorInput.getFile().
> --


> Philipp Bouillon wrote:
> > Hi,
> >
> > I have implemented an action that performs an analysis of a JUnit test
> > case (more of that later this week, I hope...). Now, the user presses the
> > button and I'd like to get the IResource of the file that is currently
> > open in the editor. So far, I do it by using an
> > IJavaSearchResultsCollector -- that means that I am "simply" searching for
> > the file name of the currently active workbench window. Now, I am pretty
> > sure that there is an easier way, but I was probably too blind to find
> > it...
> > Do you know, how I can retrieve the IResource of the currently active
> > workbench page?
> >
> > Thanks for your help,
> > Philipp
> >
Re: Get IResource of currently open file? [message #45634 is a reply to message #43713] Fri, 23 May 2003 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: John_Arthorne.oti.com_

I believe the only other input the java editor understands is
IStorageEditorInput. This is a read-only input object that is used for
files in remote locations, or in zips and JARs. Since the user is
generally only browsing these types of files, they're probably not
interesting for your tool. So yes, you can probably ignore editors that
aren't operating on an IFile.
--


Philipp Bouillon wrote:
> Thanks!
> Now, if the editor is not operating on an IFile, what other classes could
> it in fact operate on?
> Can I assume that any written JUnit test (or java program) which is not a
> class file, but a .java file is an IFile?
> In other words: Can I assume that if the editor is not operating on an
> IFile, that no java source file is currently edited in the active window?
>
> Philipp
>
>
>>You can use IWorkbenchPage.getActiveEditor or getEditors(), then you can
>>ask the editors for their IEditorInput. If the editor is operating on
>>an IFile (and there is no guarantee that it is), then you can cast
>>IEditorInput to IFileEditorInput to get access to the file via
>>IFileEditorInput.getFile().
>>--
>
>
>
>>Philipp Bouillon wrote:
>>
>>>Hi,
>>>
>>>I have implemented an action that performs an analysis of a JUnit test
>>>case (more of that later this week, I hope...). Now, the user presses the
>>>button and I'd like to get the IResource of the file that is currently
>>>open in the editor. So far, I do it by using an
>>>IJavaSearchResultsCollector -- that means that I am "simply" searching for
>>>the file name of the currently active workbench window. Now, I am pretty
>>>sure that there is an easier way, but I was probably too blind to find
>>>it...
>>>Do you know, how I can retrieve the IResource of the currently active
>>>workbench page?
>>>
>>>Thanks for your help,
>>>Philipp
>>>
>>
>
>
>
>
Re: Get IResource of currently open file? [message #45980 is a reply to message #45634] Fri, 23 May 2003 10:54 Go to previous message
Eclipse UserFriend
Cool!
Thanks for your help. Now, I can finally forget about the
ISearchResultsCollector *brrrr*.

Have a nice weekend,
Philipp

> I believe the only other input the java editor understands is
> IStorageEditorInput. This is a read-only input object that is used for
> files in remote locations, or in zips and JARs. Since the user is
> generally only browsing these types of files, they're probably not
> interesting for your tool. So yes, you can probably ignore editors that
> aren't operating on an IFile.
> --


> Philipp Bouillon wrote:
> > Thanks!
> > Now, if the editor is not operating on an IFile, what other classes could
> > it in fact operate on?
> > Can I assume that any written JUnit test (or java program) which is not a
> > class file, but a .java file is an IFile?
> > In other words: Can I assume that if the editor is not operating on an
> > IFile, that no java source file is currently edited in the active window?
> >
> > Philipp
> >
> >
> >>You can use IWorkbenchPage.getActiveEditor or getEditors(), then you can
> >>ask the editors for their IEditorInput. If the editor is operating on
> >>an IFile (and there is no guarantee that it is), then you can cast
> >>IEditorInput to IFileEditorInput to get access to the file via
> >>IFileEditorInput.getFile().
> >>--
> >
> >
> >
> >>Philipp Bouillon wrote:
> >>
> >>>Hi,
> >>>
> >>>I have implemented an action that performs an analysis of a JUnit test
> >>>case (more of that later this week, I hope...). Now, the user presses the
> >>>button and I'd like to get the IResource of the file that is currently
> >>>open in the editor. So far, I do it by using an
> >>>IJavaSearchResultsCollector -- that means that I am "simply" searching for
> >>>the file name of the currently active workbench window. Now, I am pretty
> >>>sure that there is an easier way, but I was probably too blind to find
> >>>it...
> >>>Do you know, how I can retrieve the IResource of the currently active
> >>>workbench page?
> >>>
> >>>Thanks for your help,
> >>>Philipp
> >>>
> >>
> >
> >
> >
> >
Previous Topic:Is there a way I can get Eclipse "build" the java file I just imported at when I want?
Next Topic:ISharedImages
Goto Forum:
  


Current Time: Wed Jul 02 16:55:12 EDT 2025

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

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

Back to the top