KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > HistoryFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui;
12
13 import java.util.Date JavaDoc;
14 import org.eclipse.jface.viewers.Viewer;
15 import org.eclipse.jface.viewers.ViewerFilter;
16 import org.eclipse.team.internal.ccvs.core.ILogEntry;
17
18 public class HistoryFilter extends ViewerFilter {
19     private HistoryView view;
20     public String JavaDoc author;
21     public Date JavaDoc fromDate;
22     public Date JavaDoc toDate;
23     public String JavaDoc comment;
24     public boolean isOr;
25
26     public HistoryFilter(HistoryView hView, String JavaDoc author, String JavaDoc comment, Date JavaDoc fromDate, Date JavaDoc toDate, boolean isOr) {
27         this.view = hView;
28         this.author = author;
29         this.comment = comment;
30         this.fromDate = fromDate;
31         this.toDate = toDate;
32         this.isOr = isOr;
33     }
34     /**
35      * @see ViewerFilter#select(Viewer, Object, Object)
36      */

37     public boolean select(Viewer aviewer, Object JavaDoc parentElement, Object JavaDoc element) {
38         if (element instanceof ILogEntry) {
39             ILogEntry entry = (ILogEntry)element;
40             if (isOr) {
41                 //empty fields should be considered a non-match
42
return (hasAuthor() && authorMatch(entry) )
43                 || (hasDate() && dateMatch(entry))
44                 || (hasComment() && commentMatch(entry));
45             } else {
46                 //"and" search
47
//empty fields should be considered a match
48
return (!hasAuthor() || authorMatch(entry))
49                     && (!hasDate() || dateMatch(entry))
50                     && (!hasComment() || commentMatch(entry));
51             }
52         }
53         return false;
54     }
55     protected boolean authorMatch(ILogEntry entry) {
56         return entry.getAuthor().equals(author);
57     }
58     protected boolean commentMatch(ILogEntry entry) {
59         return !(entry.getComment().toLowerCase().indexOf(comment.toLowerCase()) == -1);
60     }
61     protected boolean dateMatch(ILogEntry entry) {
62         return (fromDate.before(entry.getDate()))
63             && (toDate.after(entry.getDate()));
64     }
65     protected boolean hasAuthor() {
66         return !author.equals(""); //$NON-NLS-1$
67
}
68     protected boolean hasComment() {
69         return !comment.equals(""); //$NON-NLS-1$
70
}
71     protected boolean hasDate() {
72         return fromDate != null && toDate != null;
73     }
74 }
75
Popular Tags