0

Expand all items of a Tree at start

asked 2009-08-21 07:48:28 +0800

mrego gravatar image mrego
63 1
http://blogs.igalia.com/m...

Hello,

I'm using the ZK Tree component, and I'd like that when the page is showed the first time the tree appears expanded.
The problem is that, by default, the tree always appears collapsed.

I've found this link Open treeitem at start , but it just explain how to open an element in the tree and not the whole tree.

I'd like to know if there's any option to expand the whole tree, or if it would be feasible to create a new function expandAll on Tree component.

Thanks,
Rego

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-08-21 20:48:51 +0800

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

You must modified to your needs.

	public void onClick$btnMainMenuExpandAll(Event event) throws Exception {

		if (logger.isDebugEnabled()) {
			logger.debug("--> " + event.toString());
		}
		doCollapseExpandAll(getMainMenuWindow(), true);
	}

	public void onClick$btnMainMenuCollapseAll(Event event) throws Exception {

		if (logger.isDebugEnabled()) {
			logger.debug("--> " + event.toString());
		}
		doCollapseExpandAll(getMainMenuWindow(), false);
	}

	private void doCollapseExpandAll(Component component, boolean aufklappen) {
		if (component instanceof Treeitem) {
			Treeitem treeitem = (Treeitem) component;
			treeitem.setOpen(aufklappen);
		}
		Collection<?> com = component.getChildren();
		if (com != null) {
			for (Iterator<?> iterator = com.iterator(); iterator.hasNext();) {
				doCollapseExpandAll((Component) iterator.next(), aufklappen);

			}
		}
	}

regards
Stephan

link publish delete flag offensive edit

answered 2009-08-21 21:55:50 +0800

jj gravatar image jj
638 3

If you are using zul to declaratively layout a tree, simply use open="true" on treeitem nodes.
If you are using a model with custom Renderer, in you renderer, call treeitem.setOpen(true) method.

-JJ

link publish delete flag offensive edit

answered 2009-08-24 06:02:30 +0800

mrego gravatar image mrego
63 1
http://blogs.igalia.com/m...

setOpen method of Treeitem works right ;-)

Thank you very much,
Rego

link publish delete flag offensive edit

answered 2010-06-06 21:46:36 +0800

linkia gravatar image linkia
15

A simpler answer:

void expandTree(Boolean expander){
Collection itm = myTree.getItems();
if (itm != null){
for (item : itm){
if (item instanceof Treeitem) {
Treeitem treeitem = (Treeitem) item;
treeitem.setOpen(expander);
}
}
}
}

link publish delete flag offensive edit

answered 2012-09-19 09:56:05 +0800

Curi gravatar image Curi
9

Hi, I want to expand the items of a tree as well, but I got a ConcurrentModificationException.

My problem is that I am trying to fetch a selected item with "getSelectedItems()" and it is on the "3rd level" of the tree, the "very last node".
As by default the tree is only opened up to the second level (the main nodes and their children), it returns no selected items.

I tried to render the tree completely and open all the nodes when it is loaded. I also tried the solutions posted here, with no success.
I have also tried with getTreechildren() and renderItemByPathApi(path), which both don't raise any exception but don't give the desired results.

Thanks in advance.

link publish delete flag offensive edit

answered 2012-10-02 14:02:23 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi terrytornado

Thank you very much for expand all and collapse all. It works well

link publish delete flag offensive edit

answered 2012-10-02 17:01:06 +0800

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

:-)

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-08-21 07:48:28 +0800

Seen: 1,844 times

Last updated: Oct 02 '12

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