1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 import java.util.Date ; 14 15 import org.eclipse.jface.viewers.Viewer; 16 import org.eclipse.jface.viewers.ViewerFilter; 17 import org.eclipse.team.internal.ccvs.core.filehistory.CVSFileRevision; 18 import org.eclipse.team.internal.ui.history.AbstractHistoryCategory; 19 20 public class CVSHistoryFilter extends ViewerFilter { 21 public String author; 22 public Date fromDate; 23 public Date toDate; 24 public String comment; 25 public boolean isOr; 26 private int matchCounter; 27 28 public CVSHistoryFilter(String author, String comment, Date fromDate, Date toDate, boolean isOr) { 29 this.author = author; 30 this.comment = comment; 31 this.fromDate = fromDate; 32 this.toDate = toDate; 33 this.isOr = isOr; 34 this.matchCounter = 0; 35 } 36 37 40 public boolean select(Viewer aviewer, Object parentElement, Object element) { 41 if (element instanceof AbstractHistoryCategory) 42 return true; 43 44 if (element instanceof CVSFileRevision) { 45 CVSFileRevision entry = (CVSFileRevision) element; 46 if (isOr) { 47 boolean orSearch = (hasAuthor() && authorMatch(entry)) || (hasDate() && dateMatch(entry)) || (hasComment() && commentMatch(entry)); 49 if (orSearch) 50 matchCounter++; 51 52 return orSearch; 53 } else { 54 boolean andSearch = (!hasAuthor() || authorMatch(entry)) && (!hasDate() || dateMatch(entry)) && (!hasComment() || commentMatch(entry)); 57 if (andSearch) 58 matchCounter++; 59 60 return andSearch; 61 } 62 } 63 return false; 64 } 65 66 protected boolean authorMatch(CVSFileRevision revision) { 67 return revision.getAuthor().equals(author); 68 } 69 70 protected boolean commentMatch(CVSFileRevision revision) { 71 return !(revision.getComment().toLowerCase().indexOf(comment.toLowerCase()) == -1); 72 } 73 74 protected boolean dateMatch(CVSFileRevision revision) { 75 return isAfterFromDate(revision) && isBeforeToDate(revision); 76 } 77 78 private boolean isBeforeToDate(CVSFileRevision revision) { 79 if (toDate == null) 80 return true; 81 return (toDate.after(new Date (revision.getTimestamp()))); 82 } 83 84 private boolean isAfterFromDate(CVSFileRevision revision) { 85 if (fromDate == null) 86 return true; 87 return (fromDate.before(new Date (revision.getTimestamp()))); 88 } 89 90 protected boolean hasAuthor() { 91 return !author.equals(""); } 93 94 protected boolean hasComment() { 95 return !comment.equals(""); } 97 98 protected boolean hasDate() { 99 return fromDate != null || toDate != null; 100 } 101 102 public int getMatchCount(){ 103 return matchCounter; 104 } 105 } 106 | Popular Tags |