boolean (int increment) { final DefaultMutableTreeNode[] selectedNodes = myTree.getSelectedNodes(DefaultMutableTreeNode.class, null); if (selectedNodes.length == 0) return false; boolean enabled = true; for (DefaultMutableTreeNode node : selectedNodes) { final DefaultMutableTreeNode sibling = increment == -1 ? node.getPreviousSibling() : node.getNextSibling(); enabled = enabled && (node.getUserObject() instanceof TaskNode) && sibling != null; } if (!enabled) { enabled = true; for (DefaultMutableTreeNode node : selectedNodes) { final DefaultMutableTreeNode sibling = increment == -1 ? node.getPreviousSibling() : node.getNextSibling(); enabled = enabled && (node.getUserObject() instanceof ProjectNode) && sibling != null; } } return enabled; }