/** * Handles a single node when traversing the outline tree. Used recursively. * * @param node * @param document * @param parentDepth * @param newOutlineInput * @return */ private int addNodePosition( OutlineNode node, IDocument document, int parentDepth, TexOutlineInput newOutlineInput) { // add the Document position int beginOffset = 0; int length = 0; Position position = null; try { beginOffset = document.getLineOffset(node.getBeginLine() - 1); if (node.getEndLine() - 1 == document.getNumberOfLines()) length = document.getLength() - beginOffset; else length = document.getLineOffset(node.getEndLine() - 1) - beginOffset; position = new Position(beginOffset, length); document.addPosition("__outline", position); } catch (BadLocationException bpe) { throw new OperationCanceledException(); } catch (BadPositionCategoryException bpce) { throw new OperationCanceledException(); } node.setPosition(position); // add node to outline input newOutlineInput.addNode(node); // iterate through the children List<OutlineNode> children = node.getChildren(); int maxDepth = parentDepth + 1; if (children != null) { for (Iterator<OutlineNode> iter = children.iterator(); iter.hasNext(); ) { int localDepth = addNodePosition(iter.next(), document, parentDepth + 1, newOutlineInput); if (localDepth > maxDepth) { maxDepth = localDepth; } } } return maxDepth; }