blob: 9966bb4eb3df15f20668f145040d46c1e85abb76 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
package org.eclipse.team.internal.ccvs.ui;
import java.util.Date;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.team.internal.ccvs.core.ILogEntry;
public class HistoryFilter extends ViewerFilter {
private HistoryView view;
public String author;
public Date fromDate;
public Date toDate;
public String comment;
public boolean isOr;
public HistoryFilter(HistoryView hView, String author, String comment, Date fromDate, Date toDate, boolean isOr) {
this.view = hView;
this.author = author;
this.comment = comment;
this.fromDate = fromDate;
this.toDate = toDate;
this.isOr = isOr;
}
/**
* @see ViewerFilter#select(Viewer, Object, Object)
*/
public boolean select(Viewer aviewer, Object parentElement, Object element) {
if (element instanceof ILogEntry) {
ILogEntry entry = (ILogEntry)element;
if (isOr) {
//empty fields should be considered a non-match
return (hasAuthor() && authorMatch(entry) )
|| (hasDate() && dateMatch(entry))
|| (hasComment() && commentMatch(entry));
} else {
//"and" search
//empty fields should be considered a match
return (!hasAuthor() || authorMatch(entry))
&& (!hasDate() || dateMatch(entry))
&& (!hasComment() || commentMatch(entry));
}
}
return false;
}
protected boolean authorMatch(ILogEntry entry) {
return entry.getAuthor().equals(author);
}
protected boolean commentMatch(ILogEntry entry) {
return !(entry.getComment().toLowerCase().indexOf(comment.toLowerCase()) == -1);
}
protected boolean dateMatch(ILogEntry entry) {
return (fromDate.before(entry.getDate()))
&& (toDate.after(entry.getDate()));
}
protected boolean hasAuthor() {
return !author.equals(""); //$NON-NLS-1$
}
protected boolean hasComment() {
return !comment.equals(""); //$NON-NLS-1$
}
protected boolean hasDate() {
return fromDate != null && toDate != null;
}
}
|