KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > webui > tree > RepositoryTreeModel


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 com.openedit.webui.tree;
14
15 import org.openedit.repository.ContentItem;
16 import org.openedit.repository.Repository;
17 import org.openedit.repository.RepositoryException;
18
19 import com.openedit.OpenEditException;
20 import com.openedit.OpenEditRuntimeException;
21 import com.openedit.PageAccessListener;
22 import com.openedit.page.Page;
23
24
25 /**
26  * This model represents a tree of site content.
27  *
28  * @author Matt Avery, mavery@einnovation.com
29  */

30 public class RepositoryTreeModel extends DefaultWebTreeModel implements PageAccessListener
31 {
32     protected Repository fieldRepository;
33     protected String JavaDoc fieldRootPath;
34
35
36     /**
37      * Constructor for PageTreeModel.
38      *
39      * @param inSiteContext DOCUMENT ME!
40      */

41     public RepositoryTreeModel(Repository inRepository)
42     {
43         this( inRepository, "/");
44     }
45
46     public RepositoryTreeModel( Repository inRepository, String JavaDoc inRootPath )
47     {
48         super();
49         fieldRepository = inRepository;
50         fieldRootPath = inRootPath;
51     }
52
53
54     /* (non-Javadoc)
55      * @see TreeModel#getRoot()
56      */

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

77     public RepositoryTreeNode findNode(String JavaDoc inPath)
78     {
79         return ((RepositoryTreeNode) getRoot()).findNode(inPath);
80     }
81
82     /**
83          *
84          */

85     public void reload()
86     {
87         ContentItem rootItem;
88         try
89         {
90             rootItem = getRepository().get( getRootPath() );
91         }
92         catch( RepositoryException e )
93         {
94              throw new OpenEditRuntimeException(e);
95         }
96         RepositoryTreeNode newRoot = new RepositoryTreeNode( getRepository(), rootItem);
97         fieldRoot = newRoot;
98         
99     }
100     /**
101      * @param inString
102      */

103     public void ignore(String JavaDoc inString)
104     {
105         RepositoryTreeNode node = (RepositoryTreeNode)getRoot();
106         node.getIgnoreTypes().add( inString);
107     }
108     public Repository getRepository()
109     {
110         return fieldRepository;
111     }
112     public void setRepository( Repository repository )
113     {
114         fieldRepository = repository;
115     }
116     public String JavaDoc getRootPath()
117     {
118         return fieldRootPath;
119     }
120     public void setRootPath( String JavaDoc rootPath )
121     {
122         fieldRootPath = rootPath;
123     }
124
125
126     /**
127      * DOCUMENT ME!
128      *
129      * @param inPage
130      * @param inRevision
131      *
132      * @throws OpenEditException
133      */

134     public void pageAdded(Page inPage)
135     {
136         reload();
137     }
138
139     /**
140      * DOCUMENT ME!
141      *
142      * @param inPage
143      * @param inRevision
144      *
145      * @throws OpenEditException
146      */

147     public void pageModified(Page inPage)
148     {
149         reload();
150     }
151
152     /**
153      * DOCUMENT ME!
154      *
155      * @param inPage
156      * @param inRevision
157      *
158      * @throws OpenEditException
159      */

160     public void pageRemoved(Page inPage)
161     {
162         reload();
163     }
164
165     /**
166      * DOCUMENT ME!
167      *
168      * @param inPage
169      *
170      * @throws OpenEditException
171      */

172     public void pageRequested(Page inPage)
173     {
174         // do nothing
175
}
176 }
177
Popular Tags