KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > plugins > opentree > CMSNode


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23  
24 package org.infoglue.cms.plugins.opentree;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
30
31 public class CMSNode extends DefaultMutableTreeNode JavaDoc
32 {
33     private Controller controller = null;
34     private Integer JavaDoc id = null;
35     private String JavaDoc name = null;
36     private boolean isBranch = false;
37
38     private boolean areChildrenDefined = false;
39
40     
41     public CMSNode(Controller controller, boolean isBranch)
42     {
43         this.controller = controller;
44         this.isBranch = isBranch;
45     }
46
47     public Integer JavaDoc getId()
48     {
49         return this.id;
50     }
51
52     public void setId(Integer JavaDoc id)
53     {
54         this.id = id;
55     }
56     
57     public void setName(String JavaDoc name)
58     {
59         this.name = name;
60     }
61     
62     public String JavaDoc getName()
63     {
64         return this.name;
65     }
66     
67     public String JavaDoc toString()
68     {
69         return this.name;
70     }
71     
72     public int getChildCount()
73     {
74         //System.out.println("getChildCount called:" + areChildrenDefined);
75
if (!areChildrenDefined)
76             defineChildNodes();
77         return (super.getChildCount());
78     }
79     
80     private void defineChildNodes()
81     {
82         areChildrenDefined = true;
83         //System.out.println("defineChildNodes was called");
84
this.removeAllChildren();
85         //System.out.println("removed all old children");
86
List JavaDoc childNodes = controller.getChildNodes(this.id);
87         Iterator JavaDoc iterator = childNodes.iterator();
88         while(iterator.hasNext())
89         {
90             add((CMSNode)iterator.next());
91         }
92     }
93     
94     public void setAreChildrenDefined(boolean areChildrenDefined)
95     {
96         this.areChildrenDefined = areChildrenDefined;
97         getChildCount();
98     }
99     
100     public boolean isLeaf()
101     {
102         return !this.isBranch;
103     }
104 }
Popular Tags