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: package org.columba.mail.gui.config.filter;
017:
018: import javax.swing.table.AbstractTableModel;
019:
020: import org.columba.core.filter.Filter;
021: import org.columba.core.filter.FilterList;
022: import org.columba.core.filter.IFilter;
023: import org.columba.core.filter.IFilterList;
024: import org.columba.mail.util.MailResourceLoader;
025:
026: class FilterListDataModel extends AbstractTableModel {
027: final String[] columnNames = {
028: MailResourceLoader.getString("dialog", "filter",
029: "description_tableheader"),
030: MailResourceLoader.getString("dialog", "filter",
031: "enabled_tableheader") };
032: private IFilterList filterList;
033:
034: public FilterListDataModel(IFilterList list) {
035: super ();
036: this .filterList = list;
037: }
038:
039: /** {@inheritDoc} */
040: public int getColumnCount() {
041: return columnNames.length;
042: }
043:
044: /** {@inheritDoc} */
045: public int getRowCount() {
046: return filterList.count();
047: }
048:
049: /** {@inheritDoc} */
050: public String getColumnName(int col) {
051: return columnNames[col];
052: }
053:
054: /** {@inheritDoc} */
055: public Object getValueAt(int row, int col) {
056: IFilter filter = filterList.get(row);
057:
058: if (filter == null) {
059: return "";
060: }
061:
062: if (col == 0) {
063: // description
064: String description = filter.get("description");
065:
066: if (description == null) {
067: return "";
068: }
069:
070: return description;
071: } else {
072: // enabled/disabled
073: boolean enabled = filter.getBoolean("enabled");
074:
075: return enabled ? Boolean.TRUE : Boolean.FALSE;
076: }
077: }
078:
079: /** {@inheritDoc} */
080: public Class getColumnClass(int c) {
081: if (c == 0) {
082: return String.class;
083: } else {
084: return Boolean.class;
085: }
086: }
087:
088: /** {@inheritDoc} */
089: public boolean isCellEditable(int row, int col) {
090: return col == 1;
091: }
092:
093: /** {@inheritDoc} */
094: public void setValueAt(Object value, int row, int col) {
095: if (col == 1) {
096: IFilter filter = filterList.get(row);
097: filter.setEnabled(((Boolean) value).booleanValue());
098: }
099: }
100:
101: /**
102: * Returns the filter at the specified row/index.
103: * @param row the row.
104: * @return a Filter;
105: */
106: public IFilter getFilter(int row) {
107: return filterList.get(row);
108: }
109:
110: /**
111: * Inserts the filter into the filter list at the end of the filter list.
112: * @param newFilter the filter to insert at the end. *
113: * @throws IndexOutOfBoundsException if the index is out of range.
114: */
115: public void addFilter(Filter newFilter)
116: throws IndexOutOfBoundsException {
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: }
|