Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Open editor and parent IFolder rename
Open editor and parent IFolder rename [message #332824] Mon, 10 November 2008 20:58 Go to next message
Duncan Krebs is currently offline Duncan KrebsFriend
Messages: 79
Registered: July 2009
Member
Hi,
I've been stuck on this for a while, we have an RCP application that is
using the resource navigator and all our editors for resources are custom
and do not extend TextEditor. The issue I can't figure out is that when a
editor is currently open for one of our resources and the user renames a
parent resource it makes the IFile reference in the IEditorInput invalid
because during the rename process the IFile that is referenced is deleted
and new one is added to reflect the updated path.

Somehow the open editor needs to be made aware of a parent IFolder rename
event and should be able to access the new IFile so that it maintains a
valid reference to the resource being edited. Furthermore when this event
happens the editor needs to be able to set the part name which I have
found can be achieved by a call to setPartName() but when testing that the
UI is not updated to reflect the new title of the open editor and was
wondering how to force a UI update.

Any help would be greatly appreciated as I've been stuck on this for a
while. One last note I did notice that text editors are able to respond
nicely to a parent resource change and I can't find the code that is
making that possible. - Duncan
Re: Open editor and parent IFolder rename [message #332828 is a reply to message #332824] Mon, 10 November 2008 21:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Duncan,

In the generated EMF editors we do this

protected IResourceChangeListener resourceChangeListener =
new IResourceChangeListener()
{
public void resourceChanged(IResourceChangeEvent event)
{
//...

And this:

public void init(IEditorSite site, IEditorInput editorInput)
{
//....

ResourcesPlugin.getWorkspace().addResourceChangeListener(res ourceChangeListener,
IResourceChangeEvent.POST_CHANGE);
}

And of course we don't forget to do this:

public void dispose()
{
//...

ResourcesPlugin.getWorkspace().removeResourceChangeListener( resourceChangeListener);




Duncan Krebs wrote:
> Hi, I've been stuck on this for a while, we have an RCP application
> that is using the resource navigator and all our editors for resources
> are custom and do not extend TextEditor. The issue I can't figure out
> is that when a editor is currently open for one of our resources and
> the user renames a parent resource it makes the IFile reference in the
> IEditorInput invalid because during the rename process the IFile that
> is referenced is deleted and new one is added to reflect the updated
> path.
> Somehow the open editor needs to be made aware of a parent IFolder
> rename event and should be able to access the new IFile so that it
> maintains a valid reference to the resource being edited. Furthermore
> when this event happens the editor needs to be able to set the part
> name which I have found can be achieved by a call to setPartName() but
> when testing that the UI is not updated to reflect the new title of
> the open editor and was wondering how to force a UI update.
> Any help would be greatly appreciated as I've been stuck on this for a
> while. One last note I did notice that text editors are able to
> respond nicely to a parent resource change and I can't find the code
> that is making that possible. - Duncan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Open editor and parent IFolder rename [message #332832 is a reply to message #332828] Mon, 10 November 2008 22:09 Go to previous messageGo to next message
Duncan Krebs is currently offline Duncan KrebsFriend
Messages: 79
Registered: July 2009
Member
Hi Ed,
Thanks for the information, I generated a test EMF editor and was able to
locate the code you referenced which is a nice example to work from. From
testing the editor I see that if a parent folder is renamed and editors
that are editing child resources are open they will be closed by default.

To go one step further and reopen the editor for the user how would you
suggest I implement this. My first thought is to open the editor after
closing it in code but am a little stuck on how to get a reference to the
correct IResource that references the same file we were editing before the
parent resource rename happened.

Thanks again for your help. - Duncan
Re: Open editor and parent IFolder rename [message #332851 is a reply to message #332832] Tue, 11 November 2008 09:34 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
Your editor's input should have the information on the file being edited :
((IFileEditorInput)getEditorInput()).getFile() should work

- Prakash
--

http://blog.eclipse-tips.com
Re: Open editor and parent IFolder rename [message #332853 is a reply to message #332832] Tue, 11 November 2008 12:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Duncan,

I guess the IFile itself doesn't just have the new name? If it does,
what Prakash suggested ought to work. If not, I assume you'd have to
compute it based on the information in the resource delta.


Duncan Krebs wrote:
> Hi Ed, Thanks for the information, I generated a test EMF editor and
> was able to locate the code you referenced which is a nice example to
> work from. From testing the editor I see that if a parent folder is
> renamed and editors that are editing child resources are open they
> will be closed by default.
> To go one step further and reopen the editor for the user how would
> you suggest I implement this. My first thought is to open the editor
> after closing it in code but am a little stuck on how to get a
> reference to the correct IResource that references the same file we
> were editing before the parent resource rename happened.
> Thanks again for your help. - Duncan


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Hide/Show a TreeColumn in a Tree
Next Topic:Expressions
Goto Forum:
  


Current Time: Fri Apr 19 21:23:11 GMT 2024

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

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

Back to the top