update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / ide / hierarchy / method / MethodHierarchyBrowser.java
blob7e562c0760af8e9f508de75bd8ff3dcc5fd1da7d
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.ide.hierarchy.method;
18 import com.intellij.ide.IdeBundle;
19 import com.intellij.ide.hierarchy.*;
20 import com.intellij.ide.util.treeView.NodeDescriptor;
21 import com.intellij.openapi.actionSystem.ActionGroup;
22 import com.intellij.openapi.actionSystem.ActionManager;
23 import com.intellij.openapi.actionSystem.ActionPlaces;
24 import com.intellij.openapi.actionSystem.IdeActions;
25 import com.intellij.openapi.diagnostic.Logger;
26 import com.intellij.openapi.project.Project;
27 import com.intellij.psi.PsiElement;
28 import com.intellij.psi.PsiMethod;
29 import com.intellij.ui.PopupHandler;
30 import org.jetbrains.annotations.NotNull;
32 import javax.swing.*;
33 import java.util.Comparator;
34 import java.util.Map;
36 public final class MethodHierarchyBrowser extends MethodHierarchyBrowserBase {
37 private static final Logger LOG = Logger.getInstance("#com.intellij.ide.hierarchy.method.MethodHierarchyBrowser");
39 public MethodHierarchyBrowser(final Project project, final PsiMethod method) {
40 super(project, method);
43 protected void createTrees(@NotNull Map<String, JTree> trees) {
44 final JTree tree = createTree(false);
45 ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
46 PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
48 final BaseOnThisMethodAction baseOnThisMethodAction = new BaseOnThisMethodAction();
49 baseOnThisMethodAction
50 .registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_METHOD_HIERARCHY).getShortcutSet(), tree);
52 trees.put(METHOD_TYPE, tree);
55 protected JPanel createLegendPanel() {
56 return createStandardLegendPanel(IdeBundle.message("hierarchy.legend.method.is.defined.in.class"),
57 IdeBundle.message("hierarchy.legend.method.defined.in.superclass"),
58 IdeBundle.message("hierarchy.legend.method.should.be.defined"));
62 protected PsiElement getElementFromDescriptor(@NotNull final HierarchyNodeDescriptor descriptor) {
63 if (descriptor instanceof MethodHierarchyNodeDescriptor) {
64 return ((MethodHierarchyNodeDescriptor)descriptor).getTargetElement();
66 return null;
69 protected boolean isApplicableElement(@NotNull final PsiElement psiElement) {
70 return psiElement instanceof PsiMethod;
73 protected HierarchyTreeStructure createHierarchyTreeStructure(@NotNull final String typeName, @NotNull final PsiElement psiElement) {
74 if (!METHOD_TYPE.equals(typeName)) {
75 LOG.error("unexpected type: " + typeName);
76 return null;
78 return new MethodHierarchyTreeStructure(myProject, (PsiMethod)psiElement);
81 protected Comparator<NodeDescriptor> getComparator() {
82 return JavaHierarchyUtil.getComparator(myProject);
85 public PsiMethod getBaseMethod() {
86 final HierarchyTreeBuilder builder = myBuilders.get(myCurrentViewType);
87 final MethodHierarchyTreeStructure treeStructure = (MethodHierarchyTreeStructure)builder.getTreeStructure();
88 return treeStructure.getBaseMethod();
91 public static final class BaseOnThisMethodAction extends MethodHierarchyBrowserBase.BaseOnThisMethodAction {