1 30 package com.genimen.djeneric.tools.modeler.userperspective; 31 32 import javax.swing.JTree ; 33 import javax.swing.tree.DefaultTreeModel ; 34 35 import com.genimen.djeneric.repository.DjDomain; 36 import com.genimen.djeneric.repository.DjExtent; 37 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException; 38 import com.genimen.djeneric.structure.ExtentUsage; 39 import com.genimen.djeneric.structure.PropertyUsage; 40 import com.genimen.djeneric.structure.RelationDescriptor; 41 import com.genimen.djeneric.tools.modeler.ModelEditor; 42 43 public class ExtentUsageNode extends ExtentNode 44 { 45 private static final long serialVersionUID = 1L; 46 PropertyUsageTableModel _columnUsageModel = new PropertyUsageTableModel(_extentUsage); 47 48 public ExtentUsageNode(ExtentUsage usage) 49 { 50 super(usage); 51 updateIcon(); 52 } 53 54 public ExtentUsageNode(JTree theTree, DefaultTreeModel theModel, DjExtent extent) 55 { 56 super(theTree, theModel, extent); 57 _extentUsage.setExtent(extent); 58 updateIcon(); 59 } 60 61 public void updateIcon() 62 { 63 if (_extentUsage == null) 64 { 65 _icon = ModelEditor.getImageIcon("editor.gif"); 66 } 67 else if (isMultiRow()) _icon = ModelEditor.getImageIcon("table.gif"); 68 else _icon = ModelEditor.getImageIcon("editor.gif"); 69 } 70 71 public ExtentUsageNode(JTree theTree, DefaultTreeModel theModel, RelationDescriptor relDesc, ExtentUsage usage) 72 { 73 super(theTree, theModel, relDesc, usage); 74 updateIcon(); 75 } 76 77 public String getRoleName() 78 { 79 return "Editor Node"; 80 } 81 82 public void setExtentUsage(ExtentUsage taus) 83 { 84 _extentUsage = taus; 85 _columnUsageModel = new PropertyUsageTableModel(_extentUsage); 86 updateIcon(); 87 } 88 89 public PropertyUsageTableModel getPropertyUsageModel() 90 { 91 return _columnUsageModel; 92 } 93 94 public void initPropertyUsages() throws ObjectNotDefinedException 95 { 96 RelationDescriptor via = getVia(); 97 String detailProp = ""; 98 if (via != null) detailProp = via.getDetailPropertyName(); 99 100 for (int i = 0; i < getExtent().getPropertyCount(); i++) 101 { 102 if (getExtent().getProperty(i).getName().equals(getExtent().getIdProperty().getName())) continue; 104 if (getExtent().getProperty(i).getName().equals(detailProp)) continue; 106 107 PropertyUsage pu = new PropertyUsage(getExtent().getProperty(i)); 108 if (getExtent().getProperty(i).getType() instanceof DjDomain) 109 { 110 DjDomain dom = (DjDomain) getExtent().getProperty(i).getType(); 111 pu.setComponentType(dom.getComponentType()); 112 } 113 addPropertyUsage(pu); 114 } 115 } 116 117 public int getRowsDisplayed() 118 { 119 return _extentUsage.getRowsDisplayed(); 120 } 121 122 public void setRowsDisplayed(int rows) 123 { 124 _extentUsage.setRowsDisplayed(rows); 125 } 126 127 public boolean isMultiRow() 128 { 129 return _extentUsage.isMultiRow(); 130 } 131 132 public void setMultiRow(boolean multirow) 133 { 134 _extentUsage.setMultiRow(multirow); 135 updateIcon(); 136 _treeModel.nodeChanged(this); 137 } 138 139 public int getPropertyUsageCount() 140 { 141 return _extentUsage.getPropertyUsageCount(); 142 } 143 144 public PropertyUsage getPropertyUsage(int idx) 145 { 146 return _extentUsage.getPropertyUsage(idx); 147 } 148 149 public void addPropertyUsage(PropertyUsage usg) 150 { 151 _extentUsage.addPropertyUsage(usg); 152 } 153 154 public void removePropertyUsage(int idx) 155 { 156 _extentUsage.removePropertyUsage(idx); 157 } 158 159 public void removePropertyUsage(PropertyUsage cu) 160 { 161 _extentUsage.removePropertyUsage(cu); 162 } 163 164 protected ExtentNode createNewNode(RelationDescriptor relDesc, ExtentUsage usage) 166 { 167 return new ExtentUsageNode(getTree(), getModel(), relDesc, usage); 168 } 169 170 protected ExtentNode createNewNode(DjExtent extent) 171 { 172 return new ExtentUsageNode(getTree(), getModel(), extent); 173 } 174 175 public void sortPropertyUsages() 176 { 177 _extentUsage.sortPropertyUsages(); 178 } 179 180 public boolean shouldDeleteFromStructure(ModelEditor editor) 181 { 182 if (super.shouldDeleteFromStructure(editor)) 183 { 184 return true; 185 } 186 187 int i = 0; 189 while (i < getPropertyUsageCount()) 190 { 191 if (getPropertyUsage(i).getBaseProperty() == null) 192 { 193 removePropertyUsage(i); 194 } 195 else i++; 196 } 197 return false; 198 } 199 200 public void removeFromparent() 201 { 202 _treeModel.removeNodeFromParent(this); 203 getExtentUsage().removeFromParent(); 204 } 205 206 } | Popular Tags |