0

Aborting Selects in Tree and Listbox

asked 2009-05-15 18:25:36 +0800

rappr gravatar image rappr
48

updated 2009-05-15 18:27:28 +0800

Hi,

I have a tree and some listboxes and text boxes.
When a user selects another item in the tree or changes a listbox selection I need to check if there are un-saved changes in the text boxes and ask the user if he wants to leave without saving.
This is no problem with MessageBox etc.

But if the user does NOT want to leave without saving how can I abort/cancel the new selection in the tree or the listbox so that the old values are still selected?
My idea was to cancel the SelectEvent but I couldn't see how to do this...

Any ideas?

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-05-15 18:56:30 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-05-15 19:00:21 +0800

Hmmmmm,
i read this line 10-times. I don't understand it. Can you explain in other words.

|But if the user does NOT want to leave without saving how can I abort/cancel the new selection in the tree or the listbox so that the old values are still selected?|

Stephan

PS: I don't know but here are a few snippets:
You can store the initial values in vars and make a compare of it and restore if needed.

/**
	 * Stores the old values
	 */
	private void doStoreInitValues() {
		oldVar_kunNr = kunNr.getValue();
		oldVar_kunMatchcode = kunMatchcode.getValue();
		oldVar_kunName1 = kunName1.getValue();
		oldVar_kunName2 = kunName2.getValue();
		oldVar_kunOrt = kunOrt.getValue();

		oldVar_kunBranche = kunBranche.getSelectedItem();
		oldVar_kunMahnsperre = kunMahnsperre.isChecked();
	}

/**
	 * Checks, if data are changed since the last call of <br>
	 * doStoreInitData() . <br>
	 * 
	 * @return true, if data are changed, otherwise false
	 */
	private boolean isDataChanged() {
		boolean changed = false;

		if (oldVar_kunNr != kunNr.getValue()) {
			changed = true;
		}
		if (oldVar_kunMatchcode != kunMatchcode.getValue()) {
			changed = true;
		}
		if (oldVar_kunName1 != kunName1.getValue()) {
			changed = true;
		}
		if (oldVar_kunName2 != kunName2.getValue()) {
			changed = true;
		}
		if (oldVar_kunOrt != kunOrt.getValue()) {
			changed = true;
		}
		if (oldVar_kunBranche != kunBranche.getSelectedItem()) {
			changed = true;
		}
		if (oldVar_kunMahnsperre != kunMahnsperre.isChecked()) {
			changed = true;
		}

		return changed;
	}

link publish delete flag offensive edit

answered 2009-06-05 09:53:36 +0800

rappr gravatar image rappr
48

Hi Stephan

Thank you for your answer and sorry for my late answer. I've been on holidays.

OK. That is exactly what I want to do.
But I thought it would be possible to cancel the change (selection in the tree etc) instead of restoring to the old values.

I can try to explain it more detailled:
I have a page with a tree on the left. the user selects a product in the tree.
on the right properties are displayed for this product. Now he changes some of the product properties.
Without saving he now selects another product in the tree.
Here I want to ask the user if he really wants to leave or go back and save.
I he decides to go back for further changes and/or save I do not reload the product properties BUT in the tree on the left the new product is already selected!

Do you know if there is any other possibility instead of saving the old status and restoring it?
Something like cancel the onSelect event?

Ralf

link publish delete flag offensive edit

answered 2009-06-05 10:01:44 +0800

SergeTk gravatar image SergeTk
193 3

You could extend the tree and override onSelect method and put logic inside overriden onSelect method...

link publish delete flag offensive edit

answered 2009-06-05 11:43:45 +0800

rappr gravatar image rappr
48

Hi SergeTk

thank you for the idea. I will check this.
But I have the same problem with other components on the page:
- user can select another product in the tree
- user can select another currency, reporttype etc in some listboxes

and in all cases I need to check if there were unsaved changes and abort the "navigation" (selection in tree, selection in listboxes).

So, do I have to override onSelect methods of tree and listboxes?!

Ralf

link publish delete flag offensive edit

answered 2009-06-06 02:29:00 +0800

SergeTk gravatar image SergeTk
193 3

yes you can extend both tree, listbox and override their onSelect()..

You could also use aspectJ for this kind of staff I think , but for me extending would be simplest way.

link publish delete flag offensive edit

answered 2009-06-08 09:16:02 +0800

rappr gravatar image rappr
48

I have looked into the tree and listbox classes but I couldn't find out how to override the onSelect().
Where is the onSelect() located?

Could you please provide a little sample code for me?

link publish delete flag offensive edit

answered 2009-06-10 04:18:42 +0800

SergeTk gravatar image SergeTk
193 3

Ok you right there is no onSelect (I assumed it had since it fires select event) .....

After looking at source code it seems that Listitem is the one who calls the listbox to process selection of the item
so you probably need to look at extending Listitem and overriding setSelected() method.

But once you overriden listitem there is another problem how to make sure listbox uses your listitem and not default so you would need to extend listbox as well , and override parts where it creates listitems inside render inner class ........

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-05-15 18:25:36 +0800

Seen: 247 times

Last updated: Jun 10 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More