001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.calendar.ui.list;
018:
019: import java.util.Vector;
020:
021: import javax.swing.table.AbstractTableModel;
022:
023: import org.columba.calendar.base.api.ICalendarItem;
024:
025: /**
026: *
027: *
028: * @author fdietz
029: */
030:
031: public class CheckableItemListTableModel extends AbstractTableModel {
032: private Vector data;
033:
034: private final static String[] columns = { "Boolean", "String" };
035:
036: /**
037: *
038: */
039: public CheckableItemListTableModel() {
040: super ();
041:
042: data = new Vector();
043:
044: }
045:
046: /**
047: * @see javax.swing.table.TableModel#getColumnCount()
048: */
049: public int getColumnCount() {
050: // two column
051: return columns.length;
052: }
053:
054: /**
055: * @see javax.swing.table.TableModel#getRowCount()
056: */
057: public int getRowCount() {
058: return data.size();
059: }
060:
061: /**
062: * @see javax.swing.table.TableModel#getValueAt(int, int)
063: */
064: public Object getValueAt(int row, int column) {
065:
066: ICalendarItem item = (ICalendarItem) data.get(row);
067: //
068: // if (column == 0)
069: // return Boolean.valueOf(item.isSelected());
070: //
071: // else
072: // return item.toString();
073:
074: return item;
075: }
076:
077: public void addElement(ICalendarItem item) {
078: data.add(item);
079: }
080:
081: public void setElement(int index, ICalendarItem item) {
082: data.set(index, item);
083: }
084:
085: /**
086: * @see javax.swing.table.TableModel#getColumnClass(int)
087: */
088: public Class getColumnClass(int column) {
089: return getValueAt(0, column).getClass();
090: }
091:
092: /**
093: * @see javax.swing.table.TableModel#isCellEditable(int, int)
094: */
095: public boolean isCellEditable(int row, int column) {
096: if (column == 0)
097: return true;
098:
099: else
100: return false;
101: }
102:
103: /**
104: * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
105: */
106: public void setValueAt(Object value, int row, int column) {
107:
108: ICalendarItem item = (ICalendarItem) data.get(row);
109:
110: if (column == 0)
111: item.setSelected(((Boolean) value).booleanValue());
112:
113: }
114:
115: /**
116: * @see javax.swing.table.TableModel#getColumnName(int)
117: */
118: public String getColumnName(int column) {
119: return columns[column];
120: }
121:
122: public int count() {
123: return data.size();
124: }
125:
126: public ICalendarItem getElement(int index) {
127: return (ICalendarItem) data.get(index);
128: }
129:
130: public void updateRow(ICalendarItem item) {
131: int index = data.indexOf(item);
132: fireTableRowsUpdated(index, index);
133: }
134: }
|