Hierarchy providers refactored
[fedora-idea.git] / lang-impl / src / com / intellij / ide / hierarchy / MethodHierarchyBrowserBase.java
blob57c4e0953a3969f060950ce02c2b64d22a8cf9a0
1 package com.intellij.ide.hierarchy;
3 import com.intellij.ide.IdeBundle;
4 import com.intellij.openapi.actionSystem.*;
5 import com.intellij.openapi.application.ApplicationManager;
6 import com.intellij.openapi.project.Project;
7 import com.intellij.openapi.ui.MultiLineLabelUI;
8 import com.intellij.openapi.util.IconLoader;
9 import com.intellij.psi.PsiElement;
10 import org.jetbrains.annotations.NonNls;
11 import org.jetbrains.annotations.NotNull;
13 import javax.swing.*;
14 import java.awt.*;
16 public abstract class MethodHierarchyBrowserBase extends HierarchyBrowserBaseEx {
17 @NonNls public static final String METHOD_HIERARCHY_BROWSER_DATA_KEY = "com.intellij.ide.hierarchy.MethodHierarchyBrowserBase";
19 public MethodHierarchyBrowserBase(final Project project, final PsiElement method) {
20 super(project, method);
23 @NotNull
24 protected String getPrevOccurenceActionNameImpl() {
25 return IdeBundle.message("hierarchy.method.prev.occurence.name");
28 @NotNull
29 protected String getNextOccurenceActionNameImpl() {
30 return IdeBundle.message("hierarchy.method.next.occurence.name");
33 protected static JPanel createStandardLegendPanel(final String methodDefinedText,
34 final String methodNotDefinedLegallyText,
35 final String methodShouldBeDefined) {
36 final JPanel panel = new JPanel(new GridBagLayout());
38 JLabel label;
39 final GridBagConstraints gc =
40 new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 0, 5), 0, 0);
42 label = new JLabel(methodDefinedText, IconLoader.getIcon("/hierarchy/methodDefined.png"), SwingConstants.LEFT);
43 label.setUI(new MultiLineLabelUI());
44 label.setIconTextGap(10);
45 panel.add(label, gc);
47 gc.gridy++;
48 label = new JLabel(methodNotDefinedLegallyText, IconLoader.getIcon("/hierarchy/methodNotDefined.png"), SwingConstants.LEFT);
49 label.setUI(new MultiLineLabelUI());
50 label.setIconTextGap(10);
51 panel.add(label, gc);
53 gc.gridy++;
54 label = new JLabel(methodShouldBeDefined, IconLoader.getIcon("/hierarchy/shouldDefineMethod.png"), SwingConstants.LEFT);
55 label.setUI(new MultiLineLabelUI());
56 label.setIconTextGap(10);
57 panel.add(label, gc);
59 return panel;
62 @Override
63 protected void appendActions(@NotNull DefaultActionGroup actionGroup, String helpID) {
64 actionGroup.add(new AlphaSortAction());
65 actionGroup.add(new ShowImplementationsOnlyAction());
66 super.appendActions(actionGroup, helpID);
69 @NotNull
70 protected String getBrowserDataKey() {
71 return METHOD_HIERARCHY_BROWSER_DATA_KEY;
74 @NotNull
75 protected String getActionPlace() {
76 return ActionPlaces.METHOD_HIERARCHY_VIEW_TOOLBAR;
79 final class ShowImplementationsOnlyAction extends ToggleAction {
80 public ShowImplementationsOnlyAction() {
81 super(IdeBundle.message("action.hide.non.implementations"), null,
82 IconLoader.getIcon("/ant/filter.png")); // TODO[anton] use own icon!!!
85 public final boolean isSelected(final AnActionEvent event) {
86 return HierarchyBrowserManager.getInstance(myProject).getState().HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED;
89 public final void setSelected(final AnActionEvent event, final boolean flag) {
90 HierarchyBrowserManager.getInstance(myProject).getState().HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED = flag;
92 // invokeLater is called to update state of button before long tree building operation
93 ApplicationManager.getApplication().invokeLater(new Runnable() {
94 public void run() {
95 doRefresh(true);
97 });
100 public final void update(final AnActionEvent event) {
101 super.update(event);
102 final Presentation presentation = event.getPresentation();
103 presentation.setEnabled(isValidBase());
107 public static class BaseOnThisMethodAction extends BaseOnThisElementAction {
108 public BaseOnThisMethodAction() {
109 super(IdeBundle.message("action.base.on.this.method"), IdeActions.ACTION_METHOD_HIERARCHY, METHOD_HIERARCHY_BROWSER_DATA_KEY);