Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexedSubstringPatternFilter.java')
-rw-r--r--org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexedSubstringPatternFilter.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexedSubstringPatternFilter.java b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexedSubstringPatternFilter.java
new file mode 100644
index 000000000..ab0379efc
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexedSubstringPatternFilter.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * A pattern filter that uses a {@link TaskListIndex} to support ITask matching.
+ *
+ * @author David Green
+ */
+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