10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.viewers.ViewerFilter;
|
|
14
|
|
15 import dwtx.jface.viewers.Viewer;
|
|
16 import dwtx.jface.viewers.TreePath;
|
|
17
|
|
18 import tango.util.collection.ArraySeq;
|
|
19
|
|
20 import dwt.dwthelper.utils;
|
|
21
|
|
22 /**
|
|
23 * A viewer filter is used by a structured viewer to
|
|
24 * extract a subset of elements provided by its content provider.
|
|
25 * <p>
|
|
26 * Subclasses must implement the <code>select</code> method
|
|
27 * and may implement the <code>isFilterProperty</code> method.
|
|
28 * </p>
|
|
29 * @see IStructuredContentProvider
|
|
30 * @see StructuredViewer
|
|
31 */
|
|
32 public abstract class ViewerFilter {
|
|
33 /**
|
|
34 * Creates a new viewer filter.
|
|
35 */
|
|
36 protected this() {
|
|
37 }
|
|
38
|
|
39 /**
|
|
40 * Filters the given elements for the given viewer.
|
|
41 * The input array is not modified.
|
|
42 * <p>
|
|
43 * The default implementation of this method calls
|
|
44 * <code>select</code> on each element in the array,
|
|
45 * and returns only those elements for which <code>select</code>
|
|
46 * returns <code>true</code>.
|
|
47 * </p>
|
|
48 * @param viewer the viewer
|
|
49 * @param parent the parent element
|
|
50 * @param elements the elements to filter
|
|
51 * @return the filtered elements
|
|
52 */
|
|
53 public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
|
|
54 int size = elements.length;
|
|
55 auto out_ = new ArraySeq!(Object);
|
|
56 out_.capacity(size);
|
|
57 for (int i = 0; i < size; ++i) {
|
|
58 Object element = elements[i];
|
|
59 if (select(viewer, parent, element)) {
|
|
60 out_.append(element);
|
|
61 }
|
|
62 }
|
|
63 return out_.toArray();
|
|
64 }
|
|
65
|
|
66 /**
|
|
67 * Filters the given elements for the given viewer.
|
|
68 * The input array is not modified.
|
|
69 * <p>
|
|
70 * The default implementation of this method calls
|
|
71 * {@link #filter(Viewer, Object, Object[])} with the
|
|
72 * parent from the path. Subclasses may override
|
|
73 * </p>
|
|
74 * @param viewer the viewer
|
|
75 * @param parentPath the path of the parent element
|
|
76 * @param elements the elements to filter
|
|
77 * @return the filtered elements
|
|
78 * @since 3.2
|
|
79 */
|
|
80 public Object[] filter(Viewer viewer, TreePath parentPath, Object[] elements) {
|
|
81 return filter(viewer, parentPath.getLastSegment(), elements);
|
|
82 }
|
|
83
|
|
84 /**
|
|
85 * Returns whether this viewer filter would be affected
|
|
86 * by a change to the given property of the given element.
|
|
87 * <p>
|
|
88 * The default implementation of this method returns <code>false</code>.
|
|
89 * Subclasses should reimplement.
|
|
90 * </p>
|
|
91 *
|
|
92 * @param element the element
|
|
93 * @param property the property
|
|
94 * @return <code>true</code> if the filtering would be affected,
|
|
95 * and <code>false</code> if it would be unaffected
|
|
96 */
|
|
97 public bool isFilterProperty(Object element, String property) {
|
|
98 return false;
|
|
99 }
|
|
100
|
|
101 /**
|
|
102 * Returns whether the given element makes it through this filter.
|
|
103 *
|
|
104 * @param viewer the viewer
|
|
105 * @param parentElement the parent element
|
|
106 * @param element the element
|
|
107 * @return <code>true</code> if element is included in the
|
|
108 * filtered set, and <code>false</code> if excluded
|
|
109 */
|
|
110 public abstract bool select(Viewer viewer, Object parentElement,
|
|
111 Object element);
|
|
112 }
|