1 56 package org.objectstyle.cayenne.modeler.editor; 57 58 import java.util.ArrayList ; 59 60 import org.objectstyle.cayenne.map.DbAttribute; 61 import org.objectstyle.cayenne.map.DbEntity; 62 import org.objectstyle.cayenne.map.DerivedDbAttribute; 63 import org.objectstyle.cayenne.map.DerivedDbEntity; 64 import org.objectstyle.cayenne.modeler.ProjectController; 65 66 69 public class DerivedAttributeParamsTableModel extends DbAttributeTableModel { 70 private static final int DB_ATTRIBUTE_NAME = 0; 71 private static final int DB_ATTRIBUTE_TYPE = 1; 72 73 protected DerivedDbAttribute derived; 74 75 78 public DerivedAttributeParamsTableModel( 79 DerivedDbAttribute derived, 80 ProjectController mediator, 81 Object eventSource) { 82 83 super( 84 ((DerivedDbEntity) derived.getEntity()).getParentEntity(), 85 mediator, 86 eventSource, 87 new ArrayList (derived.getParams())); 88 this.derived = derived; 89 } 90 91 94 public String getOrderingKey() { 95 return null; 96 } 97 98 public DbEntity getParentEntity() { 99 return ((DerivedDbEntity) derived.getEntity()).getParentEntity(); 100 } 101 102 105 public int getColumnCount() { 106 return 2; 107 } 108 109 public String getColumnName(int col) { 110 switch(col) { 111 case DB_ATTRIBUTE_NAME: return "Name"; 112 case DB_ATTRIBUTE_TYPE: return "Type"; 113 default: return ""; 114 } 115 } 116 117 public Object getValueAt(int row, int column) { 118 DbAttribute attr = getAttribute(row); 119 120 if (attr == null) { 121 return ""; 122 } 123 124 switch (column) { 125 case DB_ATTRIBUTE_NAME : 126 return getAttributeName(attr); 127 case DB_ATTRIBUTE_TYPE : 128 return getAttributeType(attr); 129 default : 130 return ""; 131 } 132 } 133 134 public void setValueAt(Object newVal, int row, int col) { 135 if (col == nameColumnInd()) { 136 replaceParameter(row, (String )newVal); 137 } 138 } 139 140 141 protected void replaceParameter(int ind, String attrName) { 142 if (attrName != null) { 143 objectList.set(ind, getParentEntity().getAttribute(attrName)); 144 fireTableDataChanged(); 145 } 146 } 147 148 public boolean isCellEditable(int row, int col) { 149 return col == DB_ATTRIBUTE_NAME; 150 } 151 } 152 | Popular Tags |