1 19 20 21 package org.netbeans.modules.web.wizards; 22 23 import javax.swing.table.AbstractTableModel ; 24 import javax.swing.event.TableModelEvent ; 25 26 import org.openide.util.NbBundle; 27 28 32 public class AttrTableModel extends AbstractTableModel { 33 34 public AttrTableModel() { 35 } 36 37 private boolean debug; 38 private String [] colheaders = null; 39 private Object [][] data = null; 40 private int numCols; 41 private int numRows=0; 42 43 44 AttrTableModel(String [] headers) { 45 this.colheaders = headers; 46 numCols = colheaders.length; 47 48 } 49 50 AttrTableModel(String [] headers, Object [][] data) { 51 this.colheaders = headers; 52 numCols = colheaders.length; 53 this.data=data; 54 numRows = data.length; 55 } 56 57 public String getColumnName(int col) { 58 String key = "LBL_".concat(colheaders[col]); return NbBundle.getMessage(AttrTableModel.class, key); 60 } 61 62 public int getRowCount() { return numRows; } 63 public int getColumnCount() { return numCols; } 64 65 public Object getValueAt(int row, int col) { 66 return data[row][col]; 67 } 68 public int addRow(String name, String type, boolean required, boolean rtexpr) { 69 70 Object [][] data2 = new Object [numRows+1][numCols]; 71 int i=0, j=0; 72 73 if(numRows > 0) { 74 for(j=0; j<numRows; ++j) 75 data2[j] = data[j]; 76 } 77 78 data2[j][0] = name; 79 data2[j][1] = type; 80 data2[j][2] = Boolean.valueOf(required); 81 data2[j][3] = Boolean.valueOf(rtexpr); 82 data = data2; 83 numRows++; 84 return j; 85 } 86 87 public void removeRow(int row) { 88 89 if(debug) { 90 log("::removeRow()"); log("row is " + row); log("numRows is " + numRows); } 94 95 Object [][] data2 = new Object [numRows-1][numCols]; 96 int newRowIndex = 0; 97 for(int i=0; i<numRows; ++i) { 98 if(debug) log("\tExamining row " + i); if(i==row) continue; 100 if(debug) log("\tKeep this row"); data2[newRowIndex]=data[i]; 102 newRowIndex++; 103 if(debug) log("\tnewRowIndex is " + newRowIndex); } 105 data = data2; 106 numRows = --numRows; 107 } 108 109 public void setData(String name, String value, boolean required, boolean rtexpr, int row) { 110 data[row][0] = name; 111 data[row][1] = value; 112 data[row][2] = Boolean.valueOf(required); 113 data[row][3] = Boolean.valueOf(rtexpr); 114 fireTableChanged(new TableModelEvent (this, row)); 115 } 116 117 public void setValueAt(Object value, int row, int col) { 118 119 if(debug) 120 log("::setValueAt(): value = " + value + " at " + row + ", " + col); 123 data[row][col] = value; 124 125 if(debug) { 126 for(int i=0; i<data.length; ++i) { 127 for(int j=0; j<numCols; ++j) { 128 log("\t" + String.valueOf(i) + "," + String.valueOf(j) + ": " + data[i][j]); } 131 } 132 } 133 fireTableCellUpdated(row, col); 135 } 136 137 private void log(String s) { 138 System.out.println("AttrTableModel:"+s); } 140 141 public Object [][] getAttributes() { 142 if (data==null) return new Object [][]{}; 143 else return data; 144 } 145 } 146 | Popular Tags |