| Try to find a given node in the logical view.
If some node within the logical view tree has the supplied object
in its lookup, it ought to be returned if that is practical.
If there are multiple such nodes, the one most suitable for display
to the user should be returned.
This may be used to select nodes corresponding to files, etc.
The following constraint should hold:
private static boolean isAncestor(Node root, Node n) {
if (n == null) return false;
if (n == root) return true;
return isAncestor(root, n.getParentNode());
}
// ...
Node root = ...;
Object target = ...;
LogicalViewProvider lvp = ...;
Node n = lvp.findPath(root, target);
if (n != null) {
assert isAncestor(root, n);
Lookup.Template tmpl = new Lookup.Template(null, null, target);
Collection res = n.getLookup().lookup(tmpl).allInstances();
assert Collections.singleton(target).equals(new HashSet(res));
}
Parameters: root - a root node. E.g. a node from LogicalViewProvider.createLogicalView or some wapper(FilterNode) around the node. The provider of the functionality isresponsible for finding the appropriate node in the wrapper's children. Parameters: target - a target cookie, such as a org.openide.loaders.DataObject a subnode with that cookie, or null |