How to leave the UI again?

Hi,

I have the following piece of code:

this.getUI().ifPresent(ui -> ui.access(() -> {
                        this.getModel().setProductGroups(productGroups);

                        if (productGroups.size() > 0) {
                            if (this.getModel().getPg().equals(productGroups.get(0).getPgShort())) {
                                this.productGroupChanged(this.getModel().getPg());
                            } else {
                                this.getModel().setPg(productGroups.get(0).getPgShort());
                            }
                        }
                    }));

As you can see im accessing the ui. I have to do it because im coming from a worker thread which throws an event.
I have a problem now because of this line:

...
this.productGroupChanged(this.getModel().getPg());
...

In this function I throw another event on a worker thread which ofcourse now isnt possible since im on the UI.
How can I leave the ui again after accessing it?

I’m not sure I understand your question. Do you get any exception? What exactly are you trying to achieve?

Hi,

basically im loading a reactive stream which im getting from my backend and im updating my ui depending on the incoming data.
I have to use ui access here otherwise the data would not get set on the component. Currently im using a vaadin-dropdown-menu
to present my data. A big problem I have is that no events are fired from the vaadin-dropdown-menu if I select a value which is
already selected.

This is why I check if the current value is equals the new value and if that is true I throw my own event. But the problem
here again is that Im currently in the ui acces when im doing it and im getting an IllegalStateException (but only if
I explicitly try catch it. If I dont The UI is just not working correctly namore).

<vaadin-dropdown-menu id="productGroups" theme="light" on-value-changed="productGroupChanged">
                <template>
                    <vaadin-list-box>
                        <template is="dom-repeat" items="{{productGroups}}">
                            <vaadin-item label="[[item.pgShort]
]" value="[[item.pgShort]
]">
                                [[item.pg]
]
                            </vaadin-item>
                        </template>
                    </vaadin-list-box>
                </template>
            </vaadin-dropdown-menu>

I would not have this problem if productGroupChanged would get called when I select the same value which is already selected.

Are you able to share a minimal project so I can reproduce the problem?