if (e.getType() == TableModelEvent.UPDATE) {
int selectedRow = e.getFirstRow(); //返回首个选定行的索引,如果没有选定的行,则返回 -1
int selectedColumn = e.getColumn(); ////返回所有选定列的索引
if(-1 != selectedRow && -1 != selectedColumn) {
MetadataTable metadataTable = (MetadataTable) ui;
if(MetadataTableModel.IS_KEY_FIELD_INDEX == selectedColumn) {//isKey
Object cellValueObj = metadataTable.getValueAt(selectedRow, selectedColumn);
boolean isKey = ((Boolean) cellValueObj).booleanValue();
MetadataTableModel metadataTableModel = (MetadataTableModel) metadataTable.getModel();
metadataTableModel.setCellEditableAt(isKey, selectedRow, MetadataTableModel.CONSTRAINT_TYPE_INDEX);
metadataTableModel.setCellEditableAt(isKey, selectedRow, MetadataTableModel.REFERENCING_TABLE_INDEX);
metadataTableModel.setCellEditableAt(isKey, selectedRow, MetadataTableModel.REFERENCING_COLUMN_INDEX);
metadataTableModel.setCellEditableAt(isKey, selectedRow, MetadataTableModel.DELETE_RULE_INDEX);
metadataTableModel.setValueAt(null, selectedRow, MetadataTableModel.CONSTRAINT_TYPE_INDEX);
metadataTableModel.setValueAt(null, selectedRow, MetadataTableModel.REFERENCING_TABLE_INDEX);
metadataTableModel.setValueAt(null, selectedRow, MetadataTableModel.REFERENCING_COLUMN_INDEX);
metadataTableModel.setValueAt(null, selectedRow, MetadataTableModel.DELETE_RULE_INDEX);
} else if(MetadataTableModel.IS_QUERY_FIELD_INDEX == selectedColumn) {//isQueryField
Object cellValueObj = metadataTable.getValueAt(selectedRow, selectedColumn);
boolean isQueryField = ((Boolean) cellValueObj).booleanValue();
MetadataTableModel metadataTableModel = (MetadataTableModel) metadataTable.getModel();
metadataTableModel.setCellEditableAt(isQueryField, selectedRow, MetadataTableModel.QUERY_MODE_INDEX);
metadataTableModel.setValueAt(null, selectedRow, MetadataTableModel.QUERY_MODE_INDEX);
}
}
}