package org.wicketTutorial.checkboxtree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import org.apache.wicket.Component;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;
import org.apache.wicket.extensions.markup.html.repeater.tree.content.CheckedFolder;
import org.apache.wicket.extensions.markup.html.repeater.tree.theme.WindowsTheme;
import org.apache.wicket.extensions.markup.html.repeater.util.TreeModelProvider;
import org.apache.wicket.markup.html.basic.Label;
import org.wicketTutorial.commons.bootstrap.layout.BootstrapBasePage;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
public class HomePage extends BootstrapBasePage {
private static final long serialVersionUID = 1L;
private NestedTree<DefaultMutableTreeNode> tree;
public HomePage(final PageParameters parameters) {
super(parameters);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Cities of Europe");
addNodes(addNodes(root, "Italy"), "Rome", "Venice", "Milan", "Florence");
addNodes(addNodes(root, "Germany"), "Stuttgart", "Munich", "Berlin", "Dusseldorf", "Dresden");
addNodes(addNodes(root, "France"), "Paris ", "Toulouse", "Strasbourg", "Bordeaux", "Lyon");
DefaultTreeModel treeModel = new DefaultTreeModel(root);
TreeModelProvider<DefaultMutableTreeNode> modelProvider = new TreeModelProvider<DefaultMutableTreeNode>(treeModel) {
@Override
public IModel<DefaultMutableTreeNode> model(DefaultMutableTreeNode object) {
return Model.of(object);
}
};
tree = new NestedTree<DefaultMutableTreeNode>("tree", modelProvider)
{
private static final long serialVersionUID = 1L;
@Override
protected Component newContentComponent(String id, IModel<DefaultMutableTreeNode> model)
{
return new CheckedFolder<DefaultMutableTreeNode>(id, this, model);
}
};
tree.add(new WindowsTheme());
add(tree);
}
protected NestedTree<DefaultMutableTreeNode> getTree() {
return tree;
}
@param
@param
@return
public static DefaultMutableTreeNode addNodes(DefaultMutableTreeNode parent, String... childrenNode){
DefaultMutableTreeNode newNode = null;
for (int i = 0; i < childrenNode.length; i++) {
newNode = new DefaultMutableTreeNode(childrenNode[i]);
parent.add(newNode);
}
return newNode;
}
}