diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..64901f548cdc5c04a7d7fd8782284d3b191c8a12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +.project +.classpath +.settings diff --git a/src/main/java/fr/soleil/bensikin/components/context/detail/AttributesTree.java b/src/main/java/fr/soleil/bensikin/components/context/detail/AttributesTree.java index ea460c4ee6f29a3885e8effb9d67c9c4730d3319..191ed866bc2c85550ac8e3933d5c5523dcb6f8da 100644 --- a/src/main/java/fr/soleil/bensikin/components/context/detail/AttributesTree.java +++ b/src/main/java/fr/soleil/bensikin/components/context/detail/AttributesTree.java @@ -59,17 +59,17 @@ public class AttributesTree extends BensikinTree { /** * Standard tree building from a model, plus sets the following options: - * -setExpandsSelectedPaths ( true ) -->expands selected paths - * -setScrollsOnExpand ( true ) -->scrolls if necessary on expansion - * -setShowsRootHandles ( true ) --> shows the root handle even if empty - * -setToggleClickCount ( 1 ) -->one click tree expansion/collapse + * <ul> + * <li><code>setExpandsSelectedPaths(true)</code> --> expands selected paths</li> + * <li><code>setScrollsOnExpand(true)</code> --> scrolls if necessary on expansion</li> + * <li><code>setShowsRootHandles(true)</code> --> shows the root handle even if empty</li> + * <li><code>setToggleClickCount(1)</code> --> one click tree expansion/collapse</li> + * </ul> * - * @param newModel - * The model + * @param newModel The model */ protected AttributesTree(TreeModel newModel) { super(newModel); - this.setExpandsSelectedPaths(true); this.setScrollsOnExpand(true); this.setShowsRootHandles(true); @@ -78,40 +78,37 @@ public class AttributesTree extends BensikinTree { } /** - * Returns a list of all the tree attributes that are under a currently - * selected node. Warning, since attributes trees are only loaded up to - * member level until each member is clicked, the list will be empty if no - * member's attributes list has been loaded yet. + * Returns a list of all the tree attributes that are under a currently selected node. Warning, since attributes + * trees are only loaded up to member level until each member is clicked, the list will be empty if no member's + * attributes list has been loaded yet. * - * @param remove - * If true, removes each of the found nodes from the tree - * @return A List containing TreePath objects, each representing the path to - * one of the attributes under one of the selected nodes. + * @param remove If true, removes each of the found nodes from the tree + * @return A List containing TreePath objects, each representing the path to one of the attributes under one of the + * selected nodes. */ public List<TreePath> getListOfAttributesTreePathUnderSelectedNodes(boolean remove) { + List<TreePath> attributes = new ArrayList<>(); TreePath[] selectedPath = this.getSelectionPaths(); - if (selectedPath == null || selectedPath.length == 0) { - return null; - } - List<TreePath> attributes = new ArrayList<TreePath>(); - // as many loops as there are selected nodes - for (int i = 0; i < selectedPath.length; i++) { - TreePath currentSelectedTreePath = selectedPath[i]; - DefaultMutableTreeNode currentSelectedNode = (DefaultMutableTreeNode) currentSelectedTreePath - .getLastPathComponent(); - // String name = ( String ) currentSelectedNode.getUserObject(); - Enumeration<?> enumer = currentSelectedNode.preorderEnumeration(); - // for each selected nodes, we loop up all its attribute-level nodes - while (enumer.hasMoreElements()) { - DefaultMutableTreeNode currentTraversedNode = (DefaultMutableTreeNode) enumer.nextElement(); - if (currentTraversedNode.getLevel() == AttributesTreeModel.CONTEXT_TREE_DEPTH - 1) { - TreeNode[] path = currentTraversedNode.getPath(); - TreePath toAdd = new TreePath(path); - attributes.add(toAdd); + if ((selectedPath != null) && (selectedPath.length > 0)) { + // as many loops as there are selected nodes + for (int i = 0; i < selectedPath.length; i++) { + TreePath currentSelectedTreePath = selectedPath[i]; + DefaultMutableTreeNode currentSelectedNode = (DefaultMutableTreeNode) currentSelectedTreePath + .getLastPathComponent(); + // String name = ( String ) currentSelectedNode.getUserObject(); + Enumeration<?> enumer = currentSelectedNode.preorderEnumeration(); + // for each selected nodes, we loop up all its attribute-level nodes + while (enumer.hasMoreElements()) { + DefaultMutableTreeNode currentTraversedNode = (DefaultMutableTreeNode) enumer.nextElement(); + if (currentTraversedNode.getLevel() == AttributesTreeModel.CONTEXT_TREE_DEPTH - 1) { + TreeNode[] path = currentTraversedNode.getPath(); + TreePath toAdd = new TreePath(path); + attributes.add(toAdd); + } + } + if (remove) { + currentSelectedNode.removeFromParent(); } - } - if (remove) { - currentSelectedNode.removeFromParent(); } } return attributes;