0

Unable to know deselected items when keyboard "Move Selection" deselected something on a Tree

asked 2012-12-27 05:23:56 +0800

rangilin gravatar image rangilin
3

updated 2012-12-27 05:56:30 +0800

Sometimes a tree may contains some logic, like do things when user select/deselect an item, this can easily done by listening event like this.

   
    @Listen("onSelect = #tree")
    public void onSelect(SelectEvent<Treeitem, String> event) {
        Treeitem ref = event.getReference();
        if (ref.isSelected()) {
            // do things when item is selected
        } else {
           // do things when item is deselected
        }
    }


ZK provide function that user can using UP, DOWN, PageUp, PageDown, Home, End key on a Tree to "Move Selection". This action will also send out a select event about new selected item, but not about deselected items. Therefore, previous code snippets dose not works when user use these keys.

My questions are :

1. How should I do so I can know exactly which items are deselected when user "Move Selection"?
2. If not, can I disable these keys ?

Here's the example : Example@ZK fiddle

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2013-01-02 07:17:45 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2013-01-02 07:24:20 +0800

Hi rangilin,

You can keep original selected items at first onSelect event and compare them in next onSelect event as follows:

private Set<Treeitem> originSelectedItems;

@Listen("onSelect = #tree")
public void onSelect(SelectEvent<Treeitem, String> event) {
    Set<Treeitem> currentSelectedItems = event.getSelectedItems();
    if (originSelectedItems == null)
        originSelectedItems = currentSelectedItems;
    // compare originSelectedItems and currentSelectedItems here to get deselected items.
}

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: 2012-12-27 05:23:56 +0800

Seen: 50 times

Last updated: Jan 02 '13

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