Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

on Jun 23rd, 2010Tip: 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.

detached view Tip: How to detect that a View was Detached

Related posts:

7 Responses to “Tip: How to detect that a View was Detached”

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

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

  2. Jens Kreidler says:

    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

  3. AEHP says:

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

  4. @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).

  5. AEHP says:

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

  6. Jens Kreidler says:

    Thank you Mickael!

  7. AEHP says:

    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() {
    @Override
    public void controlResized(ControlEvent e) {
    updateDetached();
    }
    });
    updateDetached();

    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.

    Regards,

    AEHP

© EclipseSource 2008 - 2011