1 30 package com.genimen.djeneric.tools.console.nodes; 31 32 import javax.swing.ImageIcon ; 33 import javax.swing.JTree ; 34 import javax.swing.tree.DefaultTreeModel ; 35 import javax.swing.tree.TreePath ; 36 37 import com.genimen.djeneric.language.Messages; 38 import com.genimen.djeneric.repository.DjExtent; 39 import com.genimen.djeneric.repository.DjPersistenceManager; 40 import com.genimen.djeneric.repository.DjProperty; 41 import com.genimen.djeneric.repository.DjRelation; 42 import com.genimen.djeneric.util.DjLogger; 43 import com.genimen.djeneric.util.DjString; 44 45 public class ExtentNode extends CustomTreeNode 46 { 47 private static final long serialVersionUID = 1L; 48 DjExtent _extent; 49 50 public ExtentNode(JTree theTree, DefaultTreeModel theModel, DjExtent extent) 51 { 52 super(theTree, theModel); 53 _extent = extent; 54 } 55 56 public ImageIcon getImageIcon() 57 { 58 return (getImageIcon("images/extent.gif")); 59 } 60 61 public String toString() 62 { 63 return _extent.getName() + " (" + _extent.getAlias() + ")"; 64 } 65 66 String _detailDescr = null; 67 68 public String getDetailDescription() 69 { 70 if (_detailDescr != null) return _detailDescr; 71 72 StringBuffer sb = new StringBuffer (200); 73 74 sb.append(Messages.getString("ExtentNode.ObjectType", _extent.getObjectType()) + "\n" 75 + Messages.getString("ExtentNode.ExtentAlias", _extent.getInternalCode()) + "\n\n"); 76 77 DjProperty cols[] = _extent.getProperties(); 78 int maxLen = 0; 79 for (int i = 0; i < cols.length; i++) 80 { 81 if (cols[i].getName().length() > maxLen) maxLen = cols[i].getName().length(); 82 } 83 maxLen++; 84 85 sb.append(DjString.appendToLength(Messages.getString("global.Name"), " ", maxLen) 86 + DjString.appendToLength(Messages.getString("global.Mapping"), " ", 10) 87 + DjString.appendToLength(Messages.getString("global.Type"), " ", 10) 88 + DjString.appendToLength(Messages.getString("ExtentNode.Size"), " ", 10) 89 + DjString.appendToLength(Messages.getString("global.Required"), " ", 8)); 90 sb.append("\n" + DjString.appendToLength("", "-", sb.length()) + "\n"); 91 92 for (int i = 0; i < cols.length; i++) 93 { 94 sb.append(DjString.appendToLength(cols[i].getName(), " ", maxLen) 95 + DjString.appendToLength(cols[i].getMapping(), " ", 10) 96 + DjString.appendToLength(cols[i].getTypeName(), " ", 10) 97 + DjString.appendToLength("(" + cols[i].getLength() + ", " + cols[i].getDecimals() + ")", " ", 10)); 98 if (cols[i].isRequired()) sb.append(DjString.appendToLength("" + cols[i].isRequired(), " ", 8)); 99 sb.append("\n"); 100 } 101 102 try 103 { 104 DjRelation[] detail = _extent.getDetailRelations(); 105 for (int i = 0; i < detail.length; i++) 106 { 107 if (i == 0) sb.append("\n" + Messages.getString("ExtentNode.DetailExtents") + "\n"); 108 sb.append(detail[i].getName() + " (" + detail[i].getDescription() + "):\n " + _extent.getName()); 109 if (detail[i].isDetailsContained()) sb.append(" " + Messages.getString("ExtentNode.Contain") + " "); 110 else sb.append(" " + Messages.getString("ExtentNode.Reference") + " "); 111 112 sb.append(detail[i].getDetailExtent().getName() + "\n where " + _extent.getName() + "." 113 + _extent.getPropertyByMapping(DjPersistenceManager.MAPPING_OBJECT_ID).getName() + " = " 114 + detail[i].getDetailExtent().getName() + "." + detail[i].getDetailProperty().getName() + "\n\n"); 115 } 116 } 117 catch (Exception x) 118 { 119 sb.append(x.getClass().getName() + ": " + x.getMessage()); 120 DjLogger.log(x); 121 } 122 123 _detailDescr = sb.toString(); 124 return _detailDescr; 125 } 126 127 public void expandNode() throws Exception 128 { 129 if (_alreadyLoaded) return; 130 131 boolean isCollapsed = _tree.isCollapsed(new TreePath (this.getPath())); 132 removeAllChildren(); 133 _treeModel.nodeStructureChanged(this); 134 135 try 136 { 137 DjRelation[] details = _extent.getDetailRelations(); 138 for (int i = 0; i < details.length; i++) 139 { 140 DjExtent tab = details[i].getDetailExtent(); 141 insertAsFolder(new ExtentNode(getTree(), getModel(), tab)); 142 } 143 _alreadyLoaded = true; 144 } 145 catch (Exception x) 146 { 147 DjLogger.log(x); 148 } 149 if (!isCollapsed) _tree.expandPath(new TreePath (this.getPath())); 150 } 151 } | Popular Tags |