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@unine.ch>
|
|
0
|
|
|
|
Reply
|
Patrick.Stadelmann (45)
|
5/16/2008 9:53:53 AM |
|
In article <Patrick.Stadelmann-7AB856.11535316052008@individual.net>,
Patrick Stadelmann <Patrick.Stadelmann@unine.ch> 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
|
|
0
|
|
|
|
Reply
|
nospam21 (11322)
|
5/16/2008 1:13:20 PM
|
|
In article <nospam-4E4BF1.09130516052008@news-server.woh.rr.com>,
"John B. Matthews" <nospam@nospam.com> 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@unine.ch>
|
|
0
|
|
|
|
Reply
|
Patrick.Stadelmann (45)
|
5/16/2008 4:44:40 PM
|
|
In article <Patrick.Stadelmann-AEA324.18444016052008@individual.net>,
Patrick Stadelmann <Patrick.Stadelmann@unine.ch> wrote:
> In article <nospam-4E4BF1.09130516052008@news-server.woh.rr.com>,
> "John B. Matthews" <nospam@nospam.com> 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
|
|
0
|
|
|
|
Reply
|
nospam21 (11322)
|
5/16/2008 8:10:09 PM
|
|
On Fri, 16 May 2008 02:53:53 -0700, Patrick Stadelmann
<Patrick.Stadelmann@unine.ch> wrote:
> [...]
> 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 ?
I've only played around with SWT a little bit. But inasmuch as the JVM
seems to be managing the main application menu with the "Quit" item, it
seems possible to me that you may not be able to get notification. That
menu item might be operating at a higher level than that at which Java
code is executing.
If it _is_ possible, I would expect you'd need to add a listener to the
menu item itself, to see if you can get notification of the item before it
winds up disposing your Shell instance. Here's a page from Apple's docs
that includes a sample SWT program that has a custom menu; it may provide
a starting point for looking at retrieving the "Quit" menu item so that
you can add a listener (I haven't tried that, so I don't actually know if
it's possible; if it is, it shouldn't be hard to do...just enumerate the
menu items to find it).
An alternative would be to revisit the question of whether you really need
to perform these actions before the Shell instance has been disposed. The
Shell is responsible for UI stuff and if the application is exiting, it's
not clear that anything the Shell instance has should be useful. 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.
You can subscribe a DisposeListener to the shell to get notification that
it's _been_ disposed. This doesn't address your specific question, but if
you can remove the requirement of "before disposed", that will at least
get you reliable notification that the application is quitting.
Pete
|
|
0
|
|
|
|
Reply
|
NpOeStPeAdM (1107)
|
5/16/2008 8:51:12 PM
|
|
Sorry...forgot to include the link:
On Fri, 16 May 2008 13:51:12 -0700, Peter Duniho
<NpOeStPeAdM@nnowslpianmk.com> wrote:
> [...]
> If it _is_ possible, I would expect you'd need to add a listener to the
> menu item itself, to see if you can get notification of the item before
> it winds up disposing your Shell instance. Here's a page from Apple's
> docs that includes a sample SWT program that has a custom menu [...]
http://developer.apple.com/tools/usingeclipse.html
The SWT sample is near the bottom.
|
|
0
|
|
|
|
Reply
|
NpOeStPeAdM (1107)
|
5/16/2008 8:52:26 PM
|
|
In article <op.ua9ljmxj8jd0ej@petes-computer.local>,
"Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com> 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@unine.ch>
|
|
0
|
|
|
|
Reply
|
Patrick.Stadelmann (45)
|
5/17/2008 8:53:43 AM
|
|
In article <Patrick.Stadelmann-276D8C.10534317052008@individual.net>,
Patrick Stadelmann <Patrick.Stadelmann@unine.ch> 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@unine.ch>
|
|
0
|
|
|
|
Reply
|
Patrick.Stadelmann (45)
|
5/17/2008 9:48:45 AM
|
|
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
|
|
0
|
|
|
|
Reply
|
sicsicsic (164)
|
5/18/2008 9:35:30 AM
|
|
On Sun, 18 May 2008 02:35:30 -0700, Philipp <sicsicsic@freesurf.ch> wrote:
> 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.
I'm not entirely sure what you mean. It's not unusual for an application
to do _something_ before exiting, and I agree that's not necessarily an
"antipattern".
My point was that the existing Shell instance itself may not really need
to continue to exist. In a follow-up message, the OP indicated he not
only wants to do something before the Shell is disposed, he wants the
Shell to remain until he decides he's done with it, even if the user has
selected the "Quit" command from the menu. To some extent, that _is_ an
"antipattern", in that he seems to want the program to do something
contrary to the user's command.
Now, not that there's not also precedent for that. But I have to admit,
every time I run into an application that acts that way, I find myself
doing a little double-take. It always seems a little awkward.
I don't actually know exactly what Eclipse is doing when it quits.
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. 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.
Pete
|
|
0
|
|
|
|
Reply
|
NpOeStPeAdM (1107)
|
5/18/2008 11:57:25 PM
|
|
In article <op.ubdjhznv8jd0ej@petes-computer.local>,
"Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com> 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@unine.ch>
|
|
0
|
|
|
|
Reply
|
Patrick.Stadelmann (45)
|
5/19/2008 11:07:26 AM
|
|
|
10 Replies
24 Views
(page loaded in 0.129 seconds)
|