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.
17 package com
.intellij
.ide
.hierarchy
;
19 import com
.intellij
.history
.LocalHistory
;
20 import com
.intellij
.history
.LocalHistoryAction
;
21 import com
.intellij
.ide
.DeleteProvider
;
22 import com
.intellij
.ide
.IdeBundle
;
23 import com
.intellij
.ide
.util
.DeleteHandler
;
24 import com
.intellij
.openapi
.actionSystem
.*;
25 import com
.intellij
.openapi
.project
.Project
;
26 import com
.intellij
.psi
.PsiElement
;
27 import org
.jetbrains
.annotations
.NotNull
;
29 public abstract class TypeHierarchyBrowserBase
extends HierarchyBrowserBaseEx
{
31 @SuppressWarnings({"UnresolvedPropertyKey"})
32 public static final String TYPE_HIERARCHY_TYPE
= IdeBundle
.message("title.hierarchy.class");
33 @SuppressWarnings({"UnresolvedPropertyKey"})
34 public static final String SUBTYPES_HIERARCHY_TYPE
= IdeBundle
.message("title.hierarchy.subtypes");
35 @SuppressWarnings({"UnresolvedPropertyKey"})
36 public static final String SUPERTYPES_HIERARCHY_TYPE
= IdeBundle
.message("title.hierarchy.supertypes");
38 private boolean myIsInterface
;
40 private final MyDeleteProvider myDeleteElementProvider
= new MyDeleteProvider();
42 public static final DataKey
<TypeHierarchyBrowserBase
> DATA_KEY
= DataKey
.create("com.intellij.ide.hierarchy.TypeHierarchyBrowserBase");
43 @Deprecated public static final String TYPE_HIERARCHY_BROWSER_DATA_KEY
= DATA_KEY
.getName();
45 public TypeHierarchyBrowserBase(final Project project
, final PsiElement element
) {
46 super(project
, element
);
49 protected abstract boolean isInterface(PsiElement psiElement
);
51 protected abstract boolean canBeDeleted(PsiElement psiElement
);
53 protected abstract String
getQualifiedName(PsiElement psiElement
);
55 public boolean isInterface() {
60 protected void setHierarchyBase(PsiElement element
) {
61 super.setHierarchyBase(element
);
62 myIsInterface
= isInterface(element
);
65 protected void prependActions(final DefaultActionGroup actionGroup
) {
66 actionGroup
.add(new ViewClassHierarchyAction());
67 actionGroup
.add(new ViewSupertypesHierarchyAction());
68 actionGroup
.add(new ViewSubtypesHierarchyAction());
69 actionGroup
.add(new AlphaSortAction());
73 protected String
getBrowserDataKey() {
74 return DATA_KEY
.getName();
78 protected String
getActionPlace() {
79 return ActionPlaces
.TYPE_HIERARCHY_VIEW_TOOLBAR
;
82 public final Object
getData(final String dataId
) {
83 if (PlatformDataKeys
.DELETE_ELEMENT_PROVIDER
.is(dataId
)) {
84 return myDeleteElementProvider
;
86 return super.getData(dataId
);
90 protected String
getPrevOccurenceActionNameImpl() {
91 return IdeBundle
.message("hierarchy.type.prev.occurence.name");
95 protected String
getNextOccurenceActionNameImpl() {
96 return IdeBundle
.message("hierarchy.type.next.occurence.name");
99 private final class MyDeleteProvider
implements DeleteProvider
{
100 public final void deleteElement(final DataContext dataContext
) {
101 final PsiElement aClass
= getSelectedElement();
102 if (!canBeDeleted(aClass
)) return;
103 LocalHistoryAction a
= LocalHistory
.startAction(myProject
, IdeBundle
.message("progress.deleting.class", getQualifiedName(aClass
)));
105 final PsiElement
[] elements
= new PsiElement
[]{aClass
};
106 DeleteHandler
.deletePsiElement(elements
, myProject
);
113 public final boolean canDeleteElement(final DataContext dataContext
) {
114 final PsiElement aClass
= getSelectedElement();
115 if (!canBeDeleted(aClass
)) {
118 final PsiElement
[] elements
= new PsiElement
[]{aClass
};
119 return DeleteHandler
.shouldEnableDeleteAction(elements
);
124 protected static class BaseOnThisTypeAction
extends BaseOnThisElementAction
{
126 public BaseOnThisTypeAction() {
127 super("", IdeActions
.ACTION_TYPE_HIERARCHY
, DATA_KEY
.getName());
131 protected String
correctViewType(HierarchyBrowserBaseEx browser
, String viewType
) {
132 if (((TypeHierarchyBrowserBase
)browser
).myIsInterface
&& TYPE_HIERARCHY_TYPE
.equals(viewType
)) return SUBTYPES_HIERARCHY_TYPE
;
137 protected String
getNonDefaultText(@NotNull HierarchyBrowserBaseEx browser
, @NotNull PsiElement element
) {
138 return ((TypeHierarchyBrowserBase
)browser
).isInterface(element
)
139 ? IdeBundle
.message("action.base.on.this.interface")
140 : IdeBundle
.message("action.base.on.this.class");