Apache Wicket ile Tree Uygulaması
TestPage.html
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" xmlns="http://www.w3.org/1999/xhtml">
<body>
<table>
<div wicket:id="tree">
</div>
</table>
</body>
</html>
TestPage.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tree.Tree;
public class TestPage extends WebPage {
private static List items = new ArrayList();
static {
items.add(new AccordionItem("Title 1", "content 1.1", "content 1.2","content 1.3"));
items.add(new AccordionItem("Title 2", "content 2.1", "content 2.2"));
items.add(new AccordionItem("Title 3", "content 3.1"));
items.add(new AccordionItem("Title 4", "content 3.1", "content 3.2"));
}
public TestPage() {
DefaultMutableTreeNode root0 = new DefaultMutableTreeNode("Root");
final DefaultTreeModel treeModel = new DefaultTreeModel(root0);
for (AccordionItem accordionItem : items) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode(
accordionItem.title);
for (String s : accordionItem.childs) {
final DefaultMutableTreeNode rootChild = new DefaultMutableTreeNode(s);
root.add(rootChild);
}
root0.add(root);
}
final Tree tree = new Tree("tree", treeModel) {
private static final long serialVersionUID = 1L;
@Override
protected String renderNode(TreeNode node) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
return String.valueOf(treeNode.getUserObject());
}
@Override
protected void onNodeLinkClicked(AjaxRequestTarget target,
TreeNode node) {
super.onNodeLinkClicked(target, node);
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
System.out.println(treeNode.getUserObject());
}
};
tree.getTreeState().expandNode(root0);
add(tree);
}
public static class AccordionItem {
private String title;
private List childs;
public AccordionItem(String title, String... content) {
this.title = title;
this.childs = Arrays.asList(content);
}
}
}
pom.xml
<dependency> <groupId>org.apache.wicket</groupId>
<artifactId>wicket-spring</artifactId>
<version>1.5.11</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-datetime</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-auth-roles</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-devutils</artifactId>
<version>1.5.11</version>
</dependency>