KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openedit > links > webtree > LinkTreeModel


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package org.openedit.links.webtree;
14
15 import java.util.List JavaDoc;
16
17 import org.openedit.links.Link;
18 import org.openedit.links.LinkTree;
19
20 import com.openedit.webui.tree.DefaultWebTreeModel;
21
22
23 /**
24  * This model represents a tree of site content.
25  *
26  * @author Matt Avery, mavery@einnovation.com
27  */

28 public class LinkTreeModel extends DefaultWebTreeModel
29 {
30     protected LinkTree fieldLinkTree;
31     protected String JavaDoc fieldRootPath;
32     long lastMod = 1001;
33
34     /**
35      * Constructor for PageTreeModel.
36      *
37      * @param inSiteContext DOCUMENT ME!
38      */

39     public LinkTreeModel(LinkTree inLinkTree)
40     {
41         this( inLinkTree, null);
42     }
43
44     public LinkTreeModel( LinkTree inLinkTree, String JavaDoc inRootPath )
45     {
46         super();
47         fieldLinkTree = inLinkTree;
48         fieldRootPath = inRootPath;
49     }
50
51
52     /* (non-Javadoc)
53      * @see TreeModel#getRoot()
54      */

55     public Object JavaDoc getRoot()
56     {
57         if (fieldRoot == null )
58         {
59             reload();
60         }
61
62         return fieldRoot;
63     }
64
65     public List JavaDoc getChildren(Object JavaDoc parent)
66     {
67 // if( getLinkTree().getLastModified() != lastMod )
68
// {
69
// reload();
70
// }
71
return super.getChildren(parent);
72     }
73
74     /**
75      * Find the page tree node at the given path. This method will not automatically expand any
76      * node in the tree if it is not already expanded.
77      *
78      * @param inPath The path (e.g. "abc/def/ghi.html")
79      *
80      * @return The node at the given path, or <code>null</code> if no node could be found that
81      * matched the given path
82      */

83     public LinkNode findNode(String JavaDoc inPath)
84     {
85         return ((LinkNode) getRoot()).findNode(inPath);
86     }
87
88     /**
89          *
90          */

91     public void reload()
92     {
93         Link rootItem;
94         if( getRootPath() == null)
95         {
96             rootItem = getLinkTree().getRootLink();
97         }
98         else
99         {
100             rootItem = getLinkTree().getLink( getRootPath() );
101         }
102         LinkNode newRoot = new LinkNode( rootItem);
103         fieldRoot = newRoot;
104         lastMod = getLinkTree().getLastModified();
105     }
106     /**
107      * @param inString
108      */

109     public void ignore(String JavaDoc inString)
110     {
111         LinkNode node = (LinkNode)getRoot();
112         node.getIgnoreTypes().add( inString);
113     }
114     public LinkTree getLinkTree()
115     {
116         return fieldLinkTree;
117     }
118     public void setLinkTree( LinkTree LinkTree )
119     {
120         fieldLinkTree = LinkTree;
121     }
122     public String JavaDoc getRootPath()
123     {
124         return fieldRootPath;
125     }
126     public void setRootPath( String JavaDoc rootPath )
127     {
128         fieldRootPath = rootPath;
129     }
130 }
131
Popular Tags