[英]automatic update of graphiti diagrams in case of changes in the datamodel
我有一個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未處理的事件循環異常!STACK 0
org.eclipse.swt.SWTException:無法執行可運行(java.lang.IllegalStateException:如果沒有寫事務就無法修改資源集)
引起原因:java.lang.IllegalStateException:如果沒有在org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting進行寫事務,則無法修改資源集
問候,朱莉安
在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);
}
});
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.