KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > list > CheckableItemListTableModel


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.calendar.ui.list;
18
19 import java.util.Vector JavaDoc;
20
21 import javax.swing.table.AbstractTableModel JavaDoc;
22
23 import org.columba.calendar.base.api.ICalendarItem;
24
25 /**
26  *
27  *
28  * @author fdietz
29  */

30
31 public class CheckableItemListTableModel extends AbstractTableModel JavaDoc {
32     private Vector JavaDoc data;
33
34     private final static String JavaDoc[] columns = { "Boolean", "String" };
35
36     /**
37      *
38      */

39     public CheckableItemListTableModel() {
40         super();
41
42         data = new Vector JavaDoc();
43
44     }
45
46     /**
47      * @see javax.swing.table.TableModel#getColumnCount()
48      */

49     public int getColumnCount() {
50         // two column
51
return columns.length;
52     }
53
54     /**
55      * @see javax.swing.table.TableModel#getRowCount()
56      */

57     public int getRowCount() {
58         return data.size();
59     }
60
61     /**
62      * @see javax.swing.table.TableModel#getValueAt(int, int)
63      */

64     public Object JavaDoc getValueAt(int row, int column) {
65
66         ICalendarItem item = (ICalendarItem) data.get(row);
67         //
68
// if (column == 0)
69
// return Boolean.valueOf(item.isSelected());
70
//
71
// else
72
// return item.toString();
73

74         return item;
75     }
76
77     public void addElement(ICalendarItem item) {
78         data.add(item);
79     }
80
81     public void setElement(int index, ICalendarItem item) {
82         data.set(index, item);
83     }
84
85     /**
86      * @see javax.swing.table.TableModel#getColumnClass(int)
87      */

88     public Class JavaDoc getColumnClass(int column) {
89         return getValueAt(0, column).getClass();
90     }
91
92     /**
93      * @see javax.swing.table.TableModel#isCellEditable(int, int)
94      */

95     public boolean isCellEditable(int row, int column) {
96         if (column == 0)
97             return true;
98
99         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 JavaDoc value, int row, int column) {
107
108         ICalendarItem item = (ICalendarItem) data.get(row);
109
110         if (column == 0)
111             item.setSelected(((Boolean JavaDoc) value).booleanValue());
112
113     }
114
115     /**
116      * @see javax.swing.table.TableModel#getColumnName(int)
117      */

118     public String JavaDoc 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 }
135
Popular Tags