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
;
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
) {
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) {
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() {
50 public void setPackageName(final String packageName
) {
51 myPackageName
= packageName
;
54 public String
getPackageQName() {
55 return myPackageQName
;
58 public PsiElement
getPsiElement() {
62 public int getWeight() {
66 public boolean equals(Object o
) {
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;
81 public int hashCode() {
83 result
= myPackageName
.hashCode();
84 result
= 29 * result
+ (myPackageQName
!= null ? myPackageQName
.hashCode() : 0);
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();
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())) {