Quit menu notification with SWT on Mac OS X ?

Discussion in 'Java' started by Patrick Stadelmann, May 16, 2008.

  1. Hi,

    I have a GUI java application built with SWT that has a single shell. On
    Mac OS X, it is packaged as an application bundle, using the Eclipse
    export module "Mac OS X application bundle".

    I need to perform some actions before the shell is disposed. I found how
    to install a handler for the "close" event, sent when the user's click
    on the window's close box. However, if he use the Quit menu in the
    standard Mac OS X application menu, I don't get notified.

    How can I get notified either when the shell is about to be disposed
    (whether is due to the Quit menu or to the window's close box), or when
    the Quit menu is invoked ?

    Thanks,

    Patrick
    --
    Patrick Stadelmann <>
     
    Patrick Stadelmann, May 16, 2008
    #1
    1. Advertising

  2. In article <>,
    Patrick Stadelmann <> wrote:

    > Hi,
    >
    > I have a GUI java application built with SWT that has a single shell. On
    > Mac OS X, it is packaged as an application bundle, using the Eclipse
    > export module "Mac OS X application bundle".
    >
    > I need to perform some actions before the shell is disposed. I found how
    > to install a handler for the "close" event, sent when the user's click
    > on the window's close box. However, if he use the Quit menu in the
    > standard Mac OS X application menu, I don't get notified.
    >
    > How can I get notified either when the shell is about to be disposed
    > (whether is due to the Quit menu or to the window's close box), or when
    > the Quit menu is invoked ?
    >
    > Thanks,
    >
    > Patrick


    What version of Eclipse?

    You'll need to implement java.awt.event.WindowListener and possibly
    com.apple.eawt.ApplicationListener.

    The platform will handle Preferences flush().

    John
    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews
     
    John B. Matthews, May 16, 2008
    #2
    1. Advertising

  3. In article <>,
    "John B. Matthews" <> wrote:

    > What version of Eclipse?


    I'm using version 3.1.2 / J2SE 1.4.2.

    > You'll need to implement java.awt.event.WindowListener and possibly
    > com.apple.eawt.ApplicationListener.


    Isn't this for use with AWT ? I didn't find equivalents for SWT...

    Thanks for your reply,

    Patrick
    --
    Patrick Stadelmann <>
     
    Patrick Stadelmann, May 16, 2008
    #3
  4. In article <>,
    Patrick Stadelmann <> wrote:

    > In article <>,
    > "John B. Matthews" <> wrote:
    >
    > > What version of Eclipse?

    >
    > I'm using version 3.1.2 / J2SE 1.4.2.
    >
    > > You'll need to implement java.awt.event.WindowListener and possibly
    > > com.apple.eawt.ApplicationListener.

    >
    > Isn't this for use with AWT ? I didn't find equivalents for SWT...
    >
    > Thanks for your reply,
    >
    > Patrick


    Oops, misread the question! My principal contribution to an SWT project
    was the command-line interface:) I was intrigued to hear that there's
    support for building Mac application bundles; I'm still using make...

    John
    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews
     
    John B. Matthews, May 16, 2008
    #4
  5. In article <>,
    "Peter Duniho" <> wrote:

    > Or put
    > another way, if you have something in your Shell that's still useful when
    > the application is exiting, that may suggest that whatever that
    > "something" is, it belongs elsewhere and/or ought not to be interacting
    > with the Shell.


    Thanks for your reply. In my case, it holds controls providing status
    from a device. Before the application exits, some commands are sent to
    the device, and I'd like the Shell to stay around to show the device
    status in case an error occurs at this time.

    But the Shell could simply be e.g. a text editor window. If the user
    quits before saving the modifications, he needs to be notified before
    the Shell disappears...

    Patric
    --
    Patrick Stadelmann <>
     
    Patrick Stadelmann, May 17, 2008
    #5
  6. In article <>,
    Patrick Stadelmann <> wrote:

    > But the Shell could simply be e.g. a text editor window. If the user
    > quits before saving the modifications, he needs to be notified before
    > the Shell disappears...


    BTW, on Windows the listener the for SWT.Close is called when the user
    quits the application using Alt-F4.

    Patrick
    --
    Patrick Stadelmann <>
     
    Patrick Stadelmann, May 17, 2008
    #6
  7. Patrick Stadelmann

    Philipp Guest

    Peter Duniho wrote:
    > An alternative would be to revisit the question of whether you really
    > need to perform these actions before the Shell instance has been
    > disposed.


    Note that eclipse itself does it that way (saving workspace on exit). So
    it's probably not a blatant antipattern.

    Phil
     
    Philipp, May 18, 2008
    #7
  8. In article <>,
    "Peter Duniho" <> wrote:

    > However, it's possible that reviewing the Eclipse code would be a way for
    > the OP to find some direction with respect to his specific goals.


    Indeed, the answer is in the Eclipse source code.

    > At the
    > very least, it should provide better insight into what exactly happens
    > when a user on the Mac chooses "Quit" from the application menu, and what
    > sorts of things one can have their code safely do.


    Native applications receive a "quit" handler, before any action is
    taken, whatever the cause is (system shutting down, quit menu item
    selected in the menu bar or in the Dock, AppleEvent received from
    another application or from an AppleScript, etc...

    Thank you all for your help,

    Patrick
    --
    Patrick Stadelmann <>
     
    Patrick Stadelmann, May 19, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M. Duijkers
    Replies:
    2
    Views:
    500
    Joe Smith
    Dec 12, 2004
  2. Craig

    Postback quit working

    Craig, Sep 27, 2004, in forum: ASP .Net
    Replies:
    10
    Views:
    682
    Kikoz
    Sep 27, 2004
  3. Brandon
    Replies:
    0
    Views:
    360
    Brandon
    Nov 26, 2005
  4. Ramon F Herrera

    Where can I download SWT? (SWT homepage)

    Ramon F Herrera, Dec 5, 2007, in forum: Java
    Replies:
    11
    Views:
    4,110
    Ramon F Herrera
    Dec 6, 2007
  5. Gpy Good
    Replies:
    2
    Views:
    115
    Brian Candler
    May 6, 2007
Loading...

Share This Page