Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Preventing a shell from closing
Preventing a shell from closing [message #480109] Thu, 13 August 2009 20:42 Go to next message
Marian Schedenig is currently offline Marian SchedenigFriend
Messages: 25
Registered: July 2009
Junior Member
Hi!

I'm trying to make a window which cannot be closed using the close button in
the title bar. According to what I can find on the web, the following should
work:

getShell().addShellListener(new ShellAdapter()
{
@Override
public void shellClosed(ShellEvent e)
{
e.doit = false;
}
});

However, at least in GTK, the method is called only *after* the shell has
already been disposed (verified through e.widget.isDisposed()). I haven't
yet had a chance to try in Windows.

Also, GTK always displays a close button, regardless of whether the shell's
style includes one or not. This may be correct behaviour, however I really
need a working way to prevent the shell from closing when it is clicked.

Thanks,
Marian.

--
Hofstadter's law: "It always takes longer than you think,
even when you take account of Hofstadter's law".
Re: Preventing a shell from closing [message #480112 is a reply to message #480109] Thu, 13 August 2009 21:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: phillipus.nowhere.net

Marian Schedenig wrote:
> Hi!
>
> I'm trying to make a window which cannot be closed using the close button in
> the title bar. According to what I can find on the web, the following should
> work:
>
> getShell().addShellListener(new ShellAdapter()
> {
> @Override
> public void shellClosed(ShellEvent e)
> {
> e.doit = false;
> }
> });
>
> However, at least in GTK, the method is called only *after* the shell has
> already been disposed (verified through e.widget.isDisposed()). I haven't
> yet had a chance to try in Windows.
>
> Also, GTK always displays a close button, regardless of whether the shell's
> style includes one or not. This may be correct behaviour, however I really
> need a working way to prevent the shell from closing when it is clicked.
>
> Thanks,
> Marian.
>

I tested on Windows 7. It works as expected. Could be Linux bug. Make a
test snippet and post it here.
Re: Preventing a shell from closing [message #480188 is a reply to message #480112] Fri, 14 August 2009 10:18 Go to previous message
Marian Schedenig is currently offline Marian SchedenigFriend
Messages: 25
Registered: July 2009
Junior Member
Phillipus wrote:

> Marian Schedenig wrote:
>> getShell().addShellListener(new ShellAdapter()
>> {
>> @Override
>> public void shellClosed(ShellEvent e)
>> {
>> e.doit = false;
>> }
>> });
>
> I tested on Windows 7. It works as expected. Could be Linux bug. Make a
> test snippet and post it here.

My mistake. I wrote an SWT test snippet and it worked. Turns out this is a
JFace feature: The Window#canHandleShellCloseEvent()
Window#handleShellCloseEvent() are provided for dealing with the close
button. Apparently, Window registers a shell listener itself for handling
the close event, so regardless of my own listener, JFace's own listener got
called - and the default behaviour of handleShellCloseEvent() is to close
the window.

Two possible solutions:

1) Override canHandleShellCloseEvent() to return false, then implement
custom behaviour in a standard SWT shell listener.

2) Override handleShellCloseEvent() and put your own custom behaviour right
there.

Sorry for the alarm. :)
Marian.

--
Hofstadter's law: "It always takes longer than you think,
even when you take account of Hofstadter's law".
Previous Topic:Spinner - Min, Max values
Next Topic:readAndDispatch Causing Hang With Browser
Goto Forum:
  


Current Time: Tue Apr 23 13:42:57 GMT 2024

Powered by FUDForum. Page generated in 0.03119 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top