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