【问题标题】:automatic update of graphiti diagrams in case of changes in the datamodel在数据模型发生变化的情况下自动更新涂鸦图
【发布时间】:2013-07-25 17:06:08
【问题描述】:

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

有人知道如何自动更新图表吗?

这是我在监听器中的示例代码:

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 未处理的事件循环异常 !堆栈 0

org.eclipse.swt.SWTException: 无法执行 runnable (java.lang.IllegalStateException: Cannot modify resource set without a write transaction)

原因:java.lang.IllegalStateException:没有写入事务就无法修改资源集 在 org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting

问候,朱莉安

【问题讨论】:

    标签: eclipse-rcp graphiti


    【解决方案1】:

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

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2015-08-11
      • 1970-01-01
      • 2023-03-27
      • 2015-05-02
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      相关资源
      最近更新 更多