Skip to main content



      Home
Home » Modeling » EMF » Invalid thread access while updating UI
Invalid thread access while updating UI [message #1736432] Wed, 29 June 2016 08:05 Go to next message
Eclipse UserFriend
In order to update UI after changes which were perfomed in model, I've implemented listener in my custom ItemProvider.
I've used this tutorial:
http://eclipsesource.com/blogs/2013/01/29/emf-itemprovider-magic/
To make everything work properly, I had to set setFireLabelUpdateNotifications(true) in my LabelProvider, which is a child of an AdapterFactoryLabelProvider. It seems like it works fine, by is this ok to do it, or maybe there are other ways to fire my listener?

After setting setFireLabelUpdateNotifications(true) in some cases I get "invalid thread access" SWTException. It happens, when notifications are fired from another thread (from a job in my case). Obviously, I have to run my code in UI thread, so I have to place Display.asyncExec(...) somewhere... Where should I place it?
If I place it in my ModelItemProviderAdapterFactory, in fireNotifyChanged(final Notification notification) method it solves the issue, but it seems to me like there has to be better solution.
If someone encountered this issue, could you please share your thoughts on the solution?

Thanks in advance.

[Updated on: Wed, 29 June 2016 08:17] by Moderator

Re: Invalid thread access while updating UI [message #1736439 is a reply to message #1736432] Wed, 29 June 2016 08:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

do you use databinding for updating the UI?
What are the cases in which you get the invalid thread Exceptions?

Best regards

Jonas


On 29.06.2016 14:05, Oleksiy Bulhakov wrote:
> 1) In order to update UI after changes which were perfomed in model,
> I've implemented listener in my custom ItemProvider.
> I've used this tutorial:
> http://eclipsesource.com/blogs/2013/01/29/emf-itemprovider-magic/
> And to make everything work properly, I had to set
> setFireLabelUpdateNotifications(true); in my LabelProvider, which is a
> child of an AdapterFactoryLabelProvider. It seems like it works fine, by
> is this ok to do it, or maybe there are other ways to fire my listener?
>
> 2) After setting setFireLabelUpdateNotifications(true); in some cases I
> get "invalid thread access" SWTException. It happens, when notifications
> are fired from another thread (from a job in my case). Obviously, I have
> to run my code in UI thread, so I have to place Display.asyncExec(...)
> somewhere... Where should I place it?
> If I place it in my ModelItemProviderAdapterFactory, in
> fireNotifyChanged(final Notification notification) method it solves the
> issue, but it seems to me like there has to be better solution.
> If someone encountered this issue, could you please share your thoughts
> on the solution?
>
> Thanks in advance.
Re: Invalid thread access while updating UI [message #1736440 is a reply to message #1736432] Wed, 29 June 2016 08:22 Go to previous messageGo to next message
Eclipse UserFriend
In generated editors normally notifications are wrapped and this
threading problem is handled by
org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider.notifyChanged(Notification).


On 29.06.2016 08:05, Oleksiy Bulhakov wrote:
> 1) In order to update UI after changes which were perfomed in model,
> I've implemented listener in my custom ItemProvider.
> I've used this tutorial:
> http://eclipsesource.com/blogs/2013/01/29/emf-itemprovider-magic/
> And to make everything work properly, I had to set
> setFireLabelUpdateNotifications(true); in my LabelProvider, which is a
> child of an AdapterFactoryLabelProvider. It seems like it works fine,
> by is this ok to do it, or maybe there are other ways to fire my
> listener?
>
> 2) After setting setFireLabelUpdateNotifications(true); in some cases
> I get "invalid thread access" SWTException. It happens, when
> notifications are fired from another thread (from a job in my case).
> Obviously, I have to run my code in UI thread, so I have to place
> Display.asyncExec(...) somewhere... Where should I place it?
> If I place it in my ModelItemProviderAdapterFactory, in
> fireNotifyChanged(final Notification notification) method it solves
> the issue, but it seems to me like there has to be better solution.
> If someone encountered this issue, could you please share your
> thoughts on the solution?
>
> Thanks in advance.
Re: Invalid thread access while updating UI [message #1736462 is a reply to message #1736440] Wed, 29 June 2016 10:21 Go to previous messageGo to next message
Eclipse UserFriend
My application uses databinding, as far as I understand it.
The simplest case I have - my undo operation is wrapped into a job. So if I invoke my undo operation, I get these Invalid Thread Access exceptions.

My problem occurs in LabelProvider, because it does not handle threading problem. Maybe I should implement my Display.asyncExec(...) in my LabelProvider notifyChanged(...) method?

My LabelProvider is used by the CommandViewer. When I try to modify the model from the job, and notifications are fired, they eventually reach my viewer, and since job is being performed in separate thread, I get those exceptions.
Re: Invalid thread access while updating UI [message #1736466 is a reply to message #1736462] Wed, 29 June 2016 10:49 Go to previous messageGo to next message
Eclipse UserFriend
Yes, I would add logic at the central point where the notifications
arrive and are used to update the viewer, i.e., the label provider.


On 29.06.2016 10:21, Oleksiy Bulhakov wrote:
> My application uses databinding, as far as I understand it.
> The simplest case I have - my undo operation is wrapped into a job. So
> if I invoke my undo operation, I get these Invalid Thread Access
> exceptions.
> My problem occurs in LabelProvider, because it does not handle
> threading problem. Maybe I should implement my Display.asyncExec(...)
> in my LabelProvider notifyChanged(...) method?
>
> My LabelProvider is used by the CommandViewer. When I try to modify
> the model from the job, and notifications are fired, they eventually
> reach my viewer, and since job is being performed in separate thread,
> I get those exceptions.
>
Re: Invalid thread access while updating UI [message #1736602 is a reply to message #1736466] Thu, 30 June 2016 10:21 Go to previous message
Eclipse UserFriend
Thank you, it seems like it is the best solution I can have now.
Previous Topic:[Xcore] Invariant code referencing XXXValidator constants
Next Topic:Delete
Goto Forum:
  


Current Time: Mon Jul 14 22:45:44 EDT 2025

Powered by FUDForum. Page generated in 0.05555 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top