KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > common > DefaultTreeView


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jérôme Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.common;
28
29 /** The Browsr API's imports */
30 import java.io.Serializable JavaDoc;
31
32 import org.objectweb.util.browser.api.Entry;
33 import org.objectweb.util.browser.api.Tree;
34 import org.objectweb.util.browser.core.api.ExtendedEntry;
35 import org.objectweb.util.browser.core.api.ExtendedTreeView;
36 import org.objectweb.util.browser.core.api.TreeConfiguration;
37
38 /**
39  * Offers a limited view on the tree
40  *
41  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
42  * @version 0.1
43  */

44 public class DefaultTreeView
45   implements ExtendedTreeView, Serializable JavaDoc
46 {
47
48     // ==================================================================
49
//
50
// Internal states.
51
//
52
// ==================================================================
53

54     /** The associated tree */
55     protected DynamicTree tree_;
56
57     /** The selected entry and his parent */
58     protected Entry entry_, parent_;
59
60     /** The handle object */
61     protected Object JavaDoc handleObject_;
62
63     // ==================================================================
64
//
65
// Constructors.
66
//
67
// ==================================================================
68

69     /**
70      * Default Constuctor
71      * @param tree The associated tree
72      */

73     public DefaultTreeView(DynamicTree tree) {
74         tree_ = tree;
75         entry_ = tree_.getSelectedEntry();
76         parent_ = tree_.getSelectedEntryParent();
77     }
78
79     /**
80      * Constructor with params (used by popup in <code>JTable</code>).
81      * @param tree The associated tree
82      * @param entry The entry to use as selectedEntry, then, the parent entry is null.
83      */

84     public DefaultTreeView(DynamicTree tree, Entry entry) {
85         tree_ = tree;
86         entry_ = entry;
87         parent_ = null;
88     }
89
90     // ==================================================================
91
//
92
// Protected methods.
93
//
94
// ==================================================================
95

96     /**
97      * @param entry The entry on which you want to obtain the value
98      * @return The associated value of the entry
99      */

100     protected Object JavaDoc getValue(Entry entry) {
101         if (entry != null)
102             return (((ExtendedEntry) entry).getWrappedObject());
103         return null;
104     }
105
106     // ==================================================================
107
//
108
// Public methods.
109
//
110
// ==================================================================
111

112 // /**
113
// * Refresh the selected node
114
// */
115
// public void refresh() {
116
// tree_.refreshSelectedNode();
117
// }
118

119     /**
120      * Gives the way to configure the tree
121      * @return The entry to configure the tree
122      */

123     public TreeConfiguration getTreeConfiguration() {
124         return (TreeConfiguration) tree_;
125     }
126
127     /**
128      * Returns the current selected Entry.
129      */

130     public Entry getSelectedEntry() {
131         return entry_;
132     }
133
134     /**
135      * Returns the parent entry
136      */

137     public Entry getParentEntry() {
138         return parent_;
139     }
140
141     /**
142      * Returns the wrapped object of value of the associated Entry
143      */

144     public Object JavaDoc getSelectedObject() {
145         return getValue(entry_);
146     }
147
148     /**
149      * Returns the parent object
150      */

151     public Object JavaDoc getParentObject() {
152         return getValue(parent_);
153     }
154
155     /**
156      * Returns an object to manipulate the Tree.
157      */

158     public Tree
159     getTree(){
160         return (Tree)tree_;
161     }
162     
163 }
164
Popular Tags