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); }
private static Object[] convertPathsToValues(TreePath[] selectionPaths) { if (selectionPaths != null) { List<Object> result = new ArrayList<Object>(); for (TreePath selectionPath : selectionPaths) { final Object userObject = ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject(); if (userObject instanceof AbstractTreeNode) { Object value = ((AbstractTreeNode) userObject).getValue(); if (value instanceof StructureViewTreeElement) { value = ((StructureViewTreeElement) value).getValue(); } result.add(value); } } return ArrayUtil.toObjectArray(result); } else { return null; } }