0

我尝试了此处提供的解决方案: 在数据模型发生更改时自动更新石墨图

我正在尝试在实现 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)
4

1 回答 1

0

尝试使用 DiagramBehavior 执行该功能

getDiagramBehavior().executeFeature(feature, context);
于 2015-08-24T09:44:39.690 回答