Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem with interaction between list sorting and recording commands
Problem with interaction between list sorting and recording commands [message #1861626] Mon, 23 October 2023 23:54 Go to next message
Louis Detweiler is currently offline Louis DetweilerFriend
Messages: 100
Registered: August 2017
Senior Member
Hello,

We are using EMF in our Eclipse application, and we use recording commands. We are trying to implement the ability of the user to sort some of our backing ELists based on various criteria.

It's mostly working, but we have run into a problem.Say one of the lists is sorted, and a user adds an item into the list (via a recording command) that subsequently gets sorted into a different place in the list. Then, if the user then undoes the recording command, the list becomes corrupted. Then simplest example I can think of to describe the corruption is as follows:

We have a list with [Object1, Object2]. The user adds Object3, which gets some fields set, and then the list is sorted into [Object1, Object3, Object2]. The user undoes the creation command. The resultant list is [Object1, Object3] where Object3 has had all fields set to null.

It seems to me that the recording command removes objects from lists based on the index to which it was added to the list, is this correct? Thus, Object2 is removed from the list as that is where Object3 was originally added to the list, and Object3 has all its fields set to null because it undoes the setting of the fields that happened in the recording command that created Object3 and added it to the list.

I also tried sorting the list in the recording command, and the issue still occurs.

However, if I insert Object3 into the list in the index for which it would be after the sort, everything is fine.

I guess my question is what is the way we should handle this? Are we supposed to compute the sorted location of the object before adding it to the list? Is this a bug with the way the RecordingCommand removes objects that were added to lists in the RecordingCommand? I feel like when the RecordingCommand is undone, the object should be removed from the list regardless of its current index. Why does this still happen when the sorting is done within the RecordingCommand?

Thanks for your time!

Louis Detweiler
Re: Problem with interaction between list sorting and recording commands [message #1861629 is a reply to message #1861626] Tue, 24 October 2023 05:41 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
It's not clear how many commands are involved. The sorting should be done by a command. Every command can only properly be undone if the model is in exactly the state it was in after the command is executed. If you sort in a command then when that command is undone, the list will be ordered as it was originally; as such removing the object from the index at which it was added (and where it was located when the command was executed) will work correctly. The description for the changes to a list are done by org.eclipse.emf.ecore.change.util.ListDifferenceAnalyzer.createListChanges(EList<Object>, EList<?>, EList<ListChange>) and it really compares the original list and the final list. So if you sort a list via a change command it should properly restore the original unsorted list. Even if you do everything via a single change command, it should restore the original content and order...

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Obtaining a permission to quote the EMF book in Ecore documentation
Next Topic:Models partially loaded with jUnit
Goto Forum:
  


Current Time: Wed May 01 23:46:47 GMT 2024

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

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

Back to the top