Search code examples
javaeclipsedialogeclipse-rcprcp

How to give focus to Eclipse RCP TitleAreaDialog?


I have a button in my Eclipse RCP View that makes a TitleAreaDialog popup with a form. However, when I click the button, the TitleAreaDialog pops up behind my view, rather than in front of it to catch the user's attention.

This is how my dialog is declared:

public class PopUpEditForm extends TitleAreaDialog {
    public PopUpEditForm(Shell parentShell) {
        super(parentShell);
        //Irrelevant logic
    }
//Other functions to populate/create the form
}

This is how it is called:

public void editFeature(){
    Display disp = new Display();
    Shell she = new Shell(disp);
    PopUpEditForm p = new PopUpEditForm(she);
}

I tried setting the focus (.setFocus()) for the container used to display the form, along with components of that container. I also used .forceActive() but to no avail. Halp.

EDIT: SOLUTION

I was using the wrong shell:

public void editFeature(){
    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

    public void run() {
            Shell activeShell =     PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            PopUpEditForm p = new PopUpEditForm(activeShell);
    }        
}

Solution

  • I would suggest you use :

        public void editFeature()
        {
    Display disp = new Display();
    Shell she = new Shell(disp);
    PopUpEditForm p = new PopUpEditForm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
        }
    

    Ideally dialog should be above window.