1 19 22 package org.netbeans.modules.j2ee.sun.ide.editors.ui; 23 24 import java.util.*; 25 26 import javax.swing.table.*; 27 28 29 36 public abstract class AbstractDDTableModel extends AbstractTableModel 43 implements DDTableModel { 44 45 protected Vector data; 46 47 public AbstractDDTableModel (Object [] refs) { 48 data = new Vector (); 49 changeRefs(refs); 50 } 51 52 protected AbstractDDTableModel() { 57 } 58 59 protected void changeRefs(Object [] refs) { 60 if (data == null) { 61 data = new Vector (refs.length); 62 } else { 63 data.removeAllElements(); 64 } 65 for (int i = 0; i < refs.length; i++) { 66 data.addElement (refs [i]); 67 } 68 fireTableDataChanged(); 69 } 70 71 public int getRowCount () { 72 return data.size (); 73 } 74 75 public Class getColumnClass (int col) { 76 return String .class; 77 } 78 79 protected boolean valueInColumn(Object value, int col, int skipRow) { 80 for (int i = data.size()-1; i >= 0; i--) { 81 if (i != skipRow && value.equals(getValueAt(i, col))) { 82 return true; 83 } 84 } 85 return false; 86 } 87 88 public Object getValueAt (int row) { 89 if (row >= data.size ()) { 90 return null; 91 } 92 93 Object o = data.elementAt (row); 94 return o; 95 } 96 97 protected abstract void setValueAt (String strVal, Object rowElement, 98 int col); 99 100 public void setValueAt (Object value, int row, int col) { 101 String strVal = (String ) value; 102 103 if (row >= data.size()) { 104 return; 105 } 106 Object o = data.elementAt (row); 107 if (o == null) { 108 return; 109 } 110 111 setValueAt (strVal, o, col); 112 fireTableCellUpdated (row, col); 113 } 114 115 public void setValueAt(int row, Object value) { 116 data.setElementAt(value, row); 117 fireTableRowsUpdated(row,row); 118 } 119 120 public void addRowAt (int row, Object newVal, Object editedVal) { 121 126 if (row == -1) { 127 row = data.size(); 128 } else { 129 row++; 130 } 131 132 data.insertElementAt(editedVal, row); 133 fireTableRowsInserted(row, row); 134 } 135 136 public void newElementCancelled(Object obj) { 137 } 139 140 public void editsCancelled() { 141 } 143 144 public boolean isEditValid (Object rowValue, int row) { 145 return true; 146 } 147 148 public java.util.List canRemoveRow (int row) { 149 return Collections.EMPTY_LIST; 150 } 151 152 public void removeRowAt(int row) { 153 data.removeElementAt(row); 154 fireTableRowsDeleted(row, row); 155 } 156 } 157 | Popular Tags |