Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / dialogs / TreePatternFilter.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Inria
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Generoso Pagano, Inria - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs;
14
15 import org.eclipse.jface.viewers.AbstractTreeViewer;
16 import org.eclipse.jface.viewers.ITreeContentProvider;
17 import org.eclipse.jface.viewers.Viewer;
18 import org.eclipse.ui.dialogs.PatternFilter;
19
20 /**
21 * A filter extending the <code>org.eclipse.ui.dialogs.PatternFilter<code>.
22 *
23 * It redefines the {@link #isElementVisible(Viewer, Object)}} method in order
24 * to have a match on a node if: the node matches or one of the children matches
25 * or one of the parents matches.
26 *
27 * @author "Generoso Pagano <generoso.pagano@inria.fr>"
28 * @since 3.2
29 */
30 public class TreePatternFilter extends PatternFilter {
31
32 @Override
33 public boolean isElementVisible(Viewer viewer, Object element) {
34 return super.isElementVisible(viewer, element) || isChildMatch(viewer, element);
35 }
36
37 /**
38 * Check if at least one of the parents of this element is a match with the
39 * filter text.
40 *
41 * @param viewer
42 * the viewer that contains the element
43 * @param element
44 * the tree element to check
45 * @return true if the given element has a parent that matches the filter
46 * text
47 */
48 private boolean isChildMatch(Viewer viewer, Object element) {
49 Object parent = ((ITreeContentProvider) ((AbstractTreeViewer) viewer).getContentProvider())
50 .getParent(element);
51 while (parent != null) {
52 if (isLeafMatch(viewer, parent)) {
53 return true;
54 }
55 parent = ((ITreeContentProvider) ((AbstractTreeViewer) viewer).getContentProvider())
56 .getParent(parent);
57 }
58 return false;
59 }
60
61 }
This page took 0.031813 seconds and 5 git commands to generate.