KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > filter > FilterListDataModel


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
package org.columba.mail.gui.config.filter;
17
18 import javax.swing.table.AbstractTableModel JavaDoc;
19
20 import org.columba.core.filter.Filter;
21 import org.columba.core.filter.FilterList;
22 import org.columba.core.filter.IFilter;
23 import org.columba.core.filter.IFilterList;
24 import org.columba.mail.util.MailResourceLoader;
25
26
27  class FilterListDataModel extends AbstractTableModel JavaDoc {
28     final String JavaDoc[] columnNames = {
29         MailResourceLoader.getString("dialog", "filter",
30             "description_tableheader"),
31         MailResourceLoader.getString("dialog", "filter", "enabled_tableheader")
32     };
33     private IFilterList filterList;
34
35     public FilterListDataModel(IFilterList list) {
36         super();
37         this.filterList = list;
38     }
39
40     /** {@inheritDoc} */
41     public int getColumnCount() {
42         return columnNames.length;
43     }
44
45     /** {@inheritDoc} */
46     public int getRowCount() {
47         return filterList.count();
48     }
49
50     /** {@inheritDoc} */
51     public String JavaDoc getColumnName(int col) {
52         return columnNames[col];
53     }
54
55     /** {@inheritDoc} */
56     public Object JavaDoc getValueAt(int row, int col) {
57         IFilter filter = filterList.get(row);
58
59         if (filter == null) {
60             return "";
61         }
62
63         if (col == 0) {
64             // description
65
String JavaDoc description = filter.get("description");
66
67             if (description == null) {
68                 return "";
69             }
70
71             return description;
72         } else {
73             // enabled/disabled
74
boolean enabled = filter.getBoolean("enabled");
75
76             return enabled ? Boolean.TRUE : Boolean.FALSE;
77         }
78     }
79
80     /** {@inheritDoc} */
81     public Class JavaDoc getColumnClass(int c) {
82         if (c == 0) {
83             return String JavaDoc.class;
84         } else {
85             return Boolean JavaDoc.class;
86         }
87     }
88
89     /** {@inheritDoc} */
90     public boolean isCellEditable(int row, int col) {
91         return col == 1;
92     }
93
94     /** {@inheritDoc} */
95     public void setValueAt(Object JavaDoc value, int row, int col) {
96         if (col == 1) {
97             IFilter filter = filterList.get(row);
98             filter.setEnabled(((Boolean JavaDoc) value).booleanValue());
99         }
100     }
101
102     /**
103  * Returns the filter at the specified row/index.
104  * @param row the row.
105  * @return a Filter;
106  */

107     public IFilter getFilter(int row) {
108         return filterList.get(row);
109     }
110
111     /**
112  * Inserts the filter into the filter list at the end of the filter list.
113  * @param newFilter the filter to insert at the end. *
114  * @throws IndexOutOfBoundsException if the index is out of range.
115  */

116     public void addFilter(Filter newFilter) throws IndexOutOfBoundsException JavaDoc {
117         int row = filterList.count();
118         filterList.add(newFilter);
119         fireTableRowsInserted(row, row);
120     }
121
122     /**
123  * Inserts the filter into the filter list at the specified index.
124  * Filters that are at a position below the index (higher) is moved down.
125  * @param newFilter the filter to insert.
126  * @param index the positiong in the list to add the filter too.
127  */

128     public void insertFilter(Filter newFilter, int index) {
129         filterList.insert(newFilter, index);
130         fireTableRowsInserted(index, index);
131     }
132
133     /**
134  * Removes the filter from the filter list.
135  * @param filter the filter to remove.
136  */

137     public void removeFilter(Filter filter) {
138         filterList.remove(filter);
139         fireTableDataChanged();
140     }
141 }
142
Popular Tags