KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > contact > list > ContactListModel


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.contact.list;
19
20 import java.util.List JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import javax.swing.AbstractListModel JavaDoc;
24
25 import org.columba.addressbook.facade.IHeaderItem;
26
27 /**
28  * @version 1.0
29  * @author
30  */

31
32 public class ContactListModel extends AbstractListModel JavaDoc {
33     private List JavaDoc<IHeaderItem> list;
34
35     private String JavaDoc patternString = "";
36
37     public ContactListModel() {
38         super();
39
40         list = new Vector JavaDoc<IHeaderItem>();
41
42     }
43
44     public Object JavaDoc getElementAt(int index) {
45         return (IHeaderItem) list.get(index);
46     }
47
48     public int getSize() {
49         return list.size();
50     }
51
52     public String JavaDoc getPatternString() {
53         return patternString;
54     }
55
56     public void setPatternString(String JavaDoc s) throws Exception JavaDoc {
57         patternString = s;
58
59         // manipulateModel(TableModelPlugin.STRUCTURE_CHANGE);
60
}
61
62     public void clear() {
63         list.clear();
64     }
65
66     public void addElement(IHeaderItem item) {
67         list.add(item);
68
69         int index = list.indexOf(item);
70
71         fireIntervalAdded(this, index, index);
72     }
73
74     public void setHeaderItemList(List JavaDoc<IHeaderItem> l) {
75
76         this.list = l;
77
78         fireContentsChanged(this, 0, list.size() - 1);
79     }
80
81     public IHeaderItem get(int i) {
82         return (IHeaderItem) list.get(i);
83     }
84
85     public boolean addItem(IHeaderItem header) {
86         boolean result1 = false;
87
88         String JavaDoc o = header.getName();
89
90         if (o != null) {
91
92             String JavaDoc item = (String JavaDoc) o;
93
94             // System.out.println("add item?:"+item);
95
item = item.toLowerCase();
96
97             String JavaDoc pattern = getPatternString().toLowerCase();
98
99             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 JavaDoc[] 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 }
125
Popular Tags