Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to check if my object state has changed ?
How to check if my object state has changed ? [message #1253585] Sat, 22 February 2014 12:33 Go to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
So far I'm using the following code to check if my objects where changed:

EContentAdapter adapter = new EContentAdapter() {
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
eventBroker.post(CommonEvents.TOPIC_MODEL_IS_DIRTY, Boolean.TRUE);
}
};

But this is not a real solution. If the users types two character and deletes this two characters (i'm using EMF databinding) I would like to get the info that my model is not dirty anymore. Is this possible ?

[Updated on: Sat, 22 February 2014 12:38]

Report message to a moderator

Re: How to check if a model is changed ? [message #1253665 is a reply to message #1253585] Sat, 22 February 2014 14:37 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 22/02/2014 13:33, Roger Gilliar wrote:
> So far I'm using the following code to check if a model has changed:
>
> EContentAdapter adapter = new EContentAdapter() {
> @Override
> public void notifyChanged(Notification notification) {
> super.notifyChanged(notification);
> eventBroker.post(CommonEvents.TOPIC_MODEL_IS_DIRTY, Boolean.TRUE);
> }
> };
>
> But this is not a real solution. If the users types two character and
> deletes this two characters I would like to get the info that the model
> is not dirty anymore. Is this possible ?
>

As far as EMF goes, the content adapter is at good as it gets. There is
also the (iirc command-stack based) resource.isModified(). Possible to
solve otherwise? I have seen somewhere in Sirius code that they simply
save the model to a temporary file and then check if the files are
equal. Not sure if there's a better solution, it's at least very complex
to check whether a set of changes is actually neutralizes itself. To
begin with, you'd have to record all changes since the last save until
you know you're back at 0, and that might take forever if the user comes
in at 8, and saves once at 5. :)

I also felt incomfortable with this problem once until I realized that
it's more a theoretical issue than something that would affect a user
too much.
Re: How to check if a model is changed ? [message #1253681 is a reply to message #1253585] Sat, 22 February 2014 15:04 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1199
Registered: July 2009
Location: Canada
Senior Member

Hi, Roger,

As long as your application consistently uses Commands executed on an
EditingDomain's CommandStack to modify your model instance, then the
CommandStack tracks whether it has been changed from the last saved
state. See how the generated editor for your model implements its
"dirty" property.

HTH,

Christian


On 2014-02-22 12:33:20 +0000, Roger Gilliar said:

> So far I'm using the following code to check if a model has changed:
>
> EContentAdapter adapter = new EContentAdapter() {
> @Override
> public void notifyChanged(Notification notification) {
> super.notifyChanged(notification);
> eventBroker.post(CommonEvents.TOPIC_MODEL_IS_DIRTY, Boolean.TRUE);
> }
> };
>
> But this is not a real solution. If the users types two character and
> deletes this two characters I would like to get the info that the model
> is not dirty anymore. Is this possible ?
Re: How to check if a model is changed ? [message #1255779 is a reply to message #1253665] Mon, 24 February 2014 20:23 Go to previous messageGo to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
I now agree. It is more a theoretical problem.
Re: How to check if a model is changed ? [message #1256101 is a reply to message #1255779] Tue, 25 February 2014 04:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
A ChangeRecorder is much like a content adapter and it's purpose is to
detect real value changes between the start point and the end point.
But as others have pointed out, in an editor (or anywhere that undo
support is needed), a command stack is very effective.

On 24/02/2014 9:23 PM, Roger Gilliar wrote:
> I now agree. It is more a theoretical problem.
Re: How to check if a model is changed ? [message #1256251 is a reply to message #1256101] Tue, 25 February 2014 08:42 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 25/02/2014 05:58, Ed Merks wrote:
> A ChangeRecorder is much like a content adapter and it's purpose is to
> detect real value changes between the start point and the end point. But
> as others have pointed out, in an editor (or anywhere that undo support
> is needed), a command stack is very effective.

Oh, I thought a changerecorder would not be that clever. I thought it
simply accumulates notifications. You say it computes a "total delta"?
I know there's a whole chapter in the book about it, so maybe I'll look
at it again sometime.
Re: How to check if a model is changed ? [message #1256309 is a reply to message #1256251] Tue, 25 February 2014 09:48 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
Felix,

Yes, the change recorder effectively remembers the original state as
state changes arrive and then at the end effectively compares the final
state to the original state to compute a description of any actual
deltas. So it is not just an event recorder...

On 25/02/2014 9:42 AM, Felix Dorner wrote:
> On 25/02/2014 05:58, Ed Merks wrote:
>> A ChangeRecorder is much like a content adapter and it's purpose is to
>> detect real value changes between the start point and the end point. But
>> as others have pointed out, in an editor (or anywhere that undo support
>> is needed), a command stack is very effective.
>
> Oh, I thought a changerecorder would not be that clever. I thought it
> simply accumulates notifications. You say it computes a "total delta"?
> I know there's a whole chapter in the book about it, so maybe I'll
> look at it again sometime.
>
Previous Topic:[XCORE] How to make feature readonly with xcore
Next Topic:To fragment an EMF model and partially load the model
Goto Forum:
  


Current Time: Sat Dec 14 02:46:15 GMT 2019

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

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

Back to the top