Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the workbench window to open a modal dialog in an Eclipse based project?

Tags:

In order to open a modal dialog, you need to pass a parent window, and pass the necessary flags for the dialog to be modal of course.

Depending on where you are in the eclipse infrastructure, finding this parent window is not always easy.

How can the parent window be accessed?

like image 836
Tirno Avatar asked Jan 14 '09 14:01

Tirno


2 Answers

The piece of code from the previous answer will work. However, keep in mind you can only open your dialog from the UI thread. If you are opening the dialog from a different thread, e.g. a background process, you need to do something like this:

PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
    public void run() {
        Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    }
});

Otherwise you will get an exception when creating the dialog.

like image 168
zvikico Avatar answered Oct 05 '22 02:10

zvikico


From a view or an editor (this part is easy):

this.getSite().getWorkbenchWindow().getShell()

From elsewhere, access a view or editor and same as above.

If you find yourself in a class where you don't have access to a view or editor, you probably don't want to be calling any UI code, but if you really want to shoot yourself in the foot:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
like image 33
Tirno Avatar answered Oct 05 '22 02:10

Tirno