【发布时间】:2013-08-22 03:01:07
【问题描述】:
我尝试了此处提供的解决方案: automatic update of graphiti diagrams in case of changes in the datamodel
我正在尝试在实现 AbstractUpdateFeature 的类的 UpdateNeeded 函数中调用 Upadate 功能:
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);
}});
在更新函数中,我试图更改象形图元素的文本字段的值:
// Set name in pictogram model
if (pictogramElement instanceof ContainerShape) {
ContainerShape cs = (ContainerShape) pictogramElement;
for (Shape shape : cs.getChildren()) {
if (shape.getGraphicsAlgorithm() instanceof Text) {
Text text = (Text) shape.getGraphicsAlgorithm();
text.setValue("aaa");
return true;
}
}
}
但我得到了例外:
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
【问题讨论】:
-
什么异常?显示您的代码和错误。我们不是千里眼。
-
@JanDoggen 我已经用所需信息修改了我的问题。