Mercurial > projects > dwt2
comparison org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerFilter.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
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 org.eclipse.jface.viewers.ViewerFilter; | |
14 | |
15 import org.eclipse.jface.viewers.Viewer; | |
16 import org.eclipse.jface.viewers.TreePath; | |
17 | |
18 | |
19 import java.lang.all; | |
20 import java.util.ArrayList; | |
21 import java.util.Set; | |
22 | |
23 /** | |
24 * A viewer filter is used by a structured viewer to | |
25 * extract a subset of elements provided by its content provider. | |
26 * <p> | |
27 * Subclasses must implement the <code>select</code> method | |
28 * and may implement the <code>isFilterProperty</code> method. | |
29 * </p> | |
30 * @see IStructuredContentProvider | |
31 * @see StructuredViewer | |
32 */ | |
33 public abstract class ViewerFilter { | |
34 /** | |
35 * Creates a new viewer filter. | |
36 */ | |
37 protected this() { | |
38 } | |
39 | |
40 /** | |
41 * Filters the given elements for the given viewer. | |
42 * The input array is not modified. | |
43 * <p> | |
44 * The default implementation of this method calls | |
45 * <code>select</code> on each element in the array, | |
46 * and returns only those elements for which <code>select</code> | |
47 * returns <code>true</code>. | |
48 * </p> | |
49 * @param viewer the viewer | |
50 * @param parent the parent element | |
51 * @param elements the elements to filter | |
52 * @return the filtered elements | |
53 */ | |
54 public Object[] filter(Viewer viewer, Object parent, Object[] elements) { | |
55 int size = elements.length; | |
56 ArrayList out_ = new ArrayList(size); | |
57 for (int i = 0; i < size; ++i) { | |
58 Object element = elements[i]; | |
59 if (select(viewer, parent, element)) { | |
60 out_.add(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 } |