1

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

julianemue
  • 41
  • 1
  • 6

1 Answers1

2

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

david
  • 804
  • 7
  • 21