1 19 20 21 package org.netbeans.modules.i18n; 22 23 import org.openide.nodes.FilterNode; 24 import org.openide.nodes.Node; 25 26 27 28 29 36 public class FilteredNode extends FilterNode { 37 38 private NodeFilter filter; 39 private String newName = null; 40 41 45 public interface NodeFilter { 46 public boolean acceptNode(Node node) ; 47 } 48 49 public FilteredNode(Node original, NodeFilter filter ) { 50 this(original, filter, null); 51 } 52 53 54 55 public FilteredNode(Node original, NodeFilter filter, String newName) { 56 super(original, new FilteredChildren(original, filter)); 57 this.filter = filter; 58 this.newName = newName; 59 } 60 61 public String getDisplayName() { 62 if (newName != null) return newName; else return super.getDisplayName(); 63 } 64 65 public Node cloneNode() { 66 return new FilteredNode(this.getOriginal().cloneNode(), this.filter); 67 } 68 69 70 71 72 77 public static class FilteredChildren extends FilterNode.Children { 78 private NodeFilter filter; 79 80 public FilteredChildren(Node original, NodeFilter filter) { 81 super(original); 82 this.filter = filter; 83 } 84 85 protected Node copyNode(Node node) { 86 return new FilteredNode(node, this.filter); 87 } 88 89 protected Node[] createNodes(Object key) { 90 if (filter.acceptNode((Node)key)) 91 return super.createNodes(key); 92 else 93 return new Node [0]; 94 } 95 96 } 97 98 } 99 | Popular Tags |