I learned recently the clean way to replace all my Display.getDefault() method calls:
PlatformUI.getWorkbench().getDisplay();
Here is the Javadoc for this method :
Code should always ask the workbench for the display rather than rely on Display.getDefault()
Am I the last not aware about this method ?? If no, this post may be can help someone else for example spending time to know why there is no active WorkbenchWindow associated to the default Display
…
Thanks to Xavier for pointing me to this cleaner method.
November 18, 2008 at 8:46 am |
You are talking about applications that use the Workbench. Otherwise its perfectly ok to use Display.getDefault().
November 18, 2008 at 9:35 am |
Hi Philk,
You are right, I forgot to mention that I was using Display.getDefault in plugins contributing to the Workbench.
Manu
November 18, 2008 at 3:28 pm |
You’re not the last
Thanks for the tip.
I’m wondering what’s the risk to use Display.getDefault() ?
November 19, 2008 at 11:43 am |
The Display.getDefault() method returns the first DIsplay created or creates a new one if it doesn’t exist.
In an Eclipse environment it doesn’t guaranty that the returned display is the Workbench’s one so you can’t rely on this method.
I haven’t yet encounter a concrete case where it can cause problems but I’am pretty sure such cases exists … Anyone with such an example ?
Manu
November 21, 2008 at 7:05 am |
It’s all over the place Manuel, even the people on the Platform falls into this trap at times. For a concrete example, take a look at bug 250048.
November 21, 2008 at 7:18 am |
Hi Remy,
Thanks for this concrete example.
Manu