Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Only respond to Resource Change Events caused by external changes to a file
Only respond to Resource Change Events caused by external changes to a file [message #1017503] Mon, 11 March 2013 20:16 Go to next message
Eclipse UserFriend
Hello Folks,

I have an RCP application with an editor for a particular type of file (that contains an EMF model). If that file gets modified by some external editor or process while the editor has the file open, I want to prompt the user with the option to "reload."

I added a ResourceChangeListener that responds to POST_CHANGE and this works well for me. Now, when someone uses Notepad or other to edit a file, my application can deal with it.

However, I now have the problem that this listener responds to changes caused by a simple save action! This is not external and does not require a "reload".

Is there some way to suppress the Resource Changed event without causing a race condition? Am I going about this wrong?

I'm trying to replicate behavior that one usually sees with a text editor where it will prompt you to "reload" if the file has "changed on disk" (e.g. like Notepad++ does)

-Jesse
Re: Only respond to Resource Change Events caused by external changes to a file [message #1021916 is a reply to message #1017503] Wed, 20 March 2013 19:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jesse,

You have to build in a "isSaving" boolean like so:

doSave{
isSaving = true;
save ...
isSaving = false;
}

showReloadDialog{
if(isSaving)
return;
show dialog
}

Best Regards,

Wim
> Hello Folks,
>
> I have an RCP application with an editor for a particular type of file
(that contains an EMF model). If that file gets modified by some external
editor or process while the editor has the file open, I want to prompt the
user with the option to "reload."
>
> I added a ResourceChangeListener that responds to POST_CHANGE and this
works well for me. Now, when someone uses Notepad or other to edit a file, my
application can deal with it.
>
> However, I now have the problem that this listener responds to changes
caused by a simple save action! This is not external and does not require a
"reload".
>
> Is there some way to suppress the Resource Changed event without causing a
race condition? Am I going about this wrong?
>
> I'm trying to replicate behavior that one usually sees with a text editor
where it will prompt you to "reload" if the file has "changed on disk" (e.g.
like Notepad++ does)
>
> -Jesse
Re: Only respond to Resource Change Events caused by external changes to a file [message #1022817 is a reply to message #1021916] Fri, 22 March 2013 11:22 Go to previous messageGo to next message
Eclipse UserFriend
I already naively tried that. The problem is that the ResourceChangedListener does not receive the event during the save. It's asynchronous. Thus it becomes a race condition.

Thanks for the suggestion though.

Re: Only respond to Resource Change Events caused by external changes to a file [message #1022916 is a reply to message #1022817] Fri, 22 March 2013 15:38 Go to previous message
Eclipse UserFriend
I did not used editors and resource changes API, but I see that the ResourceChangeEvent has a getSource() method. I assume that you can look into the source object and detect if the resource was changed internally (e.g. a save action within the workspace) or externally (e.g. Notepad).
Thus you can show the reload dialog only in case of external changes.
Previous Topic:Question about the tabbed properties view
Next Topic:Query on SWT Browser response messages
Goto Forum:
  


Current Time: Tue Mar 25 15:13:12 EDT 2025

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

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

Back to the top