Tip: How to detect that a View was Detached

Tip: How to detect that a View was Detached

Here is a question that I got on a post about detached views:

“How can I detect that a View has been detached from the main window? I would like to adjust the view’s behavior in that case.”

There is no API to obtain that information directly. However it is possible to do this with a few tricks:

  1. detached views have an empty window title (i.e. shell.getText().length() == 0)
  2. when a view is detached resize events are fired

Armed with that knowledge we can detect that a view is detached / reattached. The snippet below shows how (tested on windows).

PS: Our eclipse support helps developers use their time efficiently by providing prompt answers to questions like this one.

  • Posted at 00:00, 2010-06-24

    It’s a bit of hack, thanks a lot.

    Do you know the reasons why the API does not exist ? OS constraints ?

  • Jens Kreidler
    Posted at 09:59, 2010-06-24

    Thx for this tip! Could come in handy!
    By the way, I’d like to know if and how you can detach a view part programatically! Thx in advance

  • AEHP
    Posted at 15:03, 2010-06-24

    You are the best, I don’t words.
    Thank man, Gad exist for you.

  • Posted at 13:27, 2010-06-25

    @Jens Kreidler

    To detach a view part programatically you need to use internal APIs.

    Look at sample project (https://bugs.eclipse.org/bugs/attachment.cgi?id=133197) from https://bugs.eclipse.org/bugs/show_bug.cgi?id=270212. From the View class, you will find an helping mehod (openDetachedView).

  • AEHP
    Posted at 10:01, 2010-06-29

    I want to resize a RCP view when I resize the window that contains this RCP view.
    Does anyone has ideas?

  • Jens Kreidler
    Posted at 07:53, 2010-07-15

    Thank you Mickael!

  • AEHP
    Posted at 14:57, 2010-08-27

    Hi Elias,

    Thank for your answer.

    Now, I want to share with you this problem, my app show

    Exception in thread “AWT-EventQueue-0” java.lang.StackOverflowError
    at sun.awt.X11.XlibWrapper.CallErrorHandler(Native Method)
    at sun.awt.X11.XToolkit.SAVED_ERROR_HANDLER(XToolkit.java:125)
    at sun.awt.X11.XToolkit.GlobalErrorHandler(XToolkit.java:136)

    when I attach and detach the views. This is the main code.

    public void createPartControl(Composite parent) {
    this.parent_ = parent;

    parent.addControlListener(new ControlAdapter() {
    public void controlResized(ControlEvent e) {

    composite_ = new Composite( parent, SWT.EMBEDDED );
    display_ = parent.getDisplay();
    display_.asyncExec(new Runnable() {
    public void run() {
    frame_ = SWT_AWT.new_Frame( composite_ );

    I hope to find the solution, it is very important for my project.