Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Rollback to a previous state of the model
Rollback to a previous state of the model [message #1792391] Mon, 16 July 2018 20:39 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 197
Registered: February 2014
Senior Member
Hello,

[I have already asked this question on XText forum but didn't get the answer I wanted, so I thought maybe someone here could help]. I was wondering if there is a way to get a snapshot of the model at some point and then revert back everything to it. I can't use RecordingCommand for some reasons. So, basically, I need to do:
1- keeping the snapshot in the memory,
2- do sth with the model and modify it.
3- if the modification is not what I wanted, then revert everything back to the snapshot that is taken in the step 1.

I tried to create an element (i.e. snapshot resource) in the memory and use ecoreutils.copy to copy everything from the original resource to the snapshot resource. But the copy back from the snapshot to the original resource does not seem to work :(

Any help would be appreciated.

Thanks,
Parsa

[Updated on: Tue, 17 July 2018 14:49]

Report message to a moderator

Re: Rollback to a previous state of the model [message #1792488 is a reply to message #1792391] Wed, 18 July 2018 15:13 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 452
Registered: July 2009
Senior Member
EMF Transaction handles all of this so you do not have to. Sirius uses EMF Transaction to manager all model changes made in the context of a Sirius session.

What you need in your case is to register a org.eclipse.emf.transaction.ResourceSetListener configured as a pre-commit listener on the session's TransactionalEditingDomain, and override the transactionAboutToCommit(ResourceSetChangeEvent). That method will get called when a model change is about to be commited, and you can throw a org.eclipse.emf.transaction.RollbackException to indicate to EMF Transaction that something is wrong with the change and it should be rolled back.


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Rollback to a previous state of the model [message #1792500 is a reply to message #1792488] Wed, 18 July 2018 18:00 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 197
Registered: February 2014
Senior Member
Hi Pierre-Charles,

Thanks for your reply. You are right but the thing is that I don't want to use RollbackException. Because there is not a single change that I roll back. I will show a dialog to the user where the user can do whatever he wants to do with the model and all these changes are within their own recording command. Then he can either accept or cancel the changes. By default, the Accept will do nothing because the changes that he made in the dialog are already saved to the original model at the time of the change. But if he selects the Cancel button, I need to revert back to the time before he opens the dialog.

So, can I use ecoreutil.copy and have the model root in a variable in the memory , and then paste back in case of cancel button?

Bests,
Parsa

Re: Rollback to a previous state of the model [message #1792529 is a reply to message #1792500] Thu, 19 July 2018 07:35 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 452
Registered: July 2009
Senior Member
Probably doable, but not easy if you want to handle the general cases. This is really not a Sirius-related question however, it should go in a more general EMF forum.

Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Rollback to a previous state of the model [message #1792570 is a reply to message #1792529] Thu, 19 July 2018 15:07 Go to previous message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 197
Registered: February 2014
Senior Member
You're right Pierre-Charles, I'll ask it on EMF forum to see if they have a good solution to it.

Thanks,
Parsa
Previous Topic:Sphinx example not able to run
Next Topic:Nested grid of boxes
Goto Forum:
  


Current Time: Tue Nov 20 06:00:10 GMT 2018

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

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

Back to the top