1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 23 import org.netbeans.modules.j2ee.dd.api.ejb.CmpField; 24 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 28 31 public class CmpFieldsTableModel extends InnerTableModel { 32 33 private EntityHelper.CmpFields cmpFields; 34 private static final String [] COLUMN_NAMES = {Utils.getBundleMessage("LBL_FieldName"), 35 Utils.getBundleMessage("LBL_Type"), 36 Utils.getBundleMessage("LBL_LocalGetter"), 37 Utils.getBundleMessage("LBL_LocalSetter"), 38 Utils.getBundleMessage("LBL_RemoteGetter"), 39 Utils.getBundleMessage("LBL_RemoteSetter"), 40 Utils.getBundleMessage("LBL_Description")}; 41 private static final int[] COLUMN_WIDTHS = new int[]{120, 160, 70, 70, 70, 70, 220}; 42 43 public CmpFieldsTableModel(EntityHelper.CmpFields cmpFields) { 44 super(null, COLUMN_NAMES, COLUMN_WIDTHS); 45 this.cmpFields = cmpFields; 46 cmpFields.addPropertyChangeListener(new PropertyChangeListener () { 47 public void propertyChange(PropertyChangeEvent evt) { 48 if (evt != null && evt.getSource() instanceof Entity && 49 (evt.getOldValue() instanceof CmpField || evt.getNewValue() instanceof CmpField)) { 50 tableChanged(); 51 } 52 } 53 }); 54 } 55 56 public int addRow() { 57 cmpFields.addCmpField(); 58 int row = getRowCount() - 1; 59 return row; 61 } 62 63 public void editRow(int row) { 64 if (cmpFields.getCmpFieldHelper(row).edit()) { 65 fireTableRowsUpdated(row, row); 66 } 67 } 68 69 public void removeRow(int row) { 70 cmpFields.getCmpFieldHelper(row).deleteCmpField(); 71 } 72 73 public void refreshView() { 74 super.refreshView(); 75 } 76 77 public int getRowCount() { 78 return cmpFields.getCmpFieldCount(); 79 } 80 81 public Object getValueAt(int rowIndex, int columnIndex) { 82 CmpFieldHelper helper = cmpFields.getCmpFieldHelper(rowIndex); 83 switch (columnIndex) { 84 case 0: 85 return helper.getFieldName(); 86 case 6: 97 return helper.getDefaultDescription(); 98 } 99 return null; 100 } 101 102 public void setValueAt(Object value, int rowIndex, int columnIndex) { 103 CmpFieldHelper helper = cmpFields.getCmpFieldHelper(rowIndex); 104 switch (columnIndex) { 105 case 0: 106 helper.setFieldName((String ) value); 107 break; 108 case 2: 112 helper.setLocalGetter(((Boolean ) value).booleanValue()); 113 break; 114 case 3: 115 helper.setLocalSetter(((Boolean ) value).booleanValue()); 116 break; 117 case 4: 118 helper.setRemoteGetter(((Boolean ) value).booleanValue()); 119 break; 120 case 5: 121 helper.setRemoteSetter(((Boolean ) value).booleanValue()); 122 break; 123 case 6: 124 helper.setDescription((String ) value); 125 break; 126 } 127 fireTableRowsUpdated(rowIndex, rowIndex); 128 } 129 130 public boolean isCellEditable(int rowIndex, int columnIndex) { 131 return true; 132 } 133 134 public Class getColumnClass(int columnIndex) { 135 switch (columnIndex) { 136 case 0: 137 return String .class; 138 case 1: 139 return String .class; 140 case 2: 141 return Boolean .class; 142 case 3: 143 return Boolean .class; 144 case 4: 145 return Boolean .class; 146 case 5: 147 return Boolean .class; 148 case 6: 149 return String .class; 150 } 151 return super.getColumnClass(columnIndex); 152 } 153 } 154 | Popular Tags |