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.addressbook.gui.list;
019:
020: import java.util.List;
021: import java.util.Vector;
022:
023: import javax.swing.AbstractListModel;
024:
025: import org.columba.addressbook.model.IBasicModelPartial;
026:
027: /**
028: * @version 1.0
029: * @author
030: */
031:
032: public class AddressbookListModel extends AbstractListModel {
033: private List<IBasicModelPartial> list;
034:
035: private String patternString = "";
036:
037: public AddressbookListModel() {
038: super ();
039: list = new Vector<IBasicModelPartial>();
040:
041: }
042:
043: public Object getElementAt(int index) {
044: return (IBasicModelPartial) list.get(index);
045: }
046:
047: public int getSize() {
048: return list.size();
049: }
050:
051: public String getPatternString() {
052: return patternString;
053: }
054:
055: public void setPatternString(String s) throws Exception {
056: patternString = s;
057:
058: // manipulateModel(TableModelPlugin.STRUCTURE_CHANGE);
059: }
060:
061: public void clear() {
062: list.clear();
063: }
064:
065: public void addElement(IBasicModelPartial item) {
066: list.add(item);
067:
068: int index = list.indexOf(item);
069:
070: fireIntervalAdded(this , index, index);
071: }
072:
073: public void setHeaderItemList(List<IBasicModelPartial> l) {
074:
075: this .list = l;
076:
077: fireContentsChanged(this , 0, list.size() - 1);
078: }
079:
080: public IBasicModelPartial get(int i) {
081: return (IBasicModelPartial) list.get(i);
082: }
083:
084: public boolean addItem(IBasicModelPartial header) {
085: boolean result1 = false;
086:
087: Object o = header.getName();
088:
089: if (o != null) {
090: if (o instanceof String) {
091: String item = (String) o;
092:
093: // System.out.println("add item?:"+item);
094: item = item.toLowerCase();
095:
096: String pattern = getPatternString().toLowerCase();
097:
098: if (item.indexOf(pattern) != -1) {
099: result1 = true;
100: } else {
101: result1 = false;
102: }
103: } else {
104: result1 = false;
105: }
106: } else {
107: result1 = false;
108: }
109:
110: return result1;
111: }
112:
113: public Object[] toArray() {
114: return list.toArray();
115: }
116:
117: public void remove(int index) {
118: list.remove(index);
119: fireIntervalRemoved(this , index, index);
120: }
121:
122: public void removeElement(IBasicModelPartial item) {
123: int index = list.indexOf(item);
124:
125: remove(index);
126: }
127: }
|