Eclipse plugin: opening a new window from the WorkBench

I am new to Eclipse plugin development and have managed to do a lot of work. This is where I got stuck. I have a view with a button. When the user clicks on the button, I want to open a new window (the window is a form with text areas, buttons and other SWT widgets). I have finished creating the window.

After compiling the application, I get a new instance of the eclipse desktop (as expected), but when I open the view and click the button, no window appears. 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 doesn't appear. I tried to fix it but couldn't find anything yet. I read a few things on this site, but I don't understand what they mean. this is the link: How do I get the desktop window to open a modal dialog in an Eclipse based project?

+1


a source to share


2 answers


Eddie, this is pretty easy to solve. Just don't create a new Display. Reusing one of 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
}

      



Alternatively, you can dismiss the displayed variable and just pass null to the shell constructor.

+3


a source


I don't think you want to create a new wrapper. Pass the parent wrapper to the new class instead. I find it easier to extend one of the Dialog (or Dialog) classes for new windows. Then in your constructor, you can call super (the parent of the wrapper) to initialize all the environment / GUI content for you, and then you can expand the dialog area however you want. Then, to open a new window, you run the dialog.open () dialog.



0


a source







All Articles