1 56 57 package org.objectstyle.cayenne.dataview.dvmodeler; 58 59 import javax.swing.table.*; 60 61 66 67 public class FieldsTableModel extends AbstractTableModel { 68 private ObjEntityView objEntityView; 69 private String [] columnNames= {"Name", 70 "Type", 71 "CalcType", 72 "Attribute/Relationship", 73 "Lookup"}; 74 75 public FieldsTableModel(ObjEntityView objEntityView) { 76 this.objEntityView = objEntityView; 77 } 78 79 public FieldsTableModel() { 80 } 81 82 public void setObjEntityView(ObjEntityView objEntityView){ 83 this.objEntityView = objEntityView; 84 fireTableStructureChanged(); 85 } 86 87 88 public int getRowCount(){ 89 if (objEntityView != null){ 90 return objEntityView.getObjEntityViewFieldCount(); 91 }else{ 92 return 0; 93 } 94 } 95 96 public int getColumnCount(){ 97 return columnNames.length; 98 } 99 100 public String getColumnName(int col) { 101 return columnNames[col]; 102 } 103 104 public Class getColumnClass(int c) { 105 return getValueAt(0, c).getClass(); 106 } 107 108 public Object getValueAt(int row, int column){ 109 ObjEntityViewField field = objEntityView.getObjEntityViewField(row); 110 switch (column){ 111 case 0: 112 return field.getName(); 113 case 1: 114 return field.getDataType(); 115 case 2: 116 return field.getCalcType(); 117 case 3: { 118 String calcType = field.getCalcType(); 119 if (calcType.equals("nocalc") && 120 field.getObjAttribute() != null){ 121 return field.getObjAttribute().getName(); 122 } else if (calcType.equals("lookup") && 123 field.getObjRelationship() != null) { 124 return field.getObjRelationship().getName(); 125 } else 126 return ""; 127 } 128 case 4:{ 129 String calcType = field.getCalcType(); 130 if (calcType.equals("lookup")){ 131 return field.getLookup().toString(); 132 }else{ 133 return ""; 134 } 135 } 136 137 default: return null; 138 } 139 } 140 } 141 | Popular Tags |