在数据模型发生更改的情况下自动更新graphiti图 [英] automatic update of graphiti diagrams in case of changes in the datamodel

查看:112
本文介绍了在数据模型发生更改的情况下自动更新graphiti图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EMF数据模型,并用 Graphiti框架表示。
如果数据模型中发生更改,则是否随机调用我的UpdateFeature中的方法 updateNeeded()。因此,我有一个听众。如果发生更改,此侦听器将调用方法 update()。
在方法更新中,我可以定义数据模型和图之间的差异。但是,如果我想向图中添加或更改任何内容,则会引发异常。

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);

,但例外情况:


!ENTRY org.eclipse.ui 4 0 2013-07-11 13:36:43.886
!MESSAGE未处理的事件循环异常
!STACK 0

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

org.eclipse.swt.SWTException:无法执行可运行(java.lang.IllegalStateException:如果没有写事务就无法修改资源集)

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

引起作者:java.lang.IllegalStateException:如果没有在org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting

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


处的写事务
,就无法修改资源集

问候,朱莉安

Regards, Juliane

推荐答案

在Graphiti中,您需要在EMF事务中执行对图的更改。
您可以通过执行以下代码来做到这一点:

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);
   }
});

希望这会有所帮助

这篇关于在数据模型发生更改的情况下自动更新graphiti图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆