1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer; 23 24 import javax.swing.table.AbstractTableModel ; 25 import javax.swing.table.TableCellEditor ; 26 import javax.swing.*; 27 28 31 public abstract class InnerTableModel extends AbstractTableModel { 32 33 private XmlMultiViewDataSynchronizer synchronizer; 34 protected final String [] columnNames; 35 private int[] columnWidths; 36 private int rowCount = -1; 37 38 public InnerTableModel(XmlMultiViewDataSynchronizer synchronizer, String [] columnNames, int[] columnWidths) { 39 this.synchronizer = synchronizer; 40 this.columnNames = columnNames; 41 this.columnWidths = columnWidths; 42 } 43 44 public boolean isCellEditable(int rowIndex, int columnIndex) { 45 return true; 46 } 47 48 public String getColumnName(int column) { 49 return columnNames[column]; 50 } 51 52 public TableCellEditor getCellEditor(int columnIndex) { 53 return null; 54 } 55 56 public int getColumnCount() { 57 return columnNames.length; 58 } 59 60 public int[] getColumnWidths() { 61 return columnWidths; 62 } 63 64 public abstract int addRow(); 65 66 public abstract void removeRow(int selectedRow); 67 68 public int getDefaultColumnWidth(int i) { 69 return columnWidths[i]; 70 } 71 72 public void refreshView() { 73 fireTableDataChanged(); 74 } 75 76 protected void tableChanged() { 77 if (!checkRowCount()) { 78 fireTableDataChanged(); 79 } 80 } 81 82 private boolean checkRowCount() { 83 int n = getRowCount(); 84 if (rowCount == -1) { 85 rowCount = n; 86 } 87 if (n != rowCount) { 88 while (rowCount < n) { 89 rowCount++; 90 fireTableRowsInserted(0, 0); 91 } 92 while (rowCount > n) { 93 rowCount--; 94 fireTableRowsDeleted(0, 0); 95 } 96 return true; 97 } else { 98 return false; 99 } 100 } 101 102 protected void modelUpdatedFromUI() { 103 if (synchronizer != null) { 104 synchronizer.requestUpdateData(); 105 } 106 } 107 108 public TableCellEditor getTableCellEditor(int column) { 109 return null; 110 } 111 112 protected TableCellEditor createComboBoxCellEditor(Object [] items) { 113 return createComboBoxCellEditor(items, false); 114 } 115 116 private static TableCellEditor createComboBoxCellEditor(Object [] items, final boolean editable) { 117 final JComboBox comboBox = new JComboBox(items); 118 comboBox.setEditable(editable); 119 return new DefaultCellEditor(comboBox); 120 } 121 } 122 | Popular Tags |