Node generated = new DirectoryTreeFilterNode(new AbstractNode(new RootContentChildren(hierarchy)), true);
Children genChilds = generated.getChildren();
final DirectoryTreeTopComponent dirTree = DirectoryTreeTopComponent.findInstance();
TreeView dirTreeView = dirTree.getTree();
ExplorerManager dirTreeExplorerManager = dirTree.getExplorerManager();
Node dirTreeRootNode = dirTreeExplorerManager.getRootContext();
Children dirChilds = dirTreeRootNode.getChildren();
Children currentChildren = dirChilds.findChild(DataSourcesNode.NAME).getChildren();
Node dirExplored = null;
// Find the parent node of the content in the directory tree
for (int i = 0; i < genChilds.getNodesCount() - 1; i++) {
Node currentGeneratedNode = genChilds.getNodeAt(i);
for (int j = 0; j < currentChildren.getNodesCount(); j++) {
Node currentDirectoryTreeNode = currentChildren.getNodeAt(j);
if (currentGeneratedNode.getDisplayName().equals(currentDirectoryTreeNode.getDisplayName())) {
dirExplored = currentDirectoryTreeNode;
dirTreeView.expandNode(dirExplored);
currentChildren = currentDirectoryTreeNode.getChildren();
break;
}
}
}
// Set the parent node of the content as the selection in the
// directory tree
try {
if (dirExplored != null) {
dirTreeView.expandNode(dirExplored);
dirTreeExplorerManager.setExploredContextAndSelection(dirExplored, new Node[]{dirExplored});
}
} catch (PropertyVetoException ex) {
logger.log(Level.WARNING, "Couldn't set selected node", ex); //NON-NLS
}