2013-07-11 34 views
1

我有一個EMF數據模型並用框架「Graphiti」表示它。 如果數據模型發生變化,我的UpdateFeature中的方法「updateNeeded()」會隨機調用或不調用。因此,我有一個聽衆。此偵聽器在發生更改時調用方法「update()」。 在方法更新中,我可以定義數據模型和圖之間的區別。但是,如果我想添加或更改任何東西到圖中,就會拋出異常。在數據模型發生變化時自動更新圖形圖表

有沒有人有一個想法,我可以自動更新圖表?

這是我在聽衆examplecode:

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年7月11日13:36:43.886 ! MESSAGE未處理的事件循環異常 !堆棧0

org.eclipse.swt.SWTException:無法執行runnable(java.lang.IllegalStateException:無法修改資源集而沒有寫transacti上)

致:java.lang.IllegalStateException:在org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting不能修改資源集合,而不寫事務

問候,朱莉安

回答

2

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

希望這有助於

相關問題