Question

I have an EMF-model and the generated editor. In the model/editor, it is possible to connect Element "Unit"(U) with "Specification"(S). Now, I want to have a specialized CSS-style for S if at least one U satisfies S. But (to the best of my knowledge) there is no way to accomplish this (with Selectors, for example) in a CSS-Stylesheet for Papyrus.

For this reason, I added an additional Property for S, called "Mapped" (should be true, when at least one U satisfies S, otherwise it is false). Then, I tried to set the "Mapped"-Property out of code, when one / more connections were added (in the handleNotification - Method):

notifier.setMapped(true);

with excception:

IllegalstateException: Cannot modify resource set without a write transaction

The second solution resulted in another Exception, but with the same semantical result:

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

with exception:

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 aim is that the CSS-File recognizes the change of the "Mapped"-Property.

Thanks a lot :)

Was it helpful?

Solution

Found the solution for my problem:

The bassword seems to be asynchronous...

To change successfully properties of EObjects following i had to do:

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

OTHER TIPS

You do need to use transactions API to make changes in a EMF. All changes made to the model should be done using commands.

Have a look at the API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top