Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » None-UI thread model updates and Display.getCurrent() returning null.
None-UI thread model updates and Display.getCurrent() returning null. [message #172952] Tue, 22 March 2005 09:31 Go to next message
Steve Jones is currently offline Steve JonesFriend
Messages: 95
Registered: July 2009
Member
Hi,

I have a multi-page editor based on org.eclipse.ui.forms.editor.FormEditor
that has a mix of GEF based pages and source/text pages that use
AbstractTextEditor.

GEF pages update the model and reflect changes as just fine but I'm getting
null pointer exceptions, in GEF, when I update the model from text pages.

All my model updates use background threads that ultimately call
AbstractEditPart.refreshVisuals(). This fails, I think, because
org.eclipse.swt.widgets.Display.getCurrent() returns null when called from
a none-UI thread.

Whats the best way of dealing with this?

Steve.
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173007 is a reply to message #172952] Tue, 22 March 2005 14:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Try Display.getDefault()

"Steve Jones" <steve@istech.demon.co.uk> wrote in message
news:d1otct$2b7$1@news.eclipse.org...
> Hi,
>
> I have a multi-page editor based on org.eclipse.ui.forms.editor.FormEditor
> that has a mix of GEF based pages and source/text pages that use
> AbstractTextEditor.
>
> GEF pages update the model and reflect changes as just fine but I'm
> getting
> null pointer exceptions, in GEF, when I update the model from text pages.
>
> All my model updates use background threads that ultimately call
> AbstractEditPart.refreshVisuals(). This fails, I think, because
> org.eclipse.swt.widgets.Display.getCurrent() returns null when called from
> a none-UI thread.
>
> Whats the best way of dealing with this?
>
> Steve.
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173044 is a reply to message #172952] Tue, 22 March 2005 17:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Steve Jones wrote:
> Hi,
>
> I have a multi-page editor based on org.eclipse.ui.forms.editor.FormEditor
> that has a mix of GEF based pages and source/text pages that use
> AbstractTextEditor.
>
> GEF pages update the model and reflect changes as just fine but I'm getting
> null pointer exceptions, in GEF, when I update the model from text pages.
>
> All my model updates use background threads that ultimately call
> AbstractEditPart.refreshVisuals(). This fails, I think, because
> org.eclipse.swt.widgets.Display.getCurrent() returns null when called from
> a none-UI thread.
>
> Whats the best way of dealing with this?
>
> Steve.

Exactly what I do. In my property listeners I create a runnable to
handle the call to refreshVisuals(). Actually my runnable is a class
member and not a local variable.

I pass my runnable into a display I get by calling

getViewer().getControl().getDisplay();

I use syncExec

CL
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173073 is a reply to message #173044] Tue, 22 March 2005 17:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

CL [dnoyeb] Gilbert wrote:
> Steve Jones wrote:
>
>> Hi,
>>
>> I have a multi-page editor based on
>> org.eclipse.ui.forms.editor.FormEditor
>> that has a mix of GEF based pages and source/text pages that use
>> AbstractTextEditor.
>>
>> GEF pages update the model and reflect changes as just fine but I'm
>> getting
>> null pointer exceptions, in GEF, when I update the model from text pages.
>>
>> All my model updates use background threads that ultimately call
>> AbstractEditPart.refreshVisuals(). This fails, I think, because
>> org.eclipse.swt.widgets.Display.getCurrent() returns null when called
>> from
>> a none-UI thread.
>>
>> Whats the best way of dealing with this?
>> Steve.
>
>
> Exactly what I do. In my property listeners I create a runnable to
> handle the call to refreshVisuals(). Actually my runnable is a class
> member and not a local variable.
>
> I pass my runnable into a display I get by calling
>
> getViewer().getControl().getDisplay();
>
> I use syncExec
>
> CL

Do you have an example of this? I'm curious by what you mean.

Cheers,

~ Chris
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173113 is a reply to message #173044] Tue, 22 March 2005 20:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

> Exactly what I do. In my property listeners I create a runnable to handle
> the call to refreshVisuals(). Actually my runnable is a class member and
> not a local variable.
>
> I pass my runnable into a display I get by calling
>
> getViewer().getControl().getDisplay();
>
> I use syncExec
>
> CL

Anytime you do something like that you should catch any NPEs. It is
possible that the editor gets closed, or the editpart is removed from the
viewer, etc. after the background event has been dispatched but before your
code runs.
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173130 is a reply to message #173113] Tue, 22 March 2005 21:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Randy Hudson wrote:
>>Exactly what I do. In my property listeners I create a runnable to handle
>>the call to refreshVisuals(). Actually my runnable is a class member and
>>not a local variable.
>>
>>I pass my runnable into a display I get by calling
>>
>>getViewer().getControl().getDisplay();
>>
>>I use syncExec
>>
>>CL
>
>
> Anytime you do something like that you should catch any NPEs. It is
> possible that the editor gets closed, or the editpart is removed from the
> viewer, etc. after the background event has been dispatched but before your
> code runs.
>
>

Ahh, good thing I use syncExec then right? Closing the editor requires
the GUI thread IIRC, so syncExec should ensure my job is performed first?

Bah, but so I dont have to fight through all the possibilities ill catch
the NPE. Thanks for the tip.


CL
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173145 is a reply to message #173073] Tue, 22 March 2005 21:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Chris Aniszczyk wrote:
> CL [dnoyeb] Gilbert wrote:
>
>> Steve Jones wrote:
>>
>>> Hi,
>>>
>>> I have a multi-page editor based on
>>> org.eclipse.ui.forms.editor.FormEditor
>>> that has a mix of GEF based pages and source/text pages that use
>>> AbstractTextEditor.
>>>
>>> GEF pages update the model and reflect changes as just fine but I'm
>>> getting
>>> null pointer exceptions, in GEF, when I update the model from text
>>> pages.
>>>
>>> All my model updates use background threads that ultimately call
>>> AbstractEditPart.refreshVisuals(). This fails, I think, because
>>> org.eclipse.swt.widgets.Display.getCurrent() returns null when called
>>> from
>>> a none-UI thread.
>>>
>>> Whats the best way of dealing with this?
>>> Steve.
>>
>>
>>
>> Exactly what I do. In my property listeners I create a runnable to
>> handle the call to refreshVisuals(). Actually my runnable is a class
>> member and not a local variable.
>>
>> I pass my runnable into a display I get by calling
>>
>> getViewer().getControl().getDisplay();
>>
>> I use syncExec
>>
>> CL
>
>
> Do you have an example of this? I'm curious by what you mean.
>
> Cheers,
>
> ~ Chris


class EditPart{

public final Runnable refresher = new Runnable () {
public void run() {
refreshVisuals();
}
}



public void propertyEvent(EventObject o){
if(o.getType().equals(ModelEvents.PROP_NAME)){
Display d = getViewer().getControl().getDisplay();
d.syncExec(refresher);
}
}
}




CL
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173312 is a reply to message #173130] Wed, 23 March 2005 19:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

It's too late, syncExec doesn't help you. Between the model change and your
listener being notified, the viewer may have been disposed.

Can it hurt? Using syncExec() is one of the common causes of deadlock. Of
course it depends on the type of notification.
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173342 is a reply to message #173312] Wed, 23 March 2005 20:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Randy Hudson wrote:
> It's too late, syncExec doesn't help you. Between the model change and your
> listener being notified, the viewer may have been disposed.
>
> Can it hurt? Using syncExec() is one of the common causes of deadlock. Of
> course it depends on the type of notification.
>
>

It takes a real man to use syncExec! :P

I see your point about it being too late though. The model change is
occurying outside of the GUI thread, so you really have no idea when
this time is, also my model is in a database, it could take 5 minutes to
update, then fire the event afterwards...


CL
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173350 is a reply to message #173312] Wed, 23 March 2005 21:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Randy Hudson wrote:
> It's too late, syncExec doesn't help you. Between the model change and your
> listener being notified, the viewer may have been disposed.
>


Since I am in the UI thread at this point, can I check something on the
UI to know if the viewer has been disposed, as opposed to just catching
the fallout?


CL
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173357 is a reply to message #173350] Wed, 23 March 2005 21:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

CL [dnoyeb] Gilbert wrote:
> Randy Hudson wrote:
>
>> It's too late, syncExec doesn't help you. Between the model change
>> and your listener being notified, the viewer may have been disposed.
>>
>
>
> Since I am in the UI thread at this point, can I check something on the
> UI to know if the viewer has been disposed, as opposed to just catching
> the fallout?
>
>
> CL

2nd question is, will this even work with a disposed viewer

getViewer().getControl().getDisplay()

Is any of this going to return null if the viewer is disposed?

Thanks,


CL
Re: None-UI thread model updates and Display.getCurrent() returning null. [message #173365 is a reply to message #173357] Wed, 23 March 2005 21:24 Go to previous message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

>
>
> 2nd question is, will this even work with a disposed viewer
>
> getViewer().getControl().getDisplay()
>
> Is any of this going to return null if the viewer is disposed?
>
> Thanks,
>
>
> CL

nevermind. I looked in the code and getControl will return null once
the control is disposed. So that is the first check I will have to perform.

CL
Previous Topic:NullPointException
Next Topic:Palette entry and action mapping
Goto Forum:
  


Current Time: Thu Apr 18 13:37:01 GMT 2024

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

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

Back to the top