001: /*
002: * ColumnIndexTableModel.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.executequery.gui.browser;
023:
024: import javax.swing.table.AbstractTableModel;
025:
026: /* ----------------------------------------------------------
027: * CVS NOTE: Changes to the CVS repository prior to the
028: * release of version 3.0.0beta1 has meant a
029: * resetting of CVS revision numbers.
030: * ----------------------------------------------------------
031: */
032:
033: /**
034: *
035: * @author Takis Diakoumis
036: * @version $Revision: 1.5 $
037: * @date $Date: 2006/09/26 16:07:25 $
038: */
039: public class ColumnIndexTableModel extends AbstractTableModel {
040:
041: /** The index data */
042: private ColumnIndex[] data;
043:
044: private static final String[] header = { "", "Index Name",
045: "Indexed Column", "Non-Unique" };
046:
047: public ColumnIndexTableModel() {
048: }
049:
050: public ColumnIndexTableModel(ColumnIndex[] data) {
051: this .data = data;
052: }
053:
054: public void setIndexData(ColumnIndex[] data) {
055: if (this .data == data) {
056: return;
057: }
058: this .data = data;
059: fireTableDataChanged();
060: }
061:
062: public int getRowCount() {
063: if (data == null) {
064: return 0;
065: }
066: return data.length;
067: }
068:
069: public int getColumnCount() {
070: return header.length;
071: }
072:
073: public String getColumnName(int col) {
074: return header[col];
075: }
076:
077: public boolean isCellEditable(int row, int col) {
078: return false;
079: }
080:
081: public Object getValueAt(int row, int col) {
082: ColumnIndex cid = data[row];
083: switch (col) {
084: case 1:
085: return cid.getIndexName();
086: case 2:
087: return cid.getIndexedColumn();
088: case 3:
089: return new Boolean(cid.isNonUnique());
090: default:
091: return null;
092: }
093: }
094:
095: public void setValueAt(Object value, int row, int col) {
096: ColumnIndex cid = data[row];
097: switch (col) {
098: case 1:
099: cid.setIndexName((String) value);
100: break;
101: case 2:
102: cid.setIndexedColumn((String) value);
103: break;
104: case 3:
105: cid.setNonUnique(((Boolean) value).booleanValue());
106: break;
107: }
108:
109: fireTableRowsUpdated(row, row);
110: }
111:
112: public Class getColumnClass(int col) {
113: if (col == 3) {
114: return Boolean.class;
115: }
116: return String.class;
117: }
118:
119: }
|