KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > templateeditor > tree > DefaultTemplateTreeNode


1 package com.genimen.djeneric.tools.templateeditor.tree;
2
3 import javax.swing.ImageIcon JavaDoc;
4 import javax.swing.JTree JavaDoc;
5 import javax.swing.RepaintManager JavaDoc;
6 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
7 import javax.swing.tree.DefaultTreeModel JavaDoc;
8 import javax.swing.tree.TreePath JavaDoc;
9
10 import com.genimen.djeneric.structure.ExtentUsage;
11 import com.genimen.djeneric.tools.generator.util.TemplateSet;
12 import com.genimen.djeneric.tools.templateeditor.TemplateEditor;
13
14 public abstract class DefaultTemplateTreeNode extends DefaultMutableTreeNode JavaDoc
15 {
16   protected boolean _alreadyLoaded = false;
17   protected JTree JavaDoc _tree;
18   protected ExtentUsage _extentUsageBasedOn;
19   protected TemplateSet _templateSet;
20
21   public DefaultTemplateTreeNode(TemplateSet templateSet)
22   {
23     _tree = null;
24     _extentUsageBasedOn = null;
25     _templateSet = templateSet;
26   }
27
28   public DefaultTemplateTreeNode(ExtentUsage extentUsage, JTree JavaDoc tree, TemplateSet templateSet)
29   {
30     _tree = tree;
31     _extentUsageBasedOn = extentUsage;
32     _templateSet = templateSet;
33   }
34
35   abstract public void reload() throws Exception JavaDoc;
36
37   public TemplateSet getTemplateSet()
38   {
39     return _templateSet;
40   }
41
42   public void setTemplateSet(TemplateSet templateSet)
43   {
44     _templateSet = templateSet;
45   }
46
47   public void setTree(JTree JavaDoc tree)
48   {
49     _tree = tree;
50   }
51
52   public ExtentUsage getExtentUsage()
53   {
54     return _extentUsageBasedOn;
55   }
56
57   public String JavaDoc toString()
58   {
59     if (_extentUsageBasedOn != null) return _extentUsageBasedOn.getTitle();
60     return "Model";
61   }
62
63   public DefaultTreeModel JavaDoc getModel()
64   {
65     return (DefaultTreeModel JavaDoc) _tree.getModel();
66   }
67
68   public DefaultTemplateTreeNode getParentTreeNode()
69   {
70     return (DefaultTemplateTreeNode) getParent();
71   }
72
73   private void copyInternalReferences(DefaultTemplateTreeNode node)
74   {
75     node._tree = _tree;
76     node._templateSet = _templateSet;
77   }
78
79   public void insertAsChild(DefaultTemplateTreeNode node)
80   {
81     getModel().insertNodeInto(node, this, getChildCount());
82     copyInternalReferences(node);
83   }
84
85   public void insertAsFolder(DefaultTemplateTreeNode node)
86   {
87     getModel().insertNodeInto(node, this, getChildCount());
88     getModel().insertNodeInto(new TemplateTreeNode(_templateSet), node, 0);
89     copyInternalReferences(node);
90   }
91
92   public void insertAsSibling(DefaultTemplateTreeNode node)
93   {
94     getModel().insertNodeInto(node, parent, parent.getChildCount());
95     copyInternalReferences(node);
96   }
97
98   public void removeFromTree()
99   {
100     getModel().removeNodeFromParent(this);
101   }
102
103   public void repaintTree()
104   {
105     RepaintManager JavaDoc rm = RepaintManager.currentManager(_tree);
106     if (rm != null)
107     {
108       rm.validateInvalidComponents();
109       rm.paintDirtyRegions();
110     }
111   }
112
113   public void expandAll()
114   {
115     _tree.expandPath(new TreePath JavaDoc(this.getPath()));
116     int cc = getChildCount();
117     for (int i = 0; i < cc; i++)
118     {
119       DefaultTemplateTreeNode child = (DefaultTemplateTreeNode) getChildAt(i);
120       child.expandAll();
121     }
122   }
123
124   public void collapseAll()
125   {
126     int cc = getChildCount();
127     for (int i = 0; i < cc; i++)
128     {
129       // Check for dummy node of folders not expanded yet:
130
if (!(getChildAt(i) instanceof DefaultTemplateTreeNode)) continue;
131       DefaultTemplateTreeNode child = (DefaultTemplateTreeNode) getChildAt(i);
132       child.collapseAll();
133     }
134     _tree.collapsePath(new TreePath JavaDoc(this.getPath()));
135   }
136
137   public abstract void expandNode() throws Exception JavaDoc;
138
139   public ImageIcon JavaDoc getImageIcon()
140   {
141     return TemplateEditor.getImageIcon("document.gif");
142   }
143
144 }
Popular Tags