made all fields final. Could not resist, sorry
[fedora-idea.git] / source / com / intellij / packageDependencies / ui / PackageNode.java
blobc0dc9589d4d6e23d081bd8ca43843277916a245b
1 package com.intellij.packageDependencies.ui;
3 import com.intellij.cyclicDependencies.ui.CyclicDependenciesPanel;
4 import com.intellij.openapi.util.Comparing;
5 import com.intellij.psi.PsiElement;
6 import com.intellij.psi.PsiFile;
7 import com.intellij.psi.PsiJavaFile;
8 import com.intellij.psi.PsiPackage;
9 import com.intellij.util.Icons;
11 import javax.swing.*;
12 import java.util.Map;
13 import java.util.Set;
15 public class PackageNode extends PackageDependenciesNode {
17 private String myPackageName;
18 private final String myPackageQName;
19 private final PsiPackage myPackage;
22 public PackageNode(PsiPackage aPackage, boolean showFQName) {
23 myPackage = aPackage;
24 myPackageName = showFQName ? aPackage.getQualifiedName() : aPackage.getName();
25 if (myPackageName == null || myPackageName.length() == 0) {
26 myPackageName = CyclicDependenciesPanel.DEFAULT_PACKAGE_ABBREVIATION;
28 String packageQName = aPackage.getQualifiedName();
29 if (packageQName.length() == 0) {
30 packageQName = null;
32 myPackageQName = packageQName;
35 public void fillFiles(Set<PsiFile> set, boolean recursively) {
36 super.fillFiles(set, recursively);
37 int count = getChildCount();
38 for (int i = 0; i < count; i++) {
39 PackageDependenciesNode child = (PackageDependenciesNode)getChildAt(i);
40 if (child instanceof FileNode || recursively) {
41 child.fillFiles(set, true);
46 public String toString() {
47 return myPackageName;
50 public void setPackageName(final String packageName) {
51 myPackageName = packageName;
54 public String getPackageQName() {
55 return myPackageQName;
58 public PsiElement getPsiElement() {
59 return myPackage;
62 public int getWeight() {
63 return 3;
66 public boolean equals(Object o) {
67 if (isEquals()){
68 return super.equals(o);
70 if (this == o) return true;
71 if (!(o instanceof PackageNode)) return false;
73 final PackageNode packageNode = (PackageNode)o;
75 if (!myPackageName.equals(packageNode.myPackageName)) return false;
76 if (myPackageQName != null ? !myPackageQName.equals(packageNode.myPackageQName) : packageNode.myPackageQName != null) return false;
78 return true;
81 public int hashCode() {
82 int result;
83 result = myPackageName.hashCode();
84 result = 29 * result + (myPackageQName != null ? myPackageQName.hashCode() : 0);
85 return result;
88 public Icon getOpenIcon() {
89 return Icons.PACKAGE_OPEN_ICON;
92 public Icon getClosedIcon() {
93 return Icons.PACKAGE_ICON;
97 public boolean isValid() {
98 return myPackage != null && myPackage.isValid();
101 @Override
102 public boolean canSelectInLeftTree(final Map<PsiFile, Set<PsiFile>> deps) {
103 Set<PsiFile> files = deps.keySet();
104 String packageName = myPackage.getQualifiedName();
105 for (PsiFile file : files) {
106 if (file instanceof PsiJavaFile && Comparing.equal(packageName, ((PsiJavaFile)file).getPackageName())) {
107 return true;
110 return false;