1 package com
.intellij
.packaging
.impl
.elements
;
3 import com
.intellij
.openapi
.compiler
.CompilerBundle
;
4 import com
.intellij
.openapi
.project
.Project
;
5 import com
.intellij
.packaging
.artifacts
.Artifact
;
6 import com
.intellij
.packaging
.artifacts
.ArtifactManager
;
7 import com
.intellij
.packaging
.artifacts
.ArtifactPointerManager
;
8 import com
.intellij
.packaging
.elements
.CompositePackagingElement
;
9 import com
.intellij
.packaging
.elements
.PackagingElementType
;
10 import com
.intellij
.packaging
.impl
.artifacts
.ArtifactUtil
;
11 import com
.intellij
.packaging
.impl
.artifacts
.PlainArtifactType
;
12 import com
.intellij
.packaging
.ui
.ArtifactEditorContext
;
13 import com
.intellij
.util
.Processor
;
14 import org
.jetbrains
.annotations
.NotNull
;
22 public class ArtifactElementType
extends PackagingElementType
<ArtifactPackagingElement
> {
23 public static final ArtifactElementType ARTIFACT_ELEMENT_TYPE
= new ArtifactElementType();
25 ArtifactElementType() {
26 super("artifact", CompilerBundle
.message("element.type.name.artifact"));
30 public Icon
getCreateElementIcon() {
31 return PlainArtifactType
.ARTIFACT_ICON
;
35 public boolean canCreate(@NotNull ArtifactEditorContext context
, @NotNull Artifact artifact
) {
36 return !getAvailableArtifacts(context
, artifact
).isEmpty();
40 public List
<?
extends ArtifactPackagingElement
> chooseAndCreate(@NotNull ArtifactEditorContext context
, @NotNull Artifact artifact
,
41 @NotNull CompositePackagingElement
<?
> parent
) {
42 final Project project
= context
.getProject();
43 List
<Artifact
> artifacts
= context
.chooseArtifacts(getAvailableArtifacts(context
, artifact
), CompilerBundle
.message("dialog.title.choose.artifacts"));
44 final List
<ArtifactPackagingElement
> elements
= new ArrayList
<ArtifactPackagingElement
>();
45 for (Artifact selected
: artifacts
) {
46 elements
.add(new ArtifactPackagingElement(project
, ArtifactPointerManager
.getInstance(project
).create(selected
.getName())));
52 public static List
<?
extends Artifact
> getAvailableArtifacts(@NotNull final ArtifactEditorContext context
, @NotNull final Artifact artifact
) {
53 final Set
<Artifact
> result
= new HashSet
<Artifact
>(Arrays
.asList(context
.getArtifactModel().getArtifacts()));
54 ArtifactUtil
.processPackagingElements(artifact
, ARTIFACT_ELEMENT_TYPE
, new Processor
<ArtifactPackagingElement
>() {
55 public boolean process(ArtifactPackagingElement artifactPackagingElement
) {
56 result
.remove(artifactPackagingElement
.findArtifact(context
));
60 result
.remove(artifact
);
61 final Iterator
<Artifact
> iterator
= result
.iterator();
62 while (iterator
.hasNext()) {
63 Artifact another
= iterator
.next();
64 final boolean notContainThis
=
65 ArtifactUtil
.processPackagingElements(another
, ARTIFACT_ELEMENT_TYPE
, new Processor
<ArtifactPackagingElement
>() {
66 public boolean process(ArtifactPackagingElement element
) {
67 return !artifact
.getName().equals(element
.getArtifactName());
70 if (!notContainThis
) {
74 final ArrayList
<Artifact
> list
= new ArrayList
<Artifact
>(result
);
75 Collections
.sort(list
, ArtifactManager
.ARTIFACT_COMPARATOR
);
80 public ArtifactPackagingElement
createEmpty(@NotNull Project project
) {
81 return new ArtifactPackagingElement(project
);