Best Practice for building and pasting data structures [message #686050] |
Tue, 21 June 2011 14:02 |
|
Hello,
I often have to attach larger data structures to my model. Of course I do this with a command. However, I used to build up the data structures "by hand". Once the data structure is complete, I can attach it with a command, e.g.
Item item = factory.createItem();
Color color = factory.createColor();
item.setColor(color);
Command cmd = SetCommand.create(editingDomain, cart, ItemPackage.Literals.CART__THE_ITEM, item);
editingDomain.getCommandStack().execute(cmd);
The problem: The model will never be notified when the color on the item is set. But I may very well be interested in that notification.
I stopped doing this. Instead, I use a number of commands and pack them into a CompoundCommand.
Question one: Is this the recommended approach, or is there an even better one?
Unfortunately, I encounter a similar situation where this approach doesn't work: Copy and Paste. When I paste a structure, notifications are only generated for the root element that is pasted, not for all the children hanging on it. Do I have to explicitly build a visitor and let it run over the structure?
There is one scenario that I am sure others have encountered: If I paste objects that have IDs multiple times, I end up with non-unique IDs. So I have to inspect all children of a node upon paste. Upon encountering conflicts, I have to create new IDs. What's the best approach to this situation? I solved it with a visitor that runs upon paste, but it has a clunky feel to it.
Thanks,
- Michael
|
|
|
|
Powered by
FUDForum. Page generated in 0.03844 seconds