1 package com.genimen.djeneric.tools.templateeditor.tree; 2 3 import javax.swing.ImageIcon ; 4 import javax.swing.JTree ; 5 import javax.swing.RepaintManager ; 6 import javax.swing.tree.DefaultMutableTreeNode ; 7 import javax.swing.tree.DefaultTreeModel ; 8 import javax.swing.tree.TreePath ; 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 15 { 16 protected boolean _alreadyLoaded = false; 17 protected JTree _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 tree, TemplateSet templateSet) 29 { 30 _tree = tree; 31 _extentUsageBasedOn = extentUsage; 32 _templateSet = templateSet; 33 } 34 35 abstract public void reload() throws Exception ; 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 tree) 48 { 49 _tree = tree; 50 } 51 52 public ExtentUsage getExtentUsage() 53 { 54 return _extentUsageBasedOn; 55 } 56 57 public String toString() 58 { 59 if (_extentUsageBasedOn != null) return _extentUsageBasedOn.getTitle(); 60 return "Model"; 61 } 62 63 public DefaultTreeModel getModel() 64 { 65 return (DefaultTreeModel ) _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 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 (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 if (!(getChildAt(i) instanceof DefaultTemplateTreeNode)) continue; 131 DefaultTemplateTreeNode child = (DefaultTemplateTreeNode) getChildAt(i); 132 child.collapseAll(); 133 } 134 _tree.collapsePath(new TreePath (this.getPath())); 135 } 136 137 public abstract void expandNode() throws Exception ; 138 139 public ImageIcon getImageIcon() 140 { 141 return TemplateEditor.getImageIcon("document.gif"); 142 } 143 144 } | Popular Tags |