Revision 2285 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/TreeModelRecursiveWildcarMatchFilter.java
TreeModelRecursiveWildcarMatchFilter.java | ||
---|---|---|
3 | 3 |
import javax.swing.tree.TreeModel; |
4 | 4 |
import org.apache.commons.io.FilenameUtils; |
5 | 5 |
import org.apache.commons.lang3.StringUtils; |
6 |
import org.gvsig.tools.swing.api.FilteredTreeModel.TreeModelFilter;
|
|
6 |
import org.gvsig.tools.swing.api.FilteredModel.FilterFunction;
|
|
7 | 7 |
|
8 | 8 |
/** |
9 | 9 |
* |
10 | 10 |
* @author jjdelcerro |
11 | 11 |
*/ |
12 |
public class TreeModelRecursiveWildcarMatchFilter implements TreeModelFilter {
|
|
12 |
public class TreeModelRecursiveWildcarMatchFilter implements FilterFunction {
|
|
13 | 13 |
|
14 |
private final String filter; |
|
15 |
|
|
16 |
public TreeModelRecursiveWildcarMatchFilter(String filter) { |
|
17 |
if (StringUtils.isBlank(filter)) { |
|
18 |
this.filter = null; |
|
19 |
} else { |
|
20 |
if (StringUtils.containsAny(filter, "*?")) { |
|
21 |
this.filter = filter.toUpperCase(); |
|
22 |
} else { |
|
23 |
this.filter = "*" + filter.toUpperCase() + "*"; |
|
24 |
} |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 | 14 |
@Override |
29 |
public boolean test(TreeModel treeModel, Object node) {
|
|
30 |
if ( this.filter==null ) {
|
|
15 |
public boolean test(Object model, Object node, String filter) {
|
|
16 |
if ( node==null ) {
|
|
31 | 17 |
return true; |
32 | 18 |
} |
33 |
if ( node==null ) {
|
|
19 |
if ( StringUtils.isBlank(filter) ) {
|
|
34 | 20 |
return true; |
35 | 21 |
} |
36 | 22 |
String nodeString = node.toString().toUpperCase(); |
37 | 23 |
boolean matches = FilenameUtils.wildcardMatch(nodeString, filter); |
38 | 24 |
|
39 |
int childCount = treeModel.getChildCount(node);
|
|
25 |
int childCount = ((TreeModel)model).getChildCount(node);
|
|
40 | 26 |
for (int i = 0; i < childCount; i++) { |
41 |
Object child = treeModel.getChild(node, i);
|
|
42 |
matches |= test(treeModel, child);
|
|
27 |
Object child = ((TreeModel)model).getChild(node, i);
|
|
28 |
matches |= test(model, child, filter);
|
|
43 | 29 |
} |
44 | 30 |
return matches; |
45 | 31 |
} |
46 |
|
|
32 |
|
|
47 | 33 |
} |
Also available in: Unified diff