Java EMF/GMF/Papyrus-Set explicit a ElementImpl-属性代码外
我有一个EMF模型和生成的编辑器。在模型/编辑器中,可以将元素“单位”(U)与“规格”(S)连接起来。现在,如果至少有一个U满足美国的要求,我想为S提供一个专门的CSS样式。但是(据我所知),在纸莎草纸的CSS样式表中无法实现这一点(例如,使用选择器) 出于这个原因,我为S添加了一个额外的属性,称为“Mapped”(当至少有一个U满足S时,应该为true,否则为false)。然后,当添加一个或多个连接时(在handleNotification-方法中),我尝试在代码外设置“Mapped”属性: 恕我直言:Java EMF/GMF/Papyrus-Set explicit a ElementImpl-属性代码外,java,css,eclipse-emf,eclipse-gmf,papyrus,Java,Css,Eclipse Emf,Eclipse Gmf,Papyrus,我有一个EMF模型和生成的编辑器。在模型/编辑器中,可以将元素“单位”(U)与“规格”(S)连接起来。现在,如果至少有一个U满足美国的要求,我想为S提供一个专门的CSS样式。但是(据我所知),在纸莎草纸的CSS样式表中无法实现这一点(例如,使用选择器) 出于这个原因,我为S添加了一个额外的属性,称为“Mapped”(当至少有一个U满足S时,应该为true,否则为false)。然后,当添加一个或多个连接时(在handleNotification-方法中),我尝试在代码外设置“Mapped”属性:
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文件识别“Mapped”属性的更改
非常感谢:)找到了解决我问题的方法: 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();
}
}
public void SpecificationEditPart.handleNotification(通知事件)
{
EObject EObject=(EObject)事件。getNotifier();
SpecificationImpl通知程序=(SpecificationImpl)EOObject;
EList satisfyRelationList=notifier.getIncoming();
int satisfyRelationListSize=satisfyRelationList.size();
TransactionalEditingDomain ted=(TransactionalEditingDomain)AdapterFactoryEditingDomain.getEditingDomainFor(EOObject);
尝试
{
ted.runExclusive(新的Runnable()
{
公开作废运行()
{
Display Display=PlatformUI.getWorkbench().getDisplay();
display.asyncExec(新的Runnable()
{
公开作废运行()
{
执行(新的SetCommand(this.ted,notifier,xxxPackage.Literals.SPECIFICATION__-MAPPED,true));
}
});
}
});
}
捕捉(中断异常e)
{
e、 printStackTrace();
}
}
您确实需要使用事务API在EMF中进行更改。全部的
应使用命令对模型进行更改
“然后我尝试将“Mapped”-属性设置为代码外”。代码之外的内容在哪里?您是如何获取/创建TransactionalEditing域的?在SpecificationEditPart.handleNotification(通知事件)中,我添加了我的帖子中列出的代码…TransactionalEditingDomain ed=(TransactionalEditingDomain)this.getEditingDomain;(此处为SpecificationEditPart实例)这是显而易见的,@Shounbough在问题中提到了他自己!您似乎还可以在run方法中执行org.eclipse.gef.commands.Command,而不会出现任何问题。
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();
}
}