Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9e82fb41d1a1f34f2bc7a420cfb873ff76fa5412 (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
/*******************************************************************************
 * Copyright (c) 2004, 2009 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *     Wim Jongman - Maintenance (391086)
 *******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;

public class PatternFilter extends org.eclipse.e4.ui.workbench.swt.internal.copy.PatternFilter {

	/**
	 * This constructor will call {@link #setIncludeLeadingWildcard(boolean)}
	 * with boolean=true.
	 */
	public PatternFilter() {
		setIncludeLeadingWildcard(true);
	}

	/**
	 * Check if the current (leaf) element is a match with the filter text. The
	 * default behavior checks that the label of the element is a match.
	 * 
	 * Subclasses should override this method.
	 * 
	 * @param viewer
	 *            the viewer that contains the element
	 * @param element
	 *            the tree element to check
	 * @return true if the given element's label matches the filter text
	 */
	protected boolean isLeafMatch(Viewer viewer, Object element) {

		Object labelProvider = ((StructuredViewer) viewer).getLabelProvider();
		String labelText = null;

		if (labelProvider instanceof ILabelProvider) {
			labelText = ((ILabelProvider) labelProvider).getText(element);
		} else {
			labelText = element.toString();
		}

		if (labelText == null) {
			return false;
		}
		return wordMatches(labelText);
	}

}

Back to the top