Java close listener for ViewPart
Asked Answered
M

1

6

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

            }
        });
Morehouse answered 21/1, 2013 at 17:5 Comment(0)
A
4

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

Aulic answered 21/1, 2013 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.