Hello community!
I have made an emf model and sirius diagram which I try to update programatically using a Recording Command. From what i have read this is the proper way of doing so. The rootObject of my model is an Analysis which has a name, an analyzer and some analysis params which are classes of my own defined in the emf model.
I have an xml file and when i save it an emf model instance is created programmatically. So I get the root element of my newly created model instance (updatedRootObject) and then I use a Recording Command to update the diagram like this:
String airdFilePath = "/my/aird/path";
URI airdFileURI = URI.createPlatformResourceURI(airdFilePath, true);
Session session = SessionManager.INSTANCE.getSession( airdFileURI, monitor);
session.open();
//get session root object
Analysis rootObj = (Analysis) session.getSemanticResources().
iterator().next().getContents().get(0);
//update root object
TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
CommandStack commandStack = editingDomain.getCommandStack();
RecordingCommand updateCommand = new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
rootObj.setName(updatedRootObject.getName());
rootObj.setAnalyzer(updatedRootObject.getAnalyzer());
rootObj.getAnalysisParams.clear();
rootObj.getAnalysisParams.AddAll(updatedRootObject.getAnalysisParams);
}
};
commandStack.execute(updateCommand);
The semantic model gets updated BUT if my diagram is opened, my nodes overlap each other and I get the following exception.
java.lang.NullPointerException
at org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand$1.run(DeferredLayoutCommand.java:153)
at org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil.synchronizeRunnableToMainThread(EditPartUtil.java:111)
at org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand.doExecuteWithResult(DeferredLayoutCommand.java:186)
at org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand.doExecute(AbstractTransactionalCommand.java:247)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
at org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy.execute(ICommandProxy.java:68)
at org.eclipse.gef.commands.CompoundCommand.execute(CompoundCommand.java:111)
at org.eclipse.sirius.diagram.ui.internal.refresh.layout.SiriusCanonicalLayoutCommand.executeLayoutDueToExternalChanges(SiriusCanonicalLayoutCommand.java:107)
at org.eclipse.sirius.diagram.ui.internal.refresh.layout.SiriusCanonicalLayoutCommand.access$3(SiriusCanonicalLayoutCommand.java:104)
at org.eclipse.sirius.diagram.ui.internal.refresh.layout.SiriusCanonicalLayoutCommand$1.run(SiriusCanonicalLayoutCommand.java:90)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
... 24 more
Thank you in advance.
[Updated on: Mon, 23 November 2015 15:44]
Report message to a moderator