pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bartlett <cbartlet...@gmail.com>
Subject Re: How to use windowStateListener?
Date Tue, 27 Mar 2012 19:47:10 GMT
Brendan,

Sorry for the slow reply.  I have only just been able to download your
sample (which was exactly what was needed).

The problem is that your WindowStateListener is opening a Prompt, but
the program execution doesn't wait for the user to click on one of the
buttons.  It just carries on and returns Vote.APPROVE, which means
that the Frame gets closed.

I have attached a slightly reworked TestFrame class that opens the
Prompt and returns a Vote.DENY to stop the Frame from closing.  Any
time later, if the 'Yes' button is pressed, it will explicitly ask for
the Frame to be closed after setting the return value to Vote.APPROVE.

public class TestFrame extends Frame implements Bindable {

	@BXML
	private Prompt closeConfirmPrompt;

	private Vote vote = Vote.DENY;

	@Override
	public void initialize(Map<String, Object> namespace, URL location,
			Resources resources) {

		this.getWindowStateListeners().add(new WindowStateListener.Adapter() {

			@Override
			public Vote previewWindowClose(final Window window) {
				if (vote == Vote.DENY) {
					closeConfirmPrompt.open(window, new SheetCloseListener() {
						@Override
						public void sheetClosed(Sheet sheet) {
							if (closeConfirmPrompt.getResult() &&
closeConfirmPrompt.getSelectedOptionIndex() == 1) {
								TestFrame.this.vote = Vote.APPROVE;
								window.close();
							}
						}
					});
				}
				return vote;
			}

		});
	}
}


I can't help thinking there is a tidier way of doing this, but my
brain is a bit rusty because I have been away from Pivot for a couple
of months.  Anyway, I hope that helps.

Chris

On 24 March 2012 11:41, Brendan cheng <ccp999@hotmail.com> wrote:
> Hi Chris,
>
> I just made a small completed program for you.
> Please try to close the frames and I added listener to prompt for
> confirmation before it close but didn't work.
>
> Brendan
>
>
>
>> Date: Sat, 24 Mar 2012 10:28:12 +0000
>> Subject: Re: How to use windowStateListener?
>> From: cbartlett.x@gmail.com
>> To: user@pivot.apache.org
>
>>
>> Could you please post a complete, small example of this?
>>
>> How is the Frame closed? Are you talking about closing the
>> org.apache.pivot.wtk.Frame or the operating system window (which is a
>> java.awt.Frame I think) in a desktop application?
>>
>> Chris
>>
>> On 24 March 2012 10:10, ccp999 <ccp999@hotmail.com> wrote:
>> > Hi,
>> >
>> > I want to do a check before a frame is closed, so that for unsaved
>> > content,
>> > I c an veto the closing.
>
>> >
>> > and here is my code:
>> >
>> > ......
>> >
>> > │ │ │private Vote vote = Vote.APPROVE;
>> >
>> > │ │ │ │@Override
>> > │ │ │ │public void initialize(Map<String, Object> namespace, URL
>> > location,
>> > │ │ │ │ │ │ │ │ │ │ │ │Resources resources) {
>> >
>> > │ │ │ │ │ │ │ │this.getWindowStateListeners().add(new
>> > WindowStateListener.Adapter() {
>> >
>> > │ │ │ │ │ │ │ │ │ │ │ │@Override
>> > │ │ │ │ │ │ │ │ │ │ │ │public Vote previewWindowClose(Window
window) {
>> >
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │if (Compose.this.isEdited())
{
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│closeConfirmPrompt.open(window,
>> > new SheetCloseListener() {
>> >
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ � �│ │@Override
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │public void
>> > sheetClosed(Sheet sheet) {
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │if
>> > (closeConfirmPrompt.getResult()
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
>> > │&& closeConfirmPrompt
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
>> > │ │ │ │ │ │ │ │.getSelectedOptionIndex() == 1) {
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │vote =
>> > Vote.APPROVE;
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │} else
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │vote =
>> > Vote.DENY;
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │}
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│});
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│return vote;
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │} else
>> > │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│return Vote.APPROVE;
>> >
>> > │ │ │ │ │ │ │ │ │ │ │ │}
>> >
>> > │ │ │ │ │ │ │ │});
>> >
>> > However, the result is the window is closed before the prompt show up.
>> > why prompt is bypassed ?
>> >
>> > Brendan
>> >
>> >
>> > --
>> > View this message in context:
>> > http://apache-pivot-users.399431.n3.nabble.com/How-to-use-windowStateListener-tp3853550p3853550.html
>> > Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
Mime
View raw message