You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Scott Lanham <li...@sael.com.au> on 2009/10/22 23:58:11 UTC

Dialog During Shutdown

Hi All,

I am at the point in my application where during Application.shutdown I would 
like a dialog to popup if they haven't saved their changes. The dialog would 
ask if they want to Save, Not Save, Cancel with the last cancelling the 
shutdown. I am uncertain of how to approach this and was hoping someone could 
give me some guidance :-)

Thanks,

Scott.

Re: Dialog During Shutdown

Posted by Todd Volkert <tv...@gmail.com>.
By the way, you could probably do this in a slightly less complicated
fashion.  My app used SaveDiscardCancelTask all over the place, but if you
only prompted the user to save during shutdown(), then you could probably do
some of what SaveDiscardCancelTask does inline inside your app and save the
"task" nature of that part of the code.

-T

On Thu, Oct 22, 2009 at 10:21 PM, Todd Volkert <tv...@gmail.com> wrote:

> SaveDiscardCancelTask.execute() will run on a worker thread, but it posts a
> callback to run on the UI thread and then immediately goes to sleep. The UI
> thread callback shows the prompt, and when the user chooses their option, it
> sets the 'choice' member variable and wakes up the worker thread, which then
> completes its task and returns the user's choice.
>
> -T
>
>
> On Thu, Oct 22, 2009 at 8:51 PM, Scott Lanham <li...@sael.com.au> wrote:
>
>> I don't understand your sample code fully yet but it looks like the Dialog
>> asking the question about saving etc is created in a new thread.
>>
>> On Fri, 23 Oct 2009 10:46:59 am Todd Volkert wrote:
>> > In general, the UI isn't thread safe, so all UI operations should be
>> done
>> > on the UI thread.  Why do you ask?
>> > -T
>> >
>> > On Thu, Oct 22, 2009 at 7:11 PM, Scott Lanham <li...@sael.com.au>
>> wrote:
>> > > Thanks Todd, that is great.
>> > >
>> > > One question though. Is there any problem with creating a dialog in a
>> > > separate
>> > > thread to the main thread?
>> > >
>> > > On Fri, 23 Oct 2009 08:23:43 am Todd Volkert wrote:
>> > > > Hi Scott,
>> > > >
>> > > > First off, you can only do this in DesktopApplicationContext, since
>> > > > BrowserApplicationContext can't reliably prevent the applet from
>> > > > getting destroyed.  If you are in DesktopAplpicationContext, then
>> the
>> > > > very short answer is that you return true from
>> Application.shutdown()
>> > > > to prevent the shutdown until the user has answered your question.
>> > > > Then, when they
>> > >
>> > > answer
>> > >
>> > > > your dialog (or sheet), you call DesktopApplicationContext.exit(),
>> and
>> > > > allow the shutdown at that time.
>> > > >
>> > > > The long answer is that it's kinda tricky to get right.  To aid you
>> on
>> > >
>> > > your
>> > >
>> > > > way, I'll blindly paste snippets of the source of my Pivot app that
>> > > > does exactly this - you should be able to gleam what you need from
>> it.
>> > > >
>> > > > I've attached two snippet source files.  Let me know if they don't
>> come
>> > > > through.
>> > > >
>> > > > -T
>> > > >
>> > > > On Thu, Oct 22, 2009 at 5:58 PM, Scott Lanham <li...@sael.com.au>
>> wrote:
>> > > > > Hi All,
>> > > > >
>> > > > > I am at the point in my application where during
>> Application.shutdown
>> > > > > I would
>> > > > > like a dialog to popup if they haven't saved their changes. The
>> > > > > dialog would
>> > > > > ask if they want to Save, Not Save, Cancel with the last
>> cancelling
>> > > > > the shutdown. I am uncertain of how to approach this and was
>> hoping
>> > > > > someone could
>> > > > > give me some guidance :-)
>> > > > >
>> > > > > Thanks,
>> > > > >
>> > > > > Scott.
>>
>>
>

Re: Dialog During Shutdown

Posted by Todd Volkert <tv...@gmail.com>.
SaveDiscardCancelTask.execute() will run on a worker thread, but it posts a
callback to run on the UI thread and then immediately goes to sleep. The UI
thread callback shows the prompt, and when the user chooses their option, it
sets the 'choice' member variable and wakes up the worker thread, which then
completes its task and returns the user's choice.

-T

On Thu, Oct 22, 2009 at 8:51 PM, Scott Lanham <li...@sael.com.au> wrote:

> I don't understand your sample code fully yet but it looks like the Dialog
> asking the question about saving etc is created in a new thread.
>
> On Fri, 23 Oct 2009 10:46:59 am Todd Volkert wrote:
> > In general, the UI isn't thread safe, so all UI operations should be done
> > on the UI thread.  Why do you ask?
> > -T
> >
> > On Thu, Oct 22, 2009 at 7:11 PM, Scott Lanham <li...@sael.com.au> wrote:
> > > Thanks Todd, that is great.
> > >
> > > One question though. Is there any problem with creating a dialog in a
> > > separate
> > > thread to the main thread?
> > >
> > > On Fri, 23 Oct 2009 08:23:43 am Todd Volkert wrote:
> > > > Hi Scott,
> > > >
> > > > First off, you can only do this in DesktopApplicationContext, since
> > > > BrowserApplicationContext can't reliably prevent the applet from
> > > > getting destroyed.  If you are in DesktopAplpicationContext, then the
> > > > very short answer is that you return true from Application.shutdown()
> > > > to prevent the shutdown until the user has answered your question.
> > > > Then, when they
> > >
> > > answer
> > >
> > > > your dialog (or sheet), you call DesktopApplicationContext.exit(),
> and
> > > > allow the shutdown at that time.
> > > >
> > > > The long answer is that it's kinda tricky to get right.  To aid you
> on
> > >
> > > your
> > >
> > > > way, I'll blindly paste snippets of the source of my Pivot app that
> > > > does exactly this - you should be able to gleam what you need from
> it.
> > > >
> > > > I've attached two snippet source files.  Let me know if they don't
> come
> > > > through.
> > > >
> > > > -T
> > > >
> > > > On Thu, Oct 22, 2009 at 5:58 PM, Scott Lanham <li...@sael.com.au>
> wrote:
> > > > > Hi All,
> > > > >
> > > > > I am at the point in my application where during
> Application.shutdown
> > > > > I would
> > > > > like a dialog to popup if they haven't saved their changes. The
> > > > > dialog would
> > > > > ask if they want to Save, Not Save, Cancel with the last cancelling
> > > > > the shutdown. I am uncertain of how to approach this and was hoping
> > > > > someone could
> > > > > give me some guidance :-)
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Scott.
>
>

Re: Dialog During Shutdown

Posted by Scott Lanham <li...@sael.com.au>.
I don't understand your sample code fully yet but it looks like the Dialog 
asking the question about saving etc is created in a new thread.

On Fri, 23 Oct 2009 10:46:59 am Todd Volkert wrote:
> In general, the UI isn't thread safe, so all UI operations should be done
> on the UI thread.  Why do you ask?
> -T
>
> On Thu, Oct 22, 2009 at 7:11 PM, Scott Lanham <li...@sael.com.au> wrote:
> > Thanks Todd, that is great.
> >
> > One question though. Is there any problem with creating a dialog in a
> > separate
> > thread to the main thread?
> >
> > On Fri, 23 Oct 2009 08:23:43 am Todd Volkert wrote:
> > > Hi Scott,
> > >
> > > First off, you can only do this in DesktopApplicationContext, since
> > > BrowserApplicationContext can't reliably prevent the applet from
> > > getting destroyed.  If you are in DesktopAplpicationContext, then the
> > > very short answer is that you return true from Application.shutdown()
> > > to prevent the shutdown until the user has answered your question. 
> > > Then, when they
> >
> > answer
> >
> > > your dialog (or sheet), you call DesktopApplicationContext.exit(), and
> > > allow the shutdown at that time.
> > >
> > > The long answer is that it's kinda tricky to get right.  To aid you on
> >
> > your
> >
> > > way, I'll blindly paste snippets of the source of my Pivot app that
> > > does exactly this - you should be able to gleam what you need from it.
> > >
> > > I've attached two snippet source files.  Let me know if they don't come
> > > through.
> > >
> > > -T
> > >
> > > On Thu, Oct 22, 2009 at 5:58 PM, Scott Lanham <li...@sael.com.au> wrote:
> > > > Hi All,
> > > >
> > > > I am at the point in my application where during Application.shutdown
> > > > I would
> > > > like a dialog to popup if they haven't saved their changes. The
> > > > dialog would
> > > > ask if they want to Save, Not Save, Cancel with the last cancelling
> > > > the shutdown. I am uncertain of how to approach this and was hoping
> > > > someone could
> > > > give me some guidance :-)
> > > >
> > > > Thanks,
> > > >
> > > > Scott.


Re: Dialog During Shutdown

Posted by Todd Volkert <tv...@gmail.com>.
In general, the UI isn't thread safe, so all UI operations should be done on
the UI thread.  Why do you ask?
-T

On Thu, Oct 22, 2009 at 7:11 PM, Scott Lanham <li...@sael.com.au> wrote:

> Thanks Todd, that is great.
>
> One question though. Is there any problem with creating a dialog in a
> separate
> thread to the main thread?
>
> On Fri, 23 Oct 2009 08:23:43 am Todd Volkert wrote:
> > Hi Scott,
> >
> > First off, you can only do this in DesktopApplicationContext, since
> > BrowserApplicationContext can't reliably prevent the applet from getting
> > destroyed.  If you are in DesktopAplpicationContext, then the very short
> > answer is that you return true from Application.shutdown() to prevent the
> > shutdown until the user has answered your question.  Then, when they
> answer
> > your dialog (or sheet), you call DesktopApplicationContext.exit(), and
> > allow the shutdown at that time.
> >
> > The long answer is that it's kinda tricky to get right.  To aid you on
> your
> > way, I'll blindly paste snippets of the source of my Pivot app that does
> > exactly this - you should be able to gleam what you need from it.
> >
> > I've attached two snippet source files.  Let me know if they don't come
> > through.
> >
> > -T
> >
> > On Thu, Oct 22, 2009 at 5:58 PM, Scott Lanham <li...@sael.com.au> wrote:
> > > Hi All,
> > >
> > > I am at the point in my application where during Application.shutdown I
> > > would
> > > like a dialog to popup if they haven't saved their changes. The dialog
> > > would
> > > ask if they want to Save, Not Save, Cancel with the last cancelling the
> > > shutdown. I am uncertain of how to approach this and was hoping someone
> > > could
> > > give me some guidance :-)
> > >
> > > Thanks,
> > >
> > > Scott.
>
>

Re: Dialog During Shutdown

Posted by Scott Lanham <li...@sael.com.au>.
Thanks Todd, that is great.

One question though. Is there any problem with creating a dialog in a separate 
thread to the main thread?

On Fri, 23 Oct 2009 08:23:43 am Todd Volkert wrote:
> Hi Scott,
>
> First off, you can only do this in DesktopApplicationContext, since
> BrowserApplicationContext can't reliably prevent the applet from getting
> destroyed.  If you are in DesktopAplpicationContext, then the very short
> answer is that you return true from Application.shutdown() to prevent the
> shutdown until the user has answered your question.  Then, when they answer
> your dialog (or sheet), you call DesktopApplicationContext.exit(), and
> allow the shutdown at that time.
>
> The long answer is that it's kinda tricky to get right.  To aid you on your
> way, I'll blindly paste snippets of the source of my Pivot app that does
> exactly this - you should be able to gleam what you need from it.
>
> I've attached two snippet source files.  Let me know if they don't come
> through.
>
> -T
>
> On Thu, Oct 22, 2009 at 5:58 PM, Scott Lanham <li...@sael.com.au> wrote:
> > Hi All,
> >
> > I am at the point in my application where during Application.shutdown I
> > would
> > like a dialog to popup if they haven't saved their changes. The dialog
> > would
> > ask if they want to Save, Not Save, Cancel with the last cancelling the
> > shutdown. I am uncertain of how to approach this and was hoping someone
> > could
> > give me some guidance :-)
> >
> > Thanks,
> >
> > Scott.


Re: Dialog During Shutdown

Posted by Todd Volkert <tv...@gmail.com>.
Hi Scott,

First off, you can only do this in DesktopApplicationContext, since
BrowserApplicationContext can't reliably prevent the applet from getting
destroyed.  If you are in DesktopAplpicationContext, then the very short
answer is that you return true from Application.shutdown() to prevent the
shutdown until the user has answered your question.  Then, when they answer
your dialog (or sheet), you call DesktopApplicationContext.exit(), and allow
the shutdown at that time.

The long answer is that it's kinda tricky to get right.  To aid you on your
way, I'll blindly paste snippets of the source of my Pivot app that does
exactly this - you should be able to gleam what you need from it.

I've attached two snippet source files.  Let me know if they don't come
through.

-T

On Thu, Oct 22, 2009 at 5:58 PM, Scott Lanham <li...@sael.com.au> wrote:

> Hi All,
>
> I am at the point in my application where during Application.shutdown I
> would
> like a dialog to popup if they haven't saved their changes. The dialog
> would
> ask if they want to Save, Not Save, Cancel with the last cancelling the
> shutdown. I am uncertain of how to approach this and was hoping someone
> could
> give me some guidance :-)
>
> Thanks,
>
> Scott.
>