public static Object extractUserObject(DefaultMutableTreeNode node) { Object userObject = node.getUserObject(); Object element = null; if (userObject instanceof AbstractTreeNode) { AbstractTreeNode descriptor = (AbstractTreeNode) userObject; element = descriptor.getValue(); } else if (userObject instanceof NodeDescriptor) { NodeDescriptor descriptor = (NodeDescriptor) userObject; element = descriptor.getElement(); if (element instanceof AbstractTreeNode) { element = ((AbstractTreeNode) element).getValue(); } } else if (userObject != null) { element = userObject; } return element; }
private static String getDescriptorKey(final NodeDescriptor nodeDescriptor) { if (nodeDescriptor instanceof AbstractTreeNode) { Object value; if (nodeDescriptor instanceof NodeDescriptorProvidingKey) { value = ((NodeDescriptorProvidingKey) nodeDescriptor).getKey(); } else { value = ((AbstractTreeNode) nodeDescriptor).getValue(); } if (value instanceof NavigationItem) { try { final String name = ((NavigationItem) value).getName(); return name != null ? name : value.toString(); } catch (Exception e) { // ignore for invalid psi element } } } return nodeDescriptor.toString(); }
private static String getDescriptorType(final NodeDescriptor nodeDescriptor) { return nodeDescriptor.getClass().getName(); }