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;
 }
示例#2
0
文件: TreeState.java 项目: jexp/idea2
  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();
  }
示例#3
0
文件: TreeState.java 项目: jexp/idea2
 private static String getDescriptorType(final NodeDescriptor nodeDescriptor) {
   return nodeDescriptor.getClass().getName();
 }