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
.openapi
.roots
.ui
.configuration
.artifacts
;
18 import com
.intellij
.openapi
.module
.Module
;
19 import com
.intellij
.openapi
.roots
.libraries
.Library
;
20 import com
.intellij
.openapi
.roots
.ui
.configuration
.projectRoot
.StructureConfigurableContext
;
21 import com
.intellij
.openapi
.roots
.ui
.configuration
.projectRoot
.daemon
.*;
22 import com
.intellij
.packaging
.artifacts
.Artifact
;
23 import com
.intellij
.packaging
.elements
.PackagingElement
;
24 import com
.intellij
.packaging
.impl
.artifacts
.ArtifactUtil
;
25 import com
.intellij
.packaging
.impl
.artifacts
.PackagingElementPath
;
26 import com
.intellij
.packaging
.impl
.artifacts
.PackagingElementProcessor
;
27 import com
.intellij
.packaging
.impl
.elements
.ArtifactPackagingElement
;
28 import com
.intellij
.packaging
.impl
.elements
.LibraryPackagingElement
;
29 import com
.intellij
.packaging
.impl
.elements
.ModuleOutputPackagingElement
;
30 import org
.jetbrains
.annotations
.NotNull
;
32 import java
.util
.ArrayList
;
33 import java
.util
.List
;
38 public class ArtifactProjectStructureElement
extends ProjectStructureElement
{
39 private final ArtifactsStructureConfigurableContext myArtifactsStructureContext
;
40 private final Artifact myOriginalArtifact
;
42 ArtifactProjectStructureElement(StructureConfigurableContext context
,
43 ArtifactsStructureConfigurableContext artifactsStructureContext
, Artifact artifact
) {
45 myArtifactsStructureContext
= artifactsStructureContext
;
46 myOriginalArtifact
= artifactsStructureContext
.getOriginalArtifact(artifact
);
50 public void check(final ProjectStructureProblemsHolder problemsHolder
) {
51 final ArtifactEditorEx artifactEditor
= (ArtifactEditorEx
)myArtifactsStructureContext
.getOrCreateEditor(myOriginalArtifact
);
52 artifactEditor
.getLayoutTreeComponent().saveElementProperties();
53 final Artifact artifact
= artifactEditor
.getArtifact();
54 artifact
.getArtifactType().checkRootElement(artifactEditor
.getRootElement(), artifact
, new ArtifactProblemsHolderImpl(artifactEditor
.getContext(), problemsHolder
));
57 public Artifact
getOriginalArtifact() {
58 return myOriginalArtifact
;
62 public List
<ProjectStructureElementUsage
> getUsagesInElement() {
63 final Artifact artifact
= myArtifactsStructureContext
.getArtifactModel().getArtifactByOriginal(myOriginalArtifact
);
64 final List
<ProjectStructureElementUsage
> usages
= new ArrayList
<ProjectStructureElementUsage
>();
65 ArtifactUtil
.processPackagingElements(myArtifactsStructureContext
.getRootElement(artifact
), null, new PackagingElementProcessor
<PackagingElement
<?
>>() {
67 public boolean process(@NotNull PackagingElement
<?
> packagingElement
, @NotNull PackagingElementPath path
) {
68 if (packagingElement
instanceof ModuleOutputPackagingElement
) {
69 final Module module
= ((ModuleOutputPackagingElement
)packagingElement
).findModule(myArtifactsStructureContext
);
71 usages
.add(new UsageInArtifact(myOriginalArtifact
, myArtifactsStructureContext
, new ModuleProjectStructureElement(myContext
, module
),
72 ArtifactProjectStructureElement
.this, path
.getPathString(), packagingElement
));
75 else if (packagingElement
instanceof LibraryPackagingElement
) {
76 final Library library
= ((LibraryPackagingElement
)packagingElement
).findLibrary(myArtifactsStructureContext
);
77 if (library
!= null) {
78 usages
.add(new UsageInArtifact(myOriginalArtifact
, myArtifactsStructureContext
, new LibraryProjectStructureElement(myContext
, library
),
79 ArtifactProjectStructureElement
.this, path
.getPathString(), packagingElement
));
82 else if (packagingElement
instanceof ArtifactPackagingElement
) {
83 final Artifact usedArtifact
= ((ArtifactPackagingElement
)packagingElement
).findArtifact(myArtifactsStructureContext
);
84 if (usedArtifact
!= null) {
85 final ArtifactProjectStructureElement artifactElement
= myArtifactsStructureContext
.getOrCreateArtifactElement(usedArtifact
);
86 usages
.add(new UsageInArtifact(myOriginalArtifact
, myArtifactsStructureContext
, artifactElement
,
87 ArtifactProjectStructureElement
.this, path
.getPathString(), packagingElement
));
92 }, myArtifactsStructureContext
, false, artifact
.getArtifactType());
97 public String
toString() {
98 return "artifact:" + myOriginalArtifact
.getName();
102 public boolean equals(Object o
) {
103 if (this == o
) return true;
104 if (!(o
instanceof ArtifactProjectStructureElement
)) return false;
106 return myOriginalArtifact
.equals(((ArtifactProjectStructureElement
)o
).myOriginalArtifact
);
111 public int hashCode() {
112 return myOriginalArtifact
.hashCode();
116 public boolean highlightIfUnused() {