views:

410

answers:

2

Hello Guys,

I am new here so forgive me for any mistake. I just need your help urgently. 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. Can someone help me to solve this problem. I have been spendig days and nights trying to fix it but has not find anything yet. I read somethig on this site but i don't understand what they meant. this is the link: http://stackoverflow.com/questions/443245/how-do-i-get-the-workbench-window-to-open-a-modal-dialog-in-an-eclipse-based-proj

I need help please.

Thank you.

A: 

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().

Gandalf
A: 

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.

Andreas_D