Cross-reference between several models [message #819159] |
Mon, 12 March 2012 11:18  |
Eclipse User |
|
|
|
Hi,
I want to use TransactionalEditingDomain to synchronize several models between them, in order to separate a "business model" (only the usefull information I want to keep) and a "notation model" (e.g. the coordinates of each object) for example (like in GMF).
I want something like this :
Business Model:
<?xml version="1.0" encoding="ASCII"?>
<test:TestModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://test/1.0">
<square name="squareA"/>
<circle name="circleA"/>
</test:TestModel>
Notation Model:
<?xml version="1.0" encoding="ASCII"?>
<notation:NotationModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://notation/1.0">
<notation href="referenceToSquareA" x="40" y="20" />
<notation href="referenceToCircleA" x="100" y="10" />
</test:TestModel>
For this, I tried to use the absolute URI of each EObject as identifier for the href attribute. I extended ResourceSetListenerImpl to listen to modifications inside my business model and modify my other models like this :
MyListener:
public class MyListener extends ResourceSetListenerImpl {
public Command transactionAboutToCommit(ResourceSetChangeEvent event)
throws RollbackException {
List notifications = event.getNotifications();
for (Iterator i = notifications.iterator(); i.hasNext();) {
Notification n = (Notification)i.next();
if (n.getEventType() == Notification.SET && n.getNotifier() instanceof Square) {
Square notifier = (Square) n.getNotifier();
System.out.println (EcoreUtil.getURI(notifier));
// Modification of the notation model
}
}
}
Problems appear when :
- I delete an EObject inside my business model:
transactionAboutToCommit:
...
if (n.getEventType() == Notification.REMOVE && n.getOldValue() instanceof Square) {
Square notifier = (Square) n.getNotifier();
System.out.println (EcoreUtil.getURI(notifier)); // print "#//"
}
...
- I add an EObject in a collection of EObject:
Modifiying my business model:
editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
protected void doExecute() {
TestModel model = (TestModel)resource.getContents().get(0);
Square square = SquareFactory.eINSTANCE.createSquare();
model.getSquare().add(2,square); // I add square in third position, what about the URI of the fourth and the fifth square ?
}
});
I found some topics about the problem of synchronizing several models but no implementation which do this.
Does anybody have an idea to achieve this ?
Best regards,
--
Nicolas
|
|
|
|
Re: Cross-reference between several models [message #820012 is a reply to message #819183] |
Tue, 13 March 2012 12:12  |
Eclipse User |
|
|
|
Hi Ed,
Thank you for your remark. I wasn't interested in the EcoreUtil's capabilities. I'm rereading the part about splitting model into multiple packages from the EMF book. I realize that I wasn't on the right track.
Thank you again,
Regards,
--
Nicolas
|
|
|
Powered by
FUDForum. Page generated in 0.06446 seconds