0

tree selection

asked 2012-09-25 07:49:32 +0800

avidD gravatar image avidD
166 2

Hello,
I have a tree with many treeitems. I now expand some nodes and make a multiple selection on some nodes which have children using the shift key. Unfortunately, the children are selected as well. This is not the correct behavior as the children are not visible at all. In effect, the semantics of the following operation is broken. For instance
* select 20 nodes using shift
* the tree selection contains 60 nodes
* press copy (copying 60 instead of the intended 20 nodes)
* paste ("flattens" the hierarchy, resp. duplicates erroneously selected children)

Can this behavior be turned off somehow?

Cheers,
David

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-09-25 08:15:12 +0800

avidD gravatar image avidD
166 2

Hi,
I now traverse the selection and remove those nodes that may be selected erroneously.

private Set<Treeitem> removeInvisibleNodes(Set<Treeitem> selection) {
    Set<Treeitem> visibleSelection = new HashSet<Treeitem>();
    for ( Treeitem item : selection ) {
      boolean visible = true;
      Treeitem current = item.getParentItem();
      while ( current != null && visible ) {
        visible = current.isOpen();
        current = current.getParentItem(); 
      } 
      if ( visible ) {
        visibleSelection.add(item);
      }
    }
    return java.util.Collections.unmodifiableSet(visibleSelection);
  }

However, this is not the correct behavior either because the user can very well select a node and then collapse its parent. Actually, the current behavior is a show-stopper for the feature. In fact, this is what the built-in Event-handler should do when shift is pressed instead of silently selecting invible nodes.

Help would be highly appreciated.

Thanks beforehand,
David

link publish delete flag offensive edit

answered 2012-10-11 10:54:59 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi David,
So you need to use shift select and do not select invisible children nodes, is it correct?

link publish delete flag offensive edit

answered 2012-10-11 17:55:01 +0800

avidD gravatar image avidD
166 2

Hi Jimmy,
yes, that's what I am planning to do. Is this somehow configurable?

Cheers,
David

link publish delete flag offensive edit

answered 2012-10-12 03:00:29 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2012-10-12 03:00:39 +0800

Hi David,
There is no configuration for tree selection, but you can try to override the client function of the Tree, please refer to the following sample

tree.setWidgetOverride("getBodyWidgetIterator", 
	"function (opts) {opts = opts || {};opts.skipHidden=true;return new zul.sel.TreeItemIter(this, opts);}");

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-09-25 07:49:32 +0800

Seen: 93 times

Last updated: Oct 12 '12

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