*
* @param rootDirectoryTreeNode the root directory of the tree structure.
*/
public void setTreeContent(DirectoryTreeNode rootDirectoryTreeNode) {
innerSelection = true;
ATreeNode selectedNode = this.getSelection();
int nbRows = configTree.getRowCount();
Set<ATreeNode> expandedNodesSet = new HashSet<ATreeNode>();
TreePath treePath;
for (int rowIndex = 0; rowIndex < nbRows; ++rowIndex) {
if (configTree.isExpanded(rowIndex)) {
treePath = configTree.getPathForRow(rowIndex);
Object[] pathElementsArray = treePath.getPath();
List<ATreeNode> pathElementsList = new ArrayList<ATreeNode>(
pathElementsArray.length);
for (Object element : pathElementsArray) {
pathElementsList.add((ATreeNode) ((DefaultMutableTreeNode) element)
.getUserObject());
}
expandedNodesSet.addAll(pathElementsList);
}
}
DefaultMutableTreeNode rootNode = buildJTreeNodeFromWrapper(rootDirectoryTreeNode);
treeModel = new DefaultTreeModel(rootNode);
configTree.setModel(treeModel);
nbRows = configTree.getRowCount();
for (int rowIndex = 0; rowIndex < nbRows; ++rowIndex) {
treePath = configTree.getPathForRow(rowIndex);
ATreeNode treeNode = (ATreeNode) ((DefaultMutableTreeNode) treePath
.getLastPathComponent()).getUserObject();
if (expandedNodesSet.contains(treeNode)) {
configTree.expandRow(rowIndex);
nbRows = configTree.getRowCount();
}
}
ATreeNode treeNode;
for (int rowIndex = 0; rowIndex < nbRows; ++rowIndex) {
treePath = configTree.getPathForRow(rowIndex);
treeNode = (ATreeNode) ((DefaultMutableTreeNode) treePath.getLastPathComponent())
.getUserObject();
if (treeNode.equals(selectedNode)) {
configTree.addSelectionRow(rowIndex);
}
}
innerSelection = false;
}