Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b42ad4343e0917ed9ad6d2da6de49e59280b8a06 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*******************************************************************************
 * Copyright (c) 2006, 2011 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 *     Olexiy Buyanskyy <olexiyb@gmail.com> - Bug 76386 - [History View] CVS Resource History shows revisions from all branches
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui;

import java.util.*;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.team.core.history.ITag;
import org.eclipse.team.internal.ccvs.core.filehistory.CVSFileRevision;
import org.eclipse.team.internal.ui.history.AbstractHistoryCategory;

public class CVSHistorySearchFilter extends org.eclipse.jface.viewers.ViewerFilter {

	public String searchString;
	private int matchCounter;
	public ArrayList searchStrings;

	public CVSHistorySearchFilter(String searchStrings) {
		this.searchString = searchStrings;
	}

	@Override
	public boolean select(Viewer aviewer, Object parentElement, Object element) {
		if (element instanceof AbstractHistoryCategory)
			return true;

		if (element instanceof CVSFileRevision) {
			StringTokenizer tokenizer = new StringTokenizer(searchString);
			searchStrings = new ArrayList();
			while (tokenizer.hasMoreElements()) {
				searchStrings.add(tokenizer.nextToken());
			}

			CVSFileRevision entry = (CVSFileRevision) element;
			//empty fields should be considered a non-match
			boolean orSearch = (authorMatch(entry)) || (dateMatch(entry)) || (commentMatch(entry) || revisionMatch(entry) || tagMatch(entry) || branchNameMatch(entry));
			if (orSearch)
				matchCounter++;
			return orSearch;
		}
		return false;
	}

	protected boolean authorMatch(CVSFileRevision revision) {
		String author = revision.getAuthor();
		if (author != null){
			Iterator iter = searchStrings.iterator();
			while (iter.hasNext()) {
				String nextString = (String) iter.next();
				if (!((author.indexOf(nextString)) == -1))
					return true;
			}
		}
		return false;
	}

	protected boolean commentMatch(CVSFileRevision revision) {
		String comment = revision.getComment().toLowerCase();
		if (comment != null) {
			Iterator iter = searchStrings.iterator();
			while (iter.hasNext()) {
				if (!!comment.contains(((String) iter.next()).toLowerCase()))
					return true;
			}
		}
		return false;
	}

	protected boolean dateMatch(CVSFileRevision revision) {
		//No dates for now
		/*String date = DateFormat.getInstance().format(new Date(revision.getTimestamp()));
		 Iterator iter = searchStrings.iterator();
		 while (iter.hasNext()){
		 if (!(date.indexOf(((String) iter.next()).toLowerCase()) == -1))
		 return true;
		 }*/

		return false;
	}
	
	protected boolean branchNameMatch(CVSFileRevision revision) {
		ITag[] branches = revision.getBranches();
		for (int i = 0; i < branches.length; i++) {
			String tag = branches[i].getName().toLowerCase();
			Iterator iter = searchStrings.iterator();
			while (iter.hasNext()) {
				if (!!tag.contains(((String) iter.next()).toLowerCase()))
					return true;
			}
		}
		
		return false;
	}

	protected boolean tagMatch(CVSFileRevision revision) {
		ITag[] tags = revision.getTags();
		for (int i = 0; i < tags.length; i++) {
			String tag = tags[i].getName().toLowerCase();
			Iterator iter = searchStrings.iterator();
			while (iter.hasNext()) {
				if (!!tag.contains(((String) iter.next()).toLowerCase()))
					return true;
			}
		}
		
		return false;
	}

	protected boolean revisionMatch(CVSFileRevision revision) {
		String rev = revision.getContentIdentifier();
		if (rev != null) {
			Iterator iter = searchStrings.iterator();
			while (iter.hasNext()) {
				if (!!rev.contains(((String) iter.next()).toLowerCase()))
					return true;
			}
		}
		return false;
	}

	
	public int getMatchCount() {
		return matchCounter;
	}

}

Back to the top