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
.project
.Project
;
19 import com
.intellij
.openapi
.roots
.ui
.configuration
.FacetsProvider
;
20 import com
.intellij
.openapi
.roots
.ui
.configuration
.ModulesProvider
;
21 import com
.intellij
.openapi
.roots
.ui
.configuration
.projectRoot
.StructureConfigurableContext
;
22 import com
.intellij
.openapi
.util
.Disposer
;
23 import com
.intellij
.packaging
.artifacts
.*;
24 import com
.intellij
.packaging
.elements
.CompositePackagingElement
;
25 import com
.intellij
.packaging
.impl
.artifacts
.ArtifactModelImpl
;
26 import com
.intellij
.packaging
.impl
.artifacts
.ArtifactUtil
;
27 import com
.intellij
.packaging
.ui
.ManifestFileConfiguration
;
28 import org
.jetbrains
.annotations
.NotNull
;
29 import org
.jetbrains
.annotations
.Nullable
;
31 import java
.util
.HashMap
;
37 class ArtifactsStructureConfigurableContextImpl
implements ArtifactsStructureConfigurableContext
{
38 private ModifiableArtifactModel myModifiableModel
;
39 private final ManifestFilesInfo myManifestFilesInfo
= new ManifestFilesInfo();
40 private ArtifactAdapter myModifiableModelListener
;
41 private StructureConfigurableContext myContext
;
42 private Project myProject
;
43 private Map
<Artifact
, CompositePackagingElement
<?
>> myModifiableRoots
= new HashMap
<Artifact
, CompositePackagingElement
<?
>>();
44 private Map
<Artifact
, ArtifactEditorImpl
> myArtifactEditors
= new HashMap
<Artifact
, ArtifactEditorImpl
>();
46 public ArtifactsStructureConfigurableContextImpl(StructureConfigurableContext context
, Project project
, final ArtifactAdapter modifiableModelListener
) {
47 myModifiableModelListener
= modifiableModelListener
;
53 public Project
getProject() {
58 public ArtifactModel
getArtifactModel() {
59 if (myModifiableModel
!= null) {
60 return myModifiableModel
;
62 return ArtifactManager
.getInstance(myProject
);
66 public Artifact
getOriginalArtifact(@NotNull Artifact artifact
) {
67 if (myModifiableModel
!= null) {
68 return ((ArtifactModelImpl
)myModifiableModel
).getOriginalArtifact(artifact
);
73 public CompositePackagingElement
<?
> getRootElement(@NotNull Artifact artifact
) {
74 artifact
= getOriginalArtifact(artifact
);
75 if (myModifiableModel
!= null) {
76 final CompositePackagingElement
<?
> rootElement
= myModifiableModel
.getArtifactByOriginal(artifact
).getRootElement();
77 if (rootElement
!= artifact
.getRootElement()) {
78 myModifiableRoots
.put(artifact
, rootElement
);
81 CompositePackagingElement
<?
> root
= myModifiableRoots
.get(artifact
);
83 root
= ArtifactUtil
.copyFromRoot(artifact
.getRootElement(), myProject
);
84 myModifiableRoots
.put(artifact
, root
);
89 public void editLayout(@NotNull Artifact artifact
, Runnable action
) {
90 artifact
= getOriginalArtifact(artifact
);
91 final ModifiableArtifact modifiableArtifact
= getModifiableArtifactModel().getOrCreateModifiableArtifact(artifact
);
92 if (modifiableArtifact
.getRootElement() == artifact
.getRootElement()) {
93 modifiableArtifact
.setRootElement(getRootElement(artifact
));
96 myContext
.getDaemonAnalyzer().queueUpdate(new ArtifactProjectStructureElement(myContext
, this, artifact
));
99 public ArtifactEditorImpl
getOrCreateEditor(Artifact artifact
) {
100 artifact
= getOriginalArtifact(artifact
);
101 ArtifactEditorImpl artifactEditor
= myArtifactEditors
.get(artifact
);
102 if (artifactEditor
== null) {
103 artifactEditor
= new ArtifactEditorImpl(this, artifact
);
104 myArtifactEditors
.put(artifact
, artifactEditor
);
106 return artifactEditor
;
110 public ModifiableArtifactModel
getActualModifiableModel() {
111 return myModifiableModel
;
115 public ModifiableArtifactModel
getModifiableArtifactModel() {
116 if (myModifiableModel
== null) {
117 myModifiableModel
= ArtifactManager
.getInstance(myProject
).createModifiableModel();
118 ((ArtifactModelImpl
)myModifiableModel
).addListener(myModifiableModelListener
);
120 return myModifiableModel
;
124 public ModulesProvider
getModulesProvider() {
125 return myContext
.getModulesConfigurator();
129 public FacetsProvider
getFacetsProvider() {
130 return myContext
.getModulesConfigurator().getFacetsConfigurator();
134 public ManifestFileConfiguration
getManifestFile(CompositePackagingElement
<?
> element
, ArtifactType artifactType
) {
135 return myManifestFilesInfo
.getManifestFile(element
, artifactType
, this);
138 public ManifestFilesInfo
getManifestFilesInfo() {
139 return myManifestFilesInfo
;
142 public void resetModifiableModel() {
143 disposeUIResources();
144 myModifiableModel
= null;
145 myModifiableRoots
.clear();
146 myManifestFilesInfo
.clear();
149 public void disposeUIResources() {
150 for (ArtifactEditorImpl editor
: myArtifactEditors
.values()) {
151 Disposer
.dispose(editor
);
153 myArtifactEditors
.clear();