我尝试了这里提供的解决方案: automatic update of graphiti diagrams in case of changes in the datamodel
我试图在我的类的UpdateNeeded函数中调用Upadate功能来实现AbstractUpdateFeature:
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)
答案 0 :(得分:0)
尝试使用DiagramBehavior
执行该功能getDiagramBehavior().executeFeature(feature, context);