Am I The Last ??

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.

6 Responses to “Am I The Last ??”

  1. philk Says:

    You are talking about applications that use the Workbench. Otherwise its perfectly ok to use Display.getDefault().

  2. Manuel Says:

    Hi Philk,

    You are right, I forgot to mention that I was using Display.getDefault in plugins contributing to the Workbench.

    Manu

  3. Nicolas Bihan Says:

    You’re not the last ;)

    Thanks for the tip.
    I’m wondering what’s the risk to use Display.getDefault() ?

  4. Manuel Says:

    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

  5. Remy Chi Jian Suen Says:

    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.

  6. Manuel Says:

    Hi Remy,

    Thanks for this concrete example.

    Manu

Leave a Reply