@Nullable
 private static Navigatable getNavigatableForNode(@NotNull DefaultMutableTreeNode node) {
   Object userObject = node.getUserObject();
   if (userObject instanceof Navigatable) {
     final Navigatable navigatable = (Navigatable) userObject;
     return navigatable.canNavigate() ? navigatable : null;
   }
   return null;
 }
 public Object getData(String dataId) {
   if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
     TreePath path = getSelectedUniquePath();
     if (path == null) return null;
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
     Object userObject = node.getUserObject();
     if (!(userObject instanceof AbstractTreeNode)) return null;
     AbstractTreeNode descriptor = (AbstractTreeNode) userObject;
     Object element = descriptor.getValue();
     if (element instanceof StructureViewTreeElement) {
       element = ((StructureViewTreeElement) element).getValue();
     }
     if (!(element instanceof PsiElement)) return null;
     if (!((PsiElement) element).isValid()) return null;
     return element;
   }
   if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
     return convertToPsiElementsArray(getSelectedElements());
   }
   if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
     return myFileEditor;
   }
   if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
     return myCopyPasteDelegator.getCutProvider();
   }
   if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
     return myCopyPasteDelegator.getCopyProvider();
   }
   if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
     return myCopyPasteDelegator.getPasteProvider();
   }
   if (PlatformDataKeys.NAVIGATABLE.is(dataId)) {
     Object[] selectedElements = getSelectedTreeElements();
     if (selectedElements == null || selectedElements.length == 0) return null;
     if (selectedElements[0] instanceof Navigatable) {
       return selectedElements[0];
     }
   }
   if (PlatformDataKeys.HELP_ID.is(dataId)) {
     return getHelpID();
   }
   return super.getData(dataId);
 }
Exemplo n.º 3
0
  @Nullable
  private String getPath(DefaultMutableTreeNode node) {
    final Object userObject = node.getUserObject();
    if (userObject instanceof String) {
      String actionId = (String) userObject;

      final TreeNode parent = node.getParent();
      if (parent instanceof DefaultMutableTreeNode) {
        final Object object = ((DefaultMutableTreeNode) parent).getUserObject();
        if (object instanceof Group) {
          return ((Group) object).getActionQualifiedPath(actionId);
        }
      }

      return myMainGroup.getActionQualifiedPath(actionId);
    }
    if (userObject instanceof Group) {
      return ((Group) userObject).getQualifiedPath();
    }
    if (userObject instanceof QuickList) {
      return ((QuickList) userObject).getDisplayName();
    }
    return null;
  }