1 30 package com.genimen.djeneric.tools.administrator.nodes; 31 32 import javax.swing.ImageIcon ; 33 import javax.swing.RepaintManager ; 34 import javax.swing.tree.DefaultMutableTreeNode ; 35 import javax.swing.tree.DefaultTreeModel ; 36 import javax.swing.tree.TreePath ; 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 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 toString(); 59 60 public DefaultTreeModel getModel() 61 { 62 return (DefaultTreeModel ) _tree.getModel(); 63 } 64 65 public DjPersistenceManager getManager() 66 { 67 return _tree.getManager(); 68 } 69 70 public DjSession createSession() throws Exception 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 (), 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 rm = RepaintManager.currentManager(_tree); 112 if (rm != null) 113 { 114 rm.validateInvalidComponents(); 115 rm.paintDirtyRegions(); 116 } 117 } 118 119 public void reloadParent() throws Exception 120 { 121 AdministratorTreeNode p = getParentTreeNode(); 122 if (p != null) p.reload(); 123 } 124 125 public void expandAll() 126 { 127 _tree.expandPath(new TreePath (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 (this.getPath())); 145 } 146 147 public AdminEditor getEditor(AdminPanel admin) 148 { 149 return null; 150 } 151 152 public AdminEditor getCreateEditor(AdminPanel admin) throws Exception 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 ; 179 180 public abstract void expandNode() throws Exception ; 181 182 public abstract ImageIcon getImageIcon(); 183 184 public abstract void delete() throws Exception ; 185 186 public abstract String getNodeType(); 187 188 public ImageIcon getObjectImageIcon() 189 190 { 191 return getImageIcon(); 192 } 193 194 } | Popular Tags |