KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > FilterCriteria


1 /*
2   Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui;
19
20 import java.util.Collection JavaDoc;
21 import org.objectweb.jac.core.rtti.CollectionItem;
22 import org.objectweb.jac.core.rtti.FieldItem;
23
24 public class FilterCriteria {
25     public FilterCriteria(int column, FieldItem field) {
26         this.column = column;
27         this.field = field;
28     }
29
30     /**
31      * Tells wether a row of table model matches the filter
32      * @param model the table model
33      * @param row row index in the table model
34      */

35     public boolean match(ExtendedTableModel model, int row) {
36         Object JavaDoc modelValue = model.getObject(row,column);
37         if (field instanceof CollectionItem) {
38             return !active ||
39                 (modelValue!=null && ((Collection JavaDoc)modelValue).contains(value));
40         } else {
41             return !active ||
42                 (value==null && modelValue==null) ||
43                 (value!=null && value.equals(modelValue));
44         }
45     }
46
47     /** The column to filter */
48     int column;
49     public int getColumn() {
50         return column;
51     }
52
53     FieldItem field;
54     public FieldItem getField() {
55         return field;
56     }
57
58     /** If false, the filer is inactive */
59     boolean active = false;
60     public boolean isActive() {
61         return active;
62     }
63     public void setActive(boolean active) {
64         this.active = active;
65     }
66
67     Object JavaDoc value;
68     public void setValue(Object JavaDoc value) {
69         this.value = value;
70     }
71     public Object JavaDoc getValue() {
72         return value;
73     }
74
75     public String JavaDoc toString() {
76         return column+(active?("=="+value):"(off)");
77     }
78
79     public boolean equals(Object JavaDoc o) {
80         if (!(o instanceof FilterCriteria))
81             return false;
82         FilterCriteria criteria = (FilterCriteria)o;
83         return criteria.column==column && criteria.active==active;
84     }
85
86     public int hashCode() {
87         return column ^ (active ? 0 : 2^31);
88     }
89 }
90
Popular Tags