KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MTreeNode


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.sql.*;
17 import java.text.*;
18 import java.util.*;
19 import javax.swing.*;
20 import javax.swing.tree.*;
21
22 import org.compiere.util.*;
23
24 /**
25  * Mutable Tree Node.
26  *
27  * @author Jorg Janke
28  * @version $Id: MTreeNode.java,v 1.1 2003/02/14 06:43:42 jjanke Exp $
29  */

30 public final class MTreeNode extends DefaultMutableTreeNode
31 {
32     /**
33      * Construct Model TreeNode
34      * @param node_ID node
35      * @param seqNo sequence
36      * @param name name
37      * @param description description
38      * @param parent_ID parent
39      * @param isSummary summary
40      * @param imageIndicator image indicator
41      * @param onBar on bar
42      */

43     public MTreeNode (int node_ID, int seqNo, String JavaDoc name, String JavaDoc description,
44         int parent_ID, boolean isSummary, String JavaDoc imageIndicator, boolean onBar)
45     {
46         super();
47     // Log.trace(Log.l6_Database, "MTreeNode Node_ID=" + node_ID + ", Parent_ID=" + parent_ID + " - " + name);
48
m_node_ID = node_ID;
49         m_seqNo = seqNo;
50         m_name = name;
51         m_description = description;
52         if (m_description == null)
53             m_description = "";
54         m_parent_ID = parent_ID;
55         setSummary(isSummary);
56         setImageIndicator(imageIndicator);
57         m_onBar = onBar;
58     } // MTreeNode
59

60     /** Node ID */
61     private int m_node_ID;
62     /** SeqNo */
63     private int m_seqNo;
64     /** Name */
65     private String JavaDoc m_name;
66     /** Description */
67     private String JavaDoc m_description;
68     /** Parent ID */
69     private int m_parent_ID;
70     /** Summaty */
71     private boolean m_isSummary;
72     /** Image Indicator */
73     private String JavaDoc m_imageIndicator;
74     /** Index to Icon */
75     private int m_imageIndex = 0;
76     /** On Bar */
77     private boolean m_onBar;
78
79     /*************************************************************************/
80
81     public static int TYPE_WINDOW = 1;
82     public static int TYPE_REPORT = 2;
83     public static int TYPE_PROCESS = 3;
84     public static int TYPE_WORKFLOW = 4;
85     public static int TYPE_WORKBENCH = 5;
86
87     /** Icons */
88     public static Icon[] IMAGES = new Icon[]
89     {
90         null,
91         Env.getImageIcon("mWindow.gif"),
92         Env.getImageIcon("mReport.gif"),
93         Env.getImageIcon("mProcess.gif"),
94         Env.getImageIcon("mWorkFlow.gif"),
95         Env.getImageIcon("mWorkbench.gif")
96     };
97
98     /*************************************************************************/
99
100     /**
101      * Get Node ID
102      * @return node id
103      */

104     public int getID()
105     {
106         return m_node_ID;
107     } // getID
108

109     /**
110      * Set Name
111      * @param name name
112      */

113     public void setName (String JavaDoc name)
114     {
115         if (name == null)
116             m_name = "";
117         else
118             m_name = name;
119     } // setName
120

121     /**
122      * Get Name
123      * @return name
124      */

125     public String JavaDoc getName()
126     {
127         return m_name;
128     } // setName
129

130     /**
131      * Get SeqNo (Index) as formatted String 0000 for sorting
132      * @return SeqNo as String
133      */

134     public String JavaDoc getSeqNo()
135     {
136         String JavaDoc retValue = "0000" + m_seqNo; // not more than 100,000 nodes
137
if (m_seqNo > 99999)
138             Log.error("MTreeNode.getIndex - TreeNode Index is higher than 99999");
139         if (retValue.length() > 5)
140             retValue = retValue.substring(retValue.length()-5); // last 5
141
return retValue;
142     } // getSeqNo
143

144     /**
145      * Return parent
146      * @return Parent_ID
147      */

148     public int getParent_ID()
149     {
150         return m_parent_ID;
151     } // getParent
152

153     /**
154      * Print Name
155      * @return info
156      */

157     public String JavaDoc toString()
158     {
159         return // m_node_ID + "/" + m_parent_ID + " " + m_seqNo + " - " +
160
m_name;
161     } // toString
162

163     /**
164      * Get Description
165      * @return description
166      */

167     public String JavaDoc getDescription()
168     {
169         return m_description;
170     } // getDescription
171

172     /*************************************************************************/
173
174     /**
175      * Set Summary (allow children)
176      * @param isSummary summary node
177      */

178     public void setSummary (boolean isSummary)
179     {
180         m_isSummary = isSummary;
181         super.setAllowsChildren(isSummary);
182     } // setSummary
183

184     /**
185      * Set Summary (allow children)
186      * @param isSummary true if summary
187      */

188     public void setAllowsChildren (boolean isSummary)
189     {
190         super.setAllowsChildren (isSummary);
191         m_isSummary = isSummary;
192     } // setAllowsChildren
193

194     /**
195      * Allow children to be added to this node
196      * @return true if summary node
197      */

198     public boolean isSummary()
199     {
200         return m_isSummary;
201     } // isSummary
202

203     /**
204      * Does the node have Summary Node children
205      * @return true if the node has children
206      *
207     public boolean hasSummaryChildren()
208     {
209         int noChildren = getChildCount();
210         if (noChildren == 0)
211             return false;
212         // check just first
213         VTreeNode child = (VTreeNode)getChildAt(0); // get first child
214
215         return child.isSummary();
216     } // hasSummaryChildren
217
218     /*************************************************************************/

219
220     /**
221      * Set Image Indicator/Index
222      * @param imageIndicator image indicator (W/X/R/P/F/T/B)
223      * @return image index
224      */

225     public static int getImageIndex (String JavaDoc imageIndicator)
226     {
227         int imageIndex = 0;
228         if (imageIndicator == null)
229             ;
230         // Menu.Action
231
else if (imageIndicator.equals("W") || imageIndicator.equals("X")) // Window
232
imageIndex = TYPE_WINDOW;
233         else if (imageIndicator.equals("R")) // Report
234
imageIndex = TYPE_REPORT;
235         else if (imageIndicator.equals("P")) // Process
236
imageIndex = TYPE_PROCESS;
237         else if (imageIndicator.equals("F")) // WorkFlow
238
imageIndex = TYPE_WORKFLOW;
239         else if (imageIndicator.equals("T")) // Task
240
;
241         else if (imageIndicator.equals("B")) // Workbench
242
imageIndex = TYPE_WORKBENCH;
243         return imageIndex;
244     } // getImageIndex
245

246     /**
247      * Set Image Indicator and Index
248      * @param imageIndicator image indicator (W/X/R/P/F/T/B)
249      */

250     public void setImageIndicator (String JavaDoc imageIndicator)
251     {
252         if (imageIndicator != null)
253         {
254             m_imageIndicator = imageIndicator;
255             m_imageIndex = getImageIndex(m_imageIndicator);
256         }
257     } // setImageIndicator
258

259     /**
260      * Get Image Indicator
261      * @return image indicator
262      */

263     public String JavaDoc getImageIndiactor()
264     {
265         return m_imageIndicator;
266     } // getImageIndiactor
267

268     /**
269      * Get Image Icon
270      * @param index image index
271      * @return Icon
272      */

273     public static Icon getIcon (int index)
274     {
275         if (index == 0 || IMAGES == null || index > IMAGES.length)
276             return null;
277         return IMAGES[index];
278     } // getIcon
279

280     /**
281      * Get Image Icon
282      * @return Icon
283      */

284     public Icon getIcon()
285     {
286         return getIcon(m_imageIndex);
287     } // getIcon
288

289     /**
290      * Get Shortcut Bar info
291      * @return true if node on bar
292      */

293     public boolean isOnBar()
294     {
295         return m_onBar;
296     } // isOnBar
297

298     /*************************************************************************/
299
300     /** Last found ID */
301     private int m_lastID = -1;
302     /** Last found Node */
303     private MTreeNode m_lastNode = null;
304
305     /**
306      * Return the Node with ID in list of children
307      * @param ID id
308      * @return VTreeNode with ID or null
309      */

310     public MTreeNode findNode (int ID)
311     {
312         if (m_node_ID == ID)
313             return this;
314         //
315
if (ID == m_lastID && m_lastNode != null)
316             return m_lastNode;
317         //
318
Enumeration en = preorderEnumeration();
319         while (en.hasMoreElements())
320         {
321             MTreeNode nd = (MTreeNode)en.nextElement();
322             if (ID == nd.getID())
323             {
324                 m_lastID = ID;
325                 m_lastNode = nd;
326                 return nd;
327             }
328         }
329         return null;
330     } // findNode
331

332 } // MTreeNode
333
Popular Tags