update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / ide / structureView / impl / java / SuperTypeGroup.java
blob18dc79f76007f19036790bf9788b0d33bb2d9dd2
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.structureView.impl.java;
18 import com.intellij.ide.IdeBundle;
19 import com.intellij.ide.util.treeView.smartTree.Group;
20 import com.intellij.ide.util.treeView.smartTree.TreeElement;
21 import com.intellij.navigation.ItemPresentation;
22 import com.intellij.openapi.editor.colors.TextAttributesKey;
23 import com.intellij.openapi.util.IconLoader;
24 import com.intellij.psi.PsiClass;
25 import com.intellij.psi.SmartPointerManager;
26 import com.intellij.psi.SmartPsiElementPointer;
27 import com.intellij.psi.PsiModifierList;
28 import com.intellij.psi.util.PsiUtil;
29 import org.jetbrains.annotations.Nullable;
31 import javax.swing.*;
32 import java.util.ArrayList;
33 import java.util.Collection;
35 public class SuperTypeGroup implements Group, ItemPresentation, AccessLevelProvider{
36 private final SmartPsiElementPointer mySuperClassPointer;
37 private final OwnershipType myOverrides;
38 private final Collection<TreeElement> myChildren = new ArrayList<TreeElement>();
39 private static final Icon OVERRIDING_ICON = IconLoader.getIcon("/general/overridingMethod.png");
40 private static final Icon IMPLEMENTING_ICON = IconLoader.getIcon("/general/implementingMethod.png");
41 private static final Icon INHERITED_ICON = IconLoader.getIcon("/general/inheritedMethod.png");
43 public static enum OwnershipType {
44 IMPLEMENTS,
45 OVERRIDES,
46 INHERITS
49 public SuperTypeGroup(PsiClass superClass, OwnershipType type) {
50 myOverrides = type;
51 mySuperClassPointer = SmartPointerManager.getInstance(superClass.getProject()).createSmartPsiElementPointer(superClass);
54 public Collection<TreeElement> getChildren() {
55 return myChildren;
58 @Nullable
59 private PsiClass getSuperClass() {
60 return (PsiClass)mySuperClassPointer.getElement();
63 public ItemPresentation getPresentation() {
64 return this;
67 public Icon getIcon(boolean open) {
68 switch (myOverrides) {
69 case IMPLEMENTS:
70 return IMPLEMENTING_ICON;
71 case INHERITS:
72 return INHERITED_ICON;
73 case OVERRIDES:
74 return OVERRIDING_ICON;
77 return null; // Can't be
80 public String getLocationString() {
81 return null;
84 public String getPresentableText() {
85 return toString();
88 public String toString() {
89 final PsiClass superClass = getSuperClass();
90 return superClass != null ? superClass.getName() : IdeBundle.message("node.structureview.invalid");
93 public boolean equals(Object o) {
94 if (this == o) return true;
95 if (!(o instanceof SuperTypeGroup)) return false;
97 final SuperTypeGroup superTypeGroup = (SuperTypeGroup)o;
99 if (myOverrides != superTypeGroup.myOverrides) return false;
100 final PsiClass superClass = getSuperClass();
101 if (superClass != null ? !superClass .equals(superTypeGroup.getSuperClass() ) : superTypeGroup.getSuperClass() != null) return false;
103 return true;
106 public int hashCode() {
107 final PsiClass superClass = getSuperClass();
108 return superClass != null ? superClass .hashCode() : 0;
111 public Object getValue() {
112 return this;
115 public int getAccessLevel() {
116 final PsiClass superClass = getSuperClass();
117 PsiModifierList modifierList = superClass == null ? null : superClass.getModifierList();
118 return modifierList == null ? PsiUtil.ACCESS_LEVEL_PUBLIC : PsiUtil.getAccessLevel(modifierList);
121 public int getSubLevel() {
122 return 1;
125 public TextAttributesKey getTextAttributesKey() {
126 return null;
129 public void addMethod(final TreeElement superMethod) {
130 myChildren.add(superMethod);