Setting an ElementImpl property explicitly in EMF/GMF/Papyrus outside of the code

I am working with an EMF-model and its generated editor. In this model/editor, there is a connection between Element "Unit"(U) and "Specification"(S). My goal is to have a specific CSS style for S if at least one U satisfies S. Unfortunately, I have not found a way to achieve this using Selectors in a CSS Stylesheet for Papyrus.

To address this issue, I added a new Property for S called "Mapped" (which should be true when at least one U satisfies S, otherwise false). I attempted to set the "Mapped" property programmatically when connections were added like so:

notifier.setMapped(true);

However, I encountered an error:

IllegalstateException: Cannot modify resource set without a write transaction

An alternative approach resulted in a different Exception but had the same outcome:

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

This also led to an exception:

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

If anyone has insights on how to handle these Exceptions or has a clever workaround, I would greatly appreciate it. The ultimate objective is for the CSS file to detect changes in the "Mapped" property.

Thank you :)

Answer №1

Successfully resolved my issue:

The password appears to be asynchronous...

In order to effectively modify properties of EObjects, I had to implement the following changes:

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

Answer №2

In order to modify an EMF, it is necessary to utilize the transactions API and execute changes using commands.

For more information on the API, check out this link: API Reference

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The button with the class ".navbar-toggler" in Bootstrap 4 is not designed to float to the right

I've been trying to use Bootstrap 4, but no matter what I do, I can't seem to get the .navbar-toggler button to align to the right. It feels like I'm missing something simple, but I just can't figure out what's going wrong. Check ...

Avoiding the need to await driver().manage().timeOut()

Could you provide guidance on a situation I am facing while waiting for an element in a particular test case? In one of my tests, I am verifying the accuracy of the phone number on the dialer that opens after clicking a button in our application. The chall ...

Is there a way to navigate through div text within a stationary container?

My current challenge involves a container that contains an overflow of text, but I desire for the container to remain fixed. The dilemma arises when the text spills out from both the top and bottom edges of the container. Instead of using scroll bars withi ...

What is the best way to maintain a div centered when the browser window shrinks smaller than the div's dimensions?

Is there a way to keep a div centered and create white space around it when the browser window is resized? I want this effect to happen whether the browser window gets larger or smaller. Currently, when the window size decreases, the left side of the div l ...

What is the syntax for indenting text inside an inline-block element?

Essentially, the checkboxes displayed here are in a graphical format to avoid using checkbox elements for accessibility reasons (only the link should be interactive). However, aligning a span next to an href and indenting the text to line up with the star ...

What prevents me from finding the square root of a "lengthy" value? (novice coder)

I recently ventured into the realm of Java, having only started my journey two days ago. Utilizing Java SE and Netbeans 8.0.2, I have managed to create a few very basic applications. However, my current challenge involves attempting to calculate the squ ...

Regex: Identifying all URLs except for those with ".js" or ".css" included

I am currently working on a project where I need to change all the links in an HTML page so that they are not clickable. However, I am having trouble finding the right Regex pattern for the following condition: href="Any_URL" except for those that contain ...

When conducting Repository Tests with DataJpaTest using MySQL, Hibernate fails to automatically increment the User in an H2 database

I have been encountering an issue while testing my Spring Boot repositories with DataJpaTest. I am using MySQL and have set IDENTITY for id generation in all my models: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; ...

I have a question for you: How can I customize the font size in Material-UI TextField for different screen sizes?

I'm facing a challenge in Material-UI where I need to set different font sizes for TextField. While it may be simple in HTML/CSS, it's proving to be tricky in Material-UI. Can anyone help me figure out how to achieve this? The code snippet below ...

Positioning of the footer using CSS: A query

What is the best way to position a footer if we know its height? For instance, if the height of the footer is 100px: footer { position:absolute; bottom: 100px; background: red; } If this approach is not recommended, could someone assist m ...

What is the Most Effective Method for Implementing a Unique Font-Family without Sacrificing Loading Speed

I have recently incorporated my own unique font to my website and utilized the code below to specify a custom font-family. Unfortunately, I've encountered an issue where the custom font initially displays as a standard web font while the page is loadi ...

What steps do I need to take in order to incorporate a new language into my

I am trying to view my project in Persian language in the preview tab of Android Studio for XML files. However, I am unsure of how to add Persian as a language option, as only English is available by default. Can anyone provide guidance on adding Persian ...

Determine the dynamic height of content in a TypeScript file

Could you please provide guidance on obtaining the height of the content within this particular div element? For example, I need to calculate the dynamic height of the content. https://i.sstatic.net/2kNk3.png code .html <div class="margin-top-4 ...

Is it possible to measure the pitch angle using an Android app during the camera snapshot?

I am currently working on an Android Studio application using Java. One of the features I want to include is the ability to take a picture with the camera. Is there any method to determine the pitch angle of the phone at the exact moment the image is cap ...

Consistently receiving codes 6a82 and 6d00 when attempting to read a Visa EMV card

When reading data from a Visa card, I consistently receive response codes 6a82 and 6d00 for PSE. Below are the commands I am using with smartcardio: Select PSE: 00A404000E315041592E5359532E444446303100 Processing code: 80A8000002830000 The following cod ...

What is the best way to access and extract both the key and value objects in a Java Map using Jackson annotations?

I've been encountering a problem with serialization. I have a class called PickupDate with a LocalDate property and I want to serialize a Map<PickupDate, Integer> object to: { "2020-07-17": 1 } But instead, it's currently serializing to: ...

Failure of Highchart's resizing mechanism when hidden

Check out this AngularJS demo app featuring Highcharts: http://jsfiddle.net/dennismadsen/dpw8b8vv/1/ <div ng-app="myapp"> <div ng-controller="myctrl"> <button ng-click="hideView()">1. Hide</button> <button ng ...

The file 'root/res/layout/custom_spinner.xml' is making use of a reserved file or directory name 'res', which is not allowed

Task ':app:packageReleaseBundle' Execution Failed An error occurred during the execution of com.android.build.gradle.internal.tasks.Workers$ActionFacade. The file 'root/res/layout/custom_spinner.xml' is using a reserved file or direct ...

@ManyToMany multiple instances

I am facing an issue with persistence in my code. The Meal class contains a list of Products, and the Product class has a list of Meals defined in a @ManyToMany relation. When I attempt to save the data, the Compiler tries to save every product, resulting ...

Locating and Clicking Elements in Selenium Using Java

I'm currently working with Selenium and Java to automate tasks on a webpage. However, I'm encountering an issue where I can't seem to click on a specific button that is preventing me from moving forward. The HTML code of the button in quest ...