【问题标题】:EMF/GMF/Papyrus - Set excplicit an ElementImpl - Property out of codeEMF/GMF/Papyrus - 设置显式和 ElementImpl - 代码外属性
【发布时间】:2013-10-08 10:02:43
【问题描述】:

我有一个 EMF 模型和生成的编辑器。在模型/编辑器中,可以将元素“Unit”(U) 与“Specification”(S) 连接起来。现在,如果至少有一个 U 满足 S,我想为 S 提供一种专门的 CSS 样式。但是(据我所知)没有办法在 CSS 样式表中实现这一点(例如,使用选择器)纸莎草纸。

为此,我为 S 添加了一个额外的属性,称为“映射”(当至少有一个 U 满足 S 时应该为真,否则为假)。然后,当添加一个/多个连接时(在handleNotification - 方法中),我尝试在代码中设置“映射”属性:

notifier.setMapped(true);

有例外:

IllegalstateException: Cannot modify resource set without a write transaction

第二种解决方案导致另一个异常,但语义结果相同:

ed.getCommandStack().execute(SetCommand.create(ed, notifier,
    xyzPackage.Literals.SPECIFICATION__MAPPED, true));

例外:

java.lang.IllegalStateException: Cannot activate read/write 
    transaction in read-only transaction context

有谁知道如何处理这些异常或有一个好的解决方法?主要目的是 CSS 文件识别“映射”属性的变化。

非常感谢:)

【问题讨论】:

  • “然后我尝试将“映射”属性设置为代码”。哪里出了代码?您如何获取/创建事务性编辑域?
  • 在 SpecificationEditPart.handleNotification(Notification event) 我添加了我的帖子中列出的代码...TransactionalEditingDomain ed = (TransactionalEditingDomain)this.getEditingDomain; (其中这个 instanceof SpecificationEditPart)

标签: java css eclipse-emf eclipse-gmf papyrus


【解决方案1】:

找到解决我的问题的方法:

bassword 好像是异步的……

要成功更改EObjects 的属性,我必须这样做:

public void SpecificationEditPart.handleNotification(Notification event)
{

    EObject eObject = (EObject)event.getNotifier();

    SpecificationImpl notifier = (SpecificationImpl)eObject;

    EList<Satisfy> satisfyRelationList = notifier.getIncoming();

    int satisfyRelationListSize = satisfyRelationList.size();

    TransactionalEditingDomain ted = (TransactionalEditingDomain)AdapterFactoryEditingDomain.getEditingDomainFor(eObject);

    try
    {
        ted.runExclusive(new Runnable()
        {
            public void run ()
            {
                Display display = PlatformUI.getWorkbench().getDisplay();
                display.asyncExec(new Runnable()
                {
                    public void run ()
                    {
                        ted.getCommandStack().execute(new SetCommand(this.ted, notifier, xxxPackage.Literals.SPECIFICATION__MAPPED, true));
                    }
                });
            }
        });
    }
    catch (InterruptedException e)
    {
        e.printStackTrace();
    }
}

【讨论】:

  • 看来你也可以在run方法中执行一个org.eclipse.gef.commands.Command没有任何问题。
【解决方案2】:

您确实需要使用事务 API 在 EMF 中进行更改。全部 对模型所做的更改应使用命令完成。

Have a look at the API

【讨论】:

  • 这很明显,@Shounbourgh 在问题中提到了自己!
猜你喜欢
  • 2016-06-15
  • 1970-01-01
  • 2012-09-30
  • 1970-01-01
  • 2010-11-03
  • 1970-01-01
  • 2011-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多