KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > administrator > nodes > AdministratorTreeNode


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.administrator.nodes;
31
32 import javax.swing.ImageIcon JavaDoc;
33 import javax.swing.RepaintManager JavaDoc;
34 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
35 import javax.swing.tree.DefaultTreeModel JavaDoc;
36 import javax.swing.tree.TreePath JavaDoc;
37
38 import com.genimen.djeneric.repository.DjPersistenceManager;
39 import com.genimen.djeneric.repository.DjSession;
40 import com.genimen.djeneric.tools.administrator.editors.AdminEditor;
41 import com.genimen.djeneric.tools.administrator.helpers.AdminPanel;
42
43 public abstract class AdministratorTreeNode extends DefaultMutableTreeNode JavaDoc
44 {
45   public boolean _alreadyLoaded = false;
46   protected AdministratorTree _tree;
47
48   public AdministratorTreeNode()
49   {
50     _tree = null;
51   }
52
53   public void setTree(AdministratorTree tree)
54   {
55     _tree = tree;
56   }
57
58   public abstract String JavaDoc toString();
59
60   public DefaultTreeModel JavaDoc getModel()
61   {
62     return (DefaultTreeModel JavaDoc) _tree.getModel();
63   }
64
65   public DjPersistenceManager getManager()
66   {
67     return _tree.getManager();
68   }
69
70   public DjSession createSession() throws Exception JavaDoc
71   {
72     return getManager().createSession();
73   }
74
75   public AdministratorTreeNode getParentTreeNode()
76   {
77     return (AdministratorTreeNode) getParent();
78   }
79
80   private void copyInternalReferences(AdministratorTreeNode node)
81   {
82     node.setTree(_tree);
83   }
84
85   public void insertAsChild(AdministratorTreeNode node)
86   {
87     getModel().insertNodeInto(node, this, getChildCount());
88     copyInternalReferences(node);
89   }
90
91   public void insertAsFolder(AdministratorTreeNode node)
92   {
93     getModel().insertNodeInto(node, this, getChildCount());
94     getModel().insertNodeInto(new DefaultMutableTreeNode JavaDoc(), node, 0);
95     copyInternalReferences(node);
96   }
97
98   public void insertAsSibling(AdministratorTreeNode node)
99   {
100     getModel().insertNodeInto(node, parent, parent.getChildCount());
101     copyInternalReferences(node);
102   }
103
104   public void removeFromTree()
105   {
106     getModel().removeNodeFromParent(this);
107   }
108
109   public void repaintTree()
110   {
111     RepaintManager JavaDoc rm = RepaintManager.currentManager(_tree);
112     if (rm != null)
113     {
114       rm.validateInvalidComponents();
115       rm.paintDirtyRegions();
116     }
117   }
118
119   public void reloadParent() throws Exception JavaDoc
120   {
121     AdministratorTreeNode p = getParentTreeNode();
122     if (p != null) p.reload();
123   }
124
125   public void expandAll()
126   {
127     _tree.expandPath(new TreePath JavaDoc(this.getPath()));
128     int cc = getChildCount();
129     for (int i = 0; i < cc; i++)
130     {
131       AdministratorTreeNode child = (AdministratorTreeNode) getChildAt(i);
132       child.expandAll();
133     }
134   }
135
136   public void collapseAll()
137   {
138     int cc = getChildCount();
139     for (int i = 0; i < cc; i++)
140     {
141       AdministratorTreeNode child = (AdministratorTreeNode) getChildAt(i);
142       child.collapseAll();
143     }
144     _tree.collapsePath(new TreePath JavaDoc(this.getPath()));
145   }
146
147   public AdminEditor getEditor(AdminPanel admin)
148   {
149     return null;
150   }
151
152   public AdminEditor getCreateEditor(AdminPanel admin) throws Exception JavaDoc
153   {
154     return null;
155   }
156
157   public boolean canImport()
158   {
159     return false;
160   }
161
162   public boolean canExport()
163   {
164     return false;
165   }
166
167   public boolean canClear()
168   {
169     return false;
170   }
171
172   public abstract boolean canEdit();
173
174   public abstract boolean canCreate();
175
176   public abstract boolean canDelete();
177
178   public abstract void reload() throws Exception JavaDoc;
179
180   public abstract void expandNode() throws Exception JavaDoc;
181
182   public abstract ImageIcon JavaDoc getImageIcon();
183
184   public abstract void delete() throws Exception JavaDoc;
185
186   public abstract String JavaDoc getNodeType();
187
188   public ImageIcon JavaDoc getObjectImageIcon()
189
190   {
191     return getImageIcon();
192   }
193
194 }
Popular Tags