EMF / GMF / Papyrus - Set ElementImpl to Exclude - Property Out of Code

I have an EMF model and a generated editor. In the model / editor, you can connect the "Unit" (U) element with the "Specification" (S). Now I want to have a special CSS style for S if at least one U satisfies S. But (as far as I know) there is no way to do this (for example, with selectors) in the CSS style for Papyrus.

For this reason, I added an additional property for S called "Mapped" (it must be true when at least one U satisfies S, otherwise it is false). Then I tried to get the "Mapped" -Property out of the code when another connection was added (in the handleNotification method - Method):

notifier.setMapped(true);

with deletion:

IllegalstateException: Cannot modify resource set without a write transaction

The second solution led to another Exception, but with the same semantic result:

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

with the exception of:

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

Does anyone know how to handle these Exceptions or have a good workaround? The main goal is that the CSS file recognizes the “Mapped” -Property change.

Many thanks:)

+4
source share
2 answers

Found a solution for my problem:

It seems that the maze is asynchronous ...

To successfully change the properties EObjectsfollowing me:

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();
    }
}
+3
source

You need to use the transaction API to make changes to EMF. All changes made to the model must be performed using commands.

Look at the API

-1
source

All Articles