Eddy Freeman
Eddy Freeman

Reputation:

Eclipse Plugin: Opening A New Window From The WorkBench

I am new in developing Eclipse plugin and i have manage to do a lot of work. This is where i have got stuck. I have a view with a button. When a user cklicks on the button i want a new window to be opened(The window is a form with Text areas, buttons and other SWT widgets). I have finished creating the window.

After I compile the application, I get a new instance of the eclipse workbench(as expected) but when I open the view and clicks on the button, the window don't show up. This is the window code snippet:

public class NewWindow {
    private Display display;
    private Shell shell;

    public NewWindow(){

        this.display = new Display();
    shell = new Shell(displaySWT.TITLE | SWT.MIN | SWT.CLOSE);
    shell.setText("fffffffffffff");

              // additional code here
               ...
               ...

    shell.open();
    this.shellSleep();  // this methode is implemented in my code
}

This is the code snippet that calls this class:

... ...

this.btnCreateNewQuery.addSelectionListener(new SelectionListener(){
            public void widgetDefaultSelected(SelectionEvent e){

            }
            public void widgetSelected(SelectionEvent e){                                   NewWindow b = new NewWindow();

        }
    });

... ...

I don't understand why the window don't show up. I have tried to fix it but has not find anything yet. I read something on this site but i don't understand what they meant. this is the link: How do I get the workbench window to open a modal dialog in an Eclipse based project?

Upvotes: 1

Views: 4365

Answers (2)

Andreas Dolk
Andreas Dolk

Reputation: 114837

Eddy, thats pretty easy to solve. Just do not create a new Display. Reuse the one from the workbench:

public NewWindow() {
        this.display = PlatformUI.getWorkbench().getDisplay();
        shell = new Shell(display, SWT.TITLE | SWT.MIN | SWT.CLOSE);
        shell.setText("fffffffffffff");

              // additional code here
               ...
               ...

        shell.open();
        this.shellSleep();  // this methode is implemented in my code
}

Alternativly you can dismiss the display variable and just pass null to the Shell constructor.

Upvotes: 4

Gandalf
Gandalf

Reputation: 9855

I don't think you want to create a new Shell. Instead pass the parent Shell into your new class. I find it easier to extend one of the Dialog classes (or Dialog itself) for new windows. Then in your constructor you can call super(Shell parent) to initialize all the environment/GUI stuff for you and then you can layout the Dialog area the way you want. Then to open the new window you do a dialog.open().

Upvotes: 0

Related Questions