<%@ page import="com.jenkov.prizetags.tree.itf.ITree,
                 com.jenkov.prizetags.tree.impl.Tree,
                 com.jenkov.prizetags.tree.itf.ITreeNode,
                 com.jenkov.prizetags.tree.impl.TreeNode"%>
<%@ page import="com.jenkov.prizetags.tree.itf.INodeMatcher"%>
<%@ page import="com.jenkov.prizetags.tree.itf.ITreeIteratorElement"%>
<%@ page import="com.jenkov.prizetags.tree.impl.TreeSorter"%>
<%@ page import="java.util.Comparator"%>
<%@ taglib uri="/WEB-INF/treetag.tld" prefix="tree" %>
<%@ taglib uri="/WEB-INF/requesttags.tld" prefix="request" %>

<%
if(session.getAttribute("tree.model") == null){
   ITree tree = new Tree();
                                 //(node id    , node name        , node type)
   ITreeNode root    = new TreeNode("rootId"   , "Servers"        , "root");
   ITreeNode server1 = new TreeNode("server1Id", "Exchange Server", "server");
   ITreeNode server2 = new TreeNode("server2Id", "Notes Server"   , "server");

   ITreeNode user1   = new TreeNode("user1Id"  , "Peter Johnson"  , "user");
   ITreeNode user2   = new TreeNode("user1Id"  , "Jakob Jenkov"   , "user");


   root.addChild(server1);
   root.addChild(server2);

   server1. addChild(user1);
   server2. addChild(user1);
   server2. addChild(user2);

   server1.setToolTip("This is a tool tip");

   server1.setObject(" - extra info ");

   tree.setRoot(root);

   session.setAttribute("tree.model", tree);

}
    request.setAttribute("myMatcher", new INodeMatcher(){
        public boolean matches(ITreeIteratorElement nodeElement) {
            return nodeElement.getName().toLowerCase().startsWith("n");
        }
    });

%>

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

<table cellspacing="0" cellpadding="0" border="0">
<tree:tree tree="tree.model"  node="tree.node" includeRootNode="true">
    <tr>
      <td>
        <table cellspacing="0" cellpadding="0" border="0"><tr>
        <td><tree:nodeIndent    node="tree.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>
        <td>
            <tree:nodeMatch node="tree.node" hasChildren="true" expanded="false" isLastChild="false">
                 <a href="<request:requestUri/>?expand=<tree:nodeId node="tree.node"/>"><img
                     src="../images/collapsedMidNode.gif" border="0"></a>
            </tree:nodeMatch>
            <tree:nodeMatch node="tree.node" hasChildren="true" expanded="true" isLastChild="false">
                 <a href="<request:requestUri/>?collapse=<tree:nodeId node="tree.node"/>"><img
                     src="../images/expandedMidNode.gif" border="0"></a>
            </tree:nodeMatch>
            <tree:nodeMatch node="tree.node" hasChildren="true" expanded="false" isLastChild="true">
                 <a href="<request:requestUri/>?expand=<tree:nodeId node="tree.node"/>"><img
                     src="../images/collapsedLastNode.gif" border="0"></a>
            </tree:nodeMatch>
            <tree:nodeMatch node="tree.node" hasChildren="true" expanded="true" isLastChild="true">
                 <a href="<request:requestUri/>?collapse=<tree:nodeId node="tree.node"/>"><img
                     src="../images/expandedLastNode.gif" border="0"></a>
            </tree:nodeMatch>
            <tree:nodeMatch node="tree.node" hasChildren="false" isLastChild="false">
                <img src="../images/noChildrenMidNode.gif" border="0">
            </tree:nodeMatch>
            <tree:nodeMatch node="tree.node" hasChildren="false" isLastChild="true">
                <img src="../images/noChildrenLastNode.gif" border="0">
            </tree:nodeMatch>
            </td>

        <tree:nodeMatch node="tree.node" hasChildren="true" expanded="true"><td><img src="../images/openFolder.gif"/></td></tree:nodeMatch>
        <tree:nodeMatch node="tree.node" hasChildren="true" expanded="false"><td><img src="../images/closedFolder.gif"/></td></tree:nodeMatch>
        <tree:nodeMatch node="tree.node" hasChildren="false" ><td><img src="../images/nonFolder.gif"/></td></tree:nodeMatch>

        <td><a href="www.jenkov.com" title="<tree:nodeToolTip node="tree.node"/>"><tree:nodeName  node="tree.node"/></a></td>
        <%--<tree:nodeMatch node="tree.node" matcherName="myMatcher"><td>Yes</td></tree:nodeMatch>--%>
        <%--<tree:nodeNoMatch node="tree.node" matcherName="myMatcher"><td>No</td></tree:nodeNoMatch>--%>
        <td>
        <tree:detachNodeObject node="tree.node" detachedObject="theNodeObject"/>
        <%  if(request.getAttribute("theNodeObject") != null){
           out.print(request.getAttribute("theNodeObject"));
        }
        %>
        </td>
        </tr></table></td>
    </tr>
</tree:tree>
</table>
</body>
</html>