Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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] Tue, 12 March 2013 00:16 Go to next message
Jesse Steinfort is currently offline Jesse SteinfortFriend
Messages: 7
Registered: October 2009
Junior Member
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 23:15 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
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 15:22 Go to previous messageGo to next message
Jesse Steinfort is currently offline Jesse SteinfortFriend
Messages: 7
Registered: October 2009
Junior Member
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 19:38 Go to previous message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

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: Thu Dec 08 04:09:03 GMT 2016

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

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