
<%@ page import="com.jenkov.prizetags.tree.impl.TreeNode,
                 com.jenkov.prizetags.tree.impl.Tree,
                 com.jenkov.prizetags.tree.itf.*" %>
<%@ page import="com.jenkov.prizetags.tree.impl.TreeSorter"%>
<%@ page import="com.jenkov.prizetags.tree.impl.FileDao"%>
<%@ page import="java.io.File"%>
<%@ taglib uri="/WEB-INF/treetag.tld" prefix="tree" %>
<%@ taglib uri="/WEB-INF/requesttags.tld" prefix="request" %>
<%
    if(session.getAttribute("example") == null){

        //creating a simple tree model instance
        ITree       tree          = new Tree();
        tree.setSingleSelectionMode(true);
//        tree.setTreeDao(new FileDao(new File("./webapps/prizetagsdemo")));
        tree.setTreeDao(new FileDao(new File(".")));

        //storing the tree model instance in the session.
        //this is where the tags get the tree model from later.
        session.setAttribute("example", tree);
//        request.setAttribute("example", tree);
    }

%>
<html>
<head>
    <title>Tree Tag - Single Page - (C) 2004 Jenkov Development</title>
    <link rel="stylesheet" href="/prizetagsdemo/stylesheet.css" type="text/css">
</head>


<body>
<h2>Tree Using ITreeDao</h2>

This JSP page demonstrates how to use the ITreeDao to dynamically (and lazily) load the nodes of
a tree. The demo uses a FileDao which reads the nodes from the file system.

<br/><br/>
You can implement your
own ITreeDao to read nodes from whereever you need to... database, XML DOM trees, JNDI etc.
The ITreeDao interface is simple. It only contains two methods.


<br/><br/>

<table cellspacing="0" cellpadding="5" style="border: 1 solid black;">

<tr><td valign="top">

        <%-- Generating the Tree HTML --%>
        <table cellspacing="0" cellpadding="0" border="0">
        <tree:tree tree="example" node="example.node" includeRootNode="true">
            <tr><td
            ><table cellspacing="0" cellpadding="0" border="0">
            <tr><td><tree:nodeIndent    node="example.node" indentationType="type"><tree:nodeIndentVerticalLine indentationType="type" ><img src="../images/verticalLine.gif"></tree:nodeIndentVerticalLine><tree:nodeIndentBlankSpace   indentationType="type" ><img src="../images/blankSpace.gif"></tree:nodeIndentBlankSpace></tree:nodeIndent></td>
            <tree:nodeMatch    node="example.node" expanded="false" hasChildren="true"  isLastChild="false"><td><a href="<request:requestUri/>?expand=<tree:nodeId node="example.node"/>"><img src="../images/collapsedMidNode.gif" border="0"></a><img src="../images/closedFolder.gif"></td></tree:nodeMatch>
            <tree:nodeMatch    node="example.node" expanded="true"  hasChildren="true"  isLastChild="false"><td><a href="<request:requestUri/>?collapse=<tree:nodeId node="example.node"/>"><img src="../images/expandedMidNode.gif"  border="0"></a><img src="../images/openFolder.gif"></td></tree:nodeMatch>
            <tree:nodeMatch    node="example.node" expanded="false" hasChildren="true"  isLastChild="true" ><td><a href="<request:requestUri/>?expand=<tree:nodeId node="example.node"/>"><img src="../images/collapsedLastNode.gif"  border="0"></a><img src="../images/closedFolder.gif"></td></tree:nodeMatch>
            <tree:nodeMatch    node="example.node" expanded="true"  hasChildren="true"  isLastChild="true" ><td><a href="<request:requestUri/>?collapse=<tree:nodeId node="example.node"/>"><img src="../images/expandedLastNode.gif" border="0"></a><img src="../images/openFolder.gif"></td></tree:nodeMatch>
            <tree:nodeMatch    node="example.node" expanded="false" hasChildren="false" isLastChild="false"><td><img src="../images/noChildrenMidNode.gif"><img src="../images/nonFolder.gif"></td></tree:nodeMatch>
            <tree:nodeMatch    node="example.node" expanded="false" hasChildren="false" isLastChild="true" ><td><img src="../images/noChildrenLastNode.gif"><img src="../images/nonFolder.gif"></td></tree:nodeMatch>

            <td valign="top">
            <tree:nodeMatch node="example.node" selected="true"><span style="Font-Size: 12px;"><b><tree:nodeName      node="example.node"/></b></span></tree:nodeMatch>
            <tree:nodeMatch node="example.node" selected="false"><a href="<request:requestUri/>?select=<tree:nodeId node="example.node"/>"><span style="Font-Size: 12px;"><tree:nodeName      node="example.node"/></span></a></tree:nodeMatch>

            </td>
            </tr>
            </table></td></tr>
        </tree:tree>
        </table>
    </td>
    <td valign="top" style="border-left: 1 solid black;">
        Selected Node Detail:<br/><br/>

        <%
            ITree tree = (ITree) session.getAttribute("example");
            ITreeNode node = new TreeNode(); //empty node, displayed when the tree isn't initialized yet.
            if(tree != null && request.getParameter("select") != null){
                node = tree.findNode(request.getParameter("select"));
            }
        %>
        <table cellspacing="0" cellpadding="5">
            <tr><td>Id  </td><td><%=node.getId()%></td></tr>
            <tr><td>Name</td><td><%=node.getName()%></td></tr>
            <tr><td>Type</td><td><%=node.getType()%></td></tr>
        </table>


    </td>
</tr>
</table>

</body>

</html>