1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 import java.util.*; 14 15 import org.eclipse.jface.viewers.Viewer; 16 import org.eclipse.jface.viewers.ViewerFilter; 17 import org.eclipse.team.core.history.ITag; 18 import org.eclipse.team.internal.ccvs.core.filehistory.CVSFileRevision; 19 import org.eclipse.team.internal.ui.history.AbstractHistoryCategory; 20 21 public class CVSHistorySearchFilter extends org.eclipse.jface.viewers.ViewerFilter { 22 23 public String searchString; 24 private int matchCounter; 25 public ArrayList searchStrings; 26 27 public CVSHistorySearchFilter(String searchStrings) { 28 this.searchString = searchStrings; 29 } 30 31 34 public boolean select(Viewer aviewer, Object parentElement, Object element) { 35 if (element instanceof AbstractHistoryCategory) 36 return true; 37 38 if (element instanceof CVSFileRevision) { 39 StringTokenizer tokenizer = new StringTokenizer(searchString); 40 searchStrings = new ArrayList(); 41 while (tokenizer.hasMoreElements()) { 42 searchStrings.add(tokenizer.nextToken()); 43 } 44 45 CVSFileRevision entry = (CVSFileRevision) element; 46 boolean orSearch = (authorMatch(entry)) || (dateMatch(entry)) || (commentMatch(entry) || revisionMatch(entry) || tagMatch(entry)); 48 if (orSearch) 49 matchCounter++; 50 return orSearch; 51 } 52 return false; 53 } 54 55 protected boolean authorMatch(CVSFileRevision revision) { 56 String author = revision.getAuthor(); 57 if (author != null){ 58 Iterator iter = searchStrings.iterator(); 59 while (iter.hasNext()) { 60 String nextString = (String ) iter.next(); 61 if (!((author.indexOf(nextString)) == -1)) 62 return true; 63 } 64 } 65 return false; 66 } 67 68 protected boolean commentMatch(CVSFileRevision revision) { 69 String comment = revision.getComment().toLowerCase(); 70 if (comment != null) { 71 Iterator iter = searchStrings.iterator(); 72 while (iter.hasNext()) { 73 if (!(comment.indexOf(((String ) iter.next()).toLowerCase()) == -1)) 74 return true; 75 } 76 } 77 return false; 78 } 79 80 protected boolean dateMatch(CVSFileRevision revision) { 81 88 89 return false; 90 } 91 92 protected boolean tagMatch(CVSFileRevision revision) { 93 ITag[] tags = revision.getTags(); 94 for (int i = 0; i < tags.length; i++) { 95 String tag = tags[i].getName().toLowerCase(); 96 Iterator iter = searchStrings.iterator(); 97 while (iter.hasNext()) { 98 if (!(tag.indexOf(((String ) iter.next()).toLowerCase()) == -1)) 99 return true; 100 } 101 } 102 103 return false; 104 } 105 106 protected boolean revisionMatch(CVSFileRevision revision) { 107 String rev = revision.getContentIdentifier(); 108 if (rev != null) { 109 Iterator iter = searchStrings.iterator(); 110 while (iter.hasNext()) { 111 if (!(rev.indexOf(((String ) iter.next()).toLowerCase()) == -1)) 112 return true; 113 } 114 } 115 return false; 116 } 117 118 119 public int getMatchCount() { 120 return matchCounter; 121 } 122 123 } 124 | Popular Tags |