package org.wicketTutorial;
import java.util.Iterator;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.tree.AbstractTree;
import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;
import org.apache.wicket.extensions.markup.html.repeater.tree.content.CheckedFolder;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;


public class AutocheckedFolder<T> extends CheckedFolder<T> {

	private ITreeProvider<T> treeProvider;
	private boolean selected;
	
	public AutocheckedFolder(String id, AbstractTree<T> tree, IModel<T> model) {
		super(id, tree, model);	
		this.treeProvider = tree.getProvider();
	}
	
	@Override
	protected IModel<Boolean> newCheckBoxModel(IModel<T> model) {
		return new PropertyModel<Boolean>(this, "selected");
	}
	
	@Override
	protected void onUpdate(AjaxRequestTarget target) {
		super.onUpdate(target);
		System.out.println("let's see!");
		
		if(isSelected())
		{
			T node = getModelObject();
			Iterator<? extends T> childrenNodes = treeProvider.getChildren(node);
			System.out.println("SELECTED!");
		}
	}
}

@@ -47,16 +47,38 @@
 terator;
+%0Aimport java.util.Set;
 %0A%0Aimport
@@ -564,24 +564,62 @@
 boolean 
-selected
+nodeChecked;%0A%09private IModel%3CSet%3CT%3E%3E treeModel
 ;%0A%09%0A%09pub
@@ -761,16 +761,52 @@
 ider();%0A
+%09%09this.treeModel = tree.getModel();%0A
 %09%7D%0A%09%0A%09@O
@@ -923,14 +923,17 @@
 s, %22
-select
+nodeCheck
 ed%22)
@@ -1035,62 +1035,25 @@
 ;%0A%09%09
-System.out.println(%22let's see!%22);%0A%09%09%0A%09%09if(isSelect
+%0A%09%09if(nodeCheck
 ed
-()
 )%0A%09%09
@@ -1091,117 +1091,308 @@
 %0A%09%09%09
-Iterator%3C? extends T%3E childrenNodes = treeProvider.getChildren(node);%0A%09%09%09System.out.println(%22SELECTED!%22);%0A%09%09%7D
+addRemoveSubNodes(node);%0A%09%09%7D%0A%09%7D%0A%09%0A%09private void addRemoveSubNodes(T node) %7B%0A%09%09Iterator%3C? extends T%3E childrenNodes = treeProvider.getChildren(node);%0A%09%09%0A%09%09while (childrenNodes.hasNext()) %7B%0A%09%09%09T childNode = childrenNodes.next();%0A%09%09%09addRemoveSubNodes(childNode);%0A%09%09%7D%0A%09%09%0A%09%09treeModel.getObject().add(node);
 %0A%09%7D%0A

Work in progress...