private ArrayList<TreeNode> childrenToArray(DefaultMutableTreeNode node) { ArrayList<TreeNode> arrayList = new ArrayList<TreeNode>(); for (int i = 0; i < node.getChildCount(); i++) { arrayList.add(node.getChildAt(i)); } return arrayList; }
public boolean restoreSelection(TreeSelection treeSelection) { if (treeSelection.isEmpty()) return false; DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot(); for (int i = 0; i < root.getChildCount(); i++) { TreeNode node = root.getChildAt(i); if (node instanceof MessageNode) { MessageNode messageNode = (MessageNode) node; String[] text = messageNode.getText(); if (text.length == 0) continue; if (Comparing.equal(treeSelection.mySelectedTarget, text[0])) { TreePath pathToSelect = new TreePath(messageNode.getPath()); for (Enumeration enumeration = messageNode.children(); enumeration.hasMoreElements(); ) { Object o = enumeration.nextElement(); if (o instanceof MessageNode) { messageNode = (MessageNode) o; if (Comparing.equal(treeSelection.mySelectedTask, text[0])) { pathToSelect = new TreePath(messageNode.getPath()); break; } } } TreeUtil.selectPath(myTree, pathToSelect); myTree.expandPath(pathToSelect); return true; } } } return false; }
private void collapseTargets() { DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot(); for (int i = 0; i < root.getChildCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i); myTree.collapsePath(new TreePath(node.getPath())); } }
private static DefaultMutableTreeNode findInChildren( DefaultMutableTreeNode currentTreeNode, AbstractTreeNode topPathElement) { for (int i = 0; i < currentTreeNode.getChildCount(); i++) { TreeNode child = currentTreeNode.getChildAt(i); if (((DefaultMutableTreeNode) child).getUserObject().equals(topPathElement)) { return (DefaultMutableTreeNode) child; } } return null; }
private void restoreUsageExpandState(final Collection<UsageState> states) { // always expand the last level group final DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot(); for (int i = root.getChildCount() - 1; i >= 0; i--) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i); if (child instanceof GroupNode) { final TreePath treePath = new TreePath(child.getPath()); myTree.expandPath(treePath); } } myTree.getSelectionModel().clearSelection(); for (final UsageState usageState : states) { usageState.restore(); } }
private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) { if (!myTree.isExpanded(pathFrom)) { return; } final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent(); final int childCount = node.getChildCount(); for (int idx = 0; idx < childCount; idx++) { final TreeNode child = node.getChildAt(idx); if (child instanceof UsageNode) { final Usage usage = ((UsageNode) child).getUsage(); states.add( new UsageState( usage, myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child)))); } else { captureUsagesExpandState(pathFrom.pathByAddingChild(child), states); } } }