TodoItemNode () { TreePath path = myTree.getSelectionPath(); if (path == null) { return null; } DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); Object userObject = node.getUserObject(); if (!(userObject instanceof NodeDescriptor)) { return null; } Object element = ((NodeDescriptor<?>)userObject).getElement(); TodoItemNode pointer; if (element instanceof TodoItemNode) { pointer = myTodoTreeBuilder.getNextPointer((TodoItemNode)element); } else { pointer = myTodoTreeBuilder.getFirstPointerForElement(element); } return pointer; }