automatic update of graphiti diagrams in case of changes in the datamodel

♀尐吖头ヾ 提交于 2019-12-23 03:19:10

问题


I have an EMF Datamodel and represent it with the framework "Graphiti". In case of changes in the datamodel the method "updateNeeded()" in my UpdateFeature is randomly called or not. Therefor I have a listener. This listener calls the method "update()" in case of changes. In the method update I can define the differences between datamodel and diagram. But if I want to add or change anything to the diagram an exception is thrown.

Has anyone an idea how I could autoupdate the diagram?

Here is my examplecode in the listener:

UpdateContext updateContext = new UpdateContext(getDiagram().getChildren().get(0).getGraphicsAlgorithm().getPictogramElement());
IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(updateContext);
updateFeature.update(updateContext);

and the exception:

!ENTRY org.eclipse.ui 4 0 2013-07-11 13:36:43.886 !MESSAGE Unhandled event loop exception !STACK 0

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.IllegalStateException: Cannot modify resource set without a write transaction)

Caused by: java.lang.IllegalStateException: Cannot modify resource set without a write transaction at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting

Regards, Juliane


回答1:


In Graphiti you need to execute changes to diagram within an EMF transaction. You can do that by executing your code as follows:

TransactionalEditingDomain domain = TransactionUtils.getEditingDomain(diagram);
domain.getCommandStack().execute(new RecordingCommand(domain) {
   public void doExecute() {
      UpdateContext updateContext = new UpdateContext(getDiagram().getChildren().get(0).getGraphicsAlgorithm().getPictogramElement());
      IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(updateContext);
      updateFeature.update(updateContext);
   }
});

Hope this helps



来源:https://stackoverflow.com/questions/17592810/automatic-update-of-graphiti-diagrams-in-case-of-changes-in-the-datamodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!