Skip to main content
summaryrefslogtreecommitdiffstats
blob: 68b98af07c118589b6809d198464cd27b384ebf2 (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
/*******************************************************************************
 * Copyright (c) 2011 Tasktop Technologies.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.internal.tasks.index.ui;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.mylyn.commons.workbench.SubstringPatternFilter;
import org.eclipse.mylyn.internal.tasks.index.core.TaskListIndex;
import org.eclipse.mylyn.tasks.core.ITask;

public class IndexedSubstringPatternFilter extends SubstringPatternFilter {

	private final TaskListIndex index;

	private String patternString;

	public IndexedSubstringPatternFilter(TaskListIndex index) {
		this.index = index;
	}

	@Override
	public void setPattern(String patternString) {
		if (patternString != null) {
			patternString = patternString.trim();
		}
		this.patternString = patternString;
		super.setPattern(patternString);
	}

	@Override
	protected boolean isLeafMatch(Viewer viewer, Object element) {
		if (patternString != null && patternString.length() > 0) {
			if (element instanceof ITask) {
				ITask task = (ITask) element;
				if (index.matches(task, patternString)) {
					return true;
				} else {
					// fall through so that we get non-indexed matching semantics
				}
			}
		}
		return super.isLeafMatch(viewer, element);
	}
}

Back to the top