Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java close listener for ViewPart

I'm using eclipse RCP with a view and I want to print something on the console when the application is closed.

This is what I have done, but It's not working;

public void createPartControl(final Composite parent){
   parent.getShell().addListener(SWT.CLOSE, new Listener() {

      @Override
      public void handleEvent(Event event) {
         System.out.println("NOW !");
      }
   });
}

EDIT: I found a solution, I needed to add a DisposeListener:

parent.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                // TODO Auto-generated method stub

            }
        });
like image 402
Zbarcea Christian Avatar asked Oct 21 '22 19:10

Zbarcea Christian


1 Answers

You want to use the SWT.Close event and not SWT.CLOSE. From the SWT Javadoc:

SWT.Close - The close event type (value is 21).

SWT.CLOSE - Style constant for close box trim (value is 1<<6, since we do not distinguish between CLOSE style and MENU style).

like image 143
Marc Baumbach Avatar answered Oct 27 '22 09:10

Marc Baumbach