001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.gui.contact.list;
019:
020: import java.util.List;
021: import java.util.Vector;
022:
023: import javax.swing.AbstractListModel;
024:
025: import org.columba.addressbook.facade.IHeaderItem;
026:
027: /**
028: * @version 1.0
029: * @author
030: */
031:
032: public class ContactListModel extends AbstractListModel {
033: private List<IHeaderItem> list;
034:
035: private String patternString = "";
036:
037: public ContactListModel() {
038: super ();
039:
040: list = new Vector<IHeaderItem>();
041:
042: }
043:
044: public Object getElementAt(int index) {
045: return (IHeaderItem) list.get(index);
046: }
047:
048: public int getSize() {
049: return list.size();
050: }
051:
052: public String getPatternString() {
053: return patternString;
054: }
055:
056: public void setPatternString(String s) throws Exception {
057: patternString = s;
058:
059: // manipulateModel(TableModelPlugin.STRUCTURE_CHANGE);
060: }
061:
062: public void clear() {
063: list.clear();
064: }
065:
066: public void addElement(IHeaderItem item) {
067: list.add(item);
068:
069: int index = list.indexOf(item);
070:
071: fireIntervalAdded(this , index, index);
072: }
073:
074: public void setHeaderItemList(List<IHeaderItem> l) {
075:
076: this .list = l;
077:
078: fireContentsChanged(this , 0, list.size() - 1);
079: }
080:
081: public IHeaderItem get(int i) {
082: return (IHeaderItem) list.get(i);
083: }
084:
085: public boolean addItem(IHeaderItem header) {
086: boolean result1 = false;
087:
088: String o = header.getName();
089:
090: if (o != null) {
091:
092: String item = (String) o;
093:
094: // System.out.println("add item?:"+item);
095: item = item.toLowerCase();
096:
097: String pattern = getPatternString().toLowerCase();
098:
099: if (item.indexOf(pattern) != -1) {
100: result1 = true;
101: } else {
102: result1 = false;
103: }
104:
105: }
106:
107: return result1;
108: }
109:
110: public Object[] toArray() {
111: return list.toArray();
112: }
113:
114: public void remove(int index) {
115: list.remove(index);
116: fireIntervalRemoved(this , index, index);
117: }
118:
119: public void removeElement(IHeaderItem item) {
120: int index = list.indexOf(item);
121:
122: remove(index);
123: }
124: }
|