blob: 56dae56a2a6ed2bced1679a5c43ce296203ede5a [file] [log] [blame]
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.hierarchy.method;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.hierarchy.*;
import com.intellij.ide.util.treeView.NodeDescriptor;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.ui.PopupHandler;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.Comparator;
import java.util.Map;
public class MethodHierarchyBrowser extends MethodHierarchyBrowserBase {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.hierarchy.method.MethodHierarchyBrowser");
public MethodHierarchyBrowser(final Project project, final PsiMethod method) {
super(project, method);
}
protected void createTrees(@NotNull Map<String, JTree> trees) {
final JTree tree = createTree(false);
ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
final BaseOnThisMethodAction baseOnThisMethodAction = new BaseOnThisMethodAction();
baseOnThisMethodAction
.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_METHOD_HIERARCHY).getShortcutSet(), tree);
trees.put(METHOD_TYPE, tree);
}
protected JPanel createLegendPanel() {
return createStandardLegendPanel(IdeBundle.message("hierarchy.legend.method.is.defined.in.class"),
IdeBundle.message("hierarchy.legend.method.defined.in.superclass"),
IdeBundle.message("hierarchy.legend.method.should.be.defined"));
}
protected PsiElement getElementFromDescriptor(@NotNull final HierarchyNodeDescriptor descriptor) {
if (descriptor instanceof MethodHierarchyNodeDescriptor) {
return ((MethodHierarchyNodeDescriptor)descriptor).getTargetElement();
}
return null;
}
protected boolean isApplicableElement(@NotNull final PsiElement psiElement) {
return psiElement instanceof PsiMethod;
}
protected HierarchyTreeStructure createHierarchyTreeStructure(@NotNull final String typeName, @NotNull final PsiElement psiElement) {
if (!METHOD_TYPE.equals(typeName)) {
LOG.error("unexpected type: " + typeName);
return null;
}
return new MethodHierarchyTreeStructure(myProject, (PsiMethod)psiElement);
}
protected Comparator<NodeDescriptor> getComparator() {
return JavaHierarchyUtil.getComparator(myProject);
}
public PsiMethod getBaseMethod() {
final HierarchyTreeBuilder builder = myBuilders.get(myCurrentViewType);
final MethodHierarchyTreeStructure treeStructure = (MethodHierarchyTreeStructure)builder.getTreeStructure();
return treeStructure.getBaseMethod();
}
public static final class BaseOnThisMethodAction extends MethodHierarchyBrowserBase.BaseOnThisMethodAction {
}
}