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
.facet
.Facet
;
19 import com
.intellij
.openapi
.module
.Module
;
20 import com
.intellij
.openapi
.project
.Project
;
21 import com
.intellij
.openapi
.roots
.ModuleRootModel
;
22 import com
.intellij
.openapi
.roots
.OrderEntry
;
23 import com
.intellij
.openapi
.roots
.impl
.ModuleLibraryOrderEntryImpl
;
24 import com
.intellij
.openapi
.roots
.impl
.libraries
.LibraryImpl
;
25 import com
.intellij
.openapi
.roots
.libraries
.Library
;
26 import com
.intellij
.openapi
.roots
.libraries
.LibraryTable
;
27 import com
.intellij
.openapi
.roots
.ui
.configuration
.FacetsProvider
;
28 import com
.intellij
.openapi
.roots
.ui
.configuration
.ModulesProvider
;
29 import com
.intellij
.openapi
.roots
.ui
.configuration
.ProjectStructureConfigurable
;
30 import com
.intellij
.openapi
.roots
.ui
.configuration
.libraryEditor
.ChooseModulesDialog
;
31 import com
.intellij
.openapi
.roots
.ui
.configuration
.packaging
.ChooseLibrariesDialog
;
32 import com
.intellij
.openapi
.roots
.ui
.configuration
.projectRoot
.ModuleStructureConfigurable
;
33 import com
.intellij
.packaging
.artifacts
.Artifact
;
34 import com
.intellij
.packaging
.artifacts
.ArtifactModel
;
35 import com
.intellij
.packaging
.artifacts
.ArtifactType
;
36 import com
.intellij
.packaging
.artifacts
.ModifiableArtifactModel
;
37 import com
.intellij
.packaging
.elements
.CompositePackagingElement
;
38 import com
.intellij
.packaging
.ui
.ArtifactEditor
;
39 import com
.intellij
.packaging
.ui
.ArtifactEditorContext
;
40 import com
.intellij
.packaging
.ui
.ManifestFileConfiguration
;
41 import org
.jetbrains
.annotations
.NotNull
;
43 import java
.util
.Collections
;
44 import java
.util
.List
;
49 public class ArtifactEditorContextImpl
implements ArtifactEditorContext
{
50 private final ArtifactsStructureConfigurableContext myParent
;
51 private final ArtifactEditorEx myEditor
;
52 private ArtifactValidationManagerImpl myValidationManager
;
54 public ArtifactEditorContextImpl(ArtifactsStructureConfigurableContext parent
, ArtifactEditorEx editor
) {
60 public ModifiableArtifactModel
getModifiableArtifactModel() {
61 return myParent
.getModifiableArtifactModel();
65 public ManifestFileConfiguration
getManifestFile(CompositePackagingElement
<?
> element
, ArtifactType artifactType
) {
66 return myParent
.getManifestFile(element
, artifactType
);
70 public Project
getProject() {
71 return myParent
.getProject();
74 public CompositePackagingElement
<?
> getRootElement(@NotNull Artifact artifact
) {
75 return myParent
.getRootElement(artifact
);
78 public void editLayout(@NotNull Artifact artifact
, Runnable runnable
) {
79 myParent
.editLayout(artifact
, runnable
);
82 public ArtifactEditor
getOrCreateEditor(Artifact artifact
) {
83 return myParent
.getOrCreateEditor(artifact
);
86 public void selectArtifact(@NotNull Artifact artifact
) {
87 ProjectStructureConfigurable
.getInstance(getProject()).select(artifact
, true);
90 public void selectFacet(@NotNull Facet
<?
> facet
) {
91 ProjectStructureConfigurable
.getInstance(getProject()).select(facet
, true);
94 public void selectModule(@NotNull Module module
) {
95 ProjectStructureConfigurable
.getInstance(getProject()).select(module
.getName(), null, true);
98 public void selectLibrary(@NotNull Library library
) {
99 final LibraryTable table
= library
.getTable();
101 ProjectStructureConfigurable
.getInstance(getProject()).selectProjectOrGlobalLibrary(library
, true);
104 final Module module
= ((LibraryImpl
)library
).getModule();
105 if (module
!= null) {
106 final ModuleRootModel rootModel
= myParent
.getModulesProvider().getRootModel(module
);
107 final String libraryName
= library
.getName();
108 for (OrderEntry entry
: rootModel
.getOrderEntries()) {
109 if (entry
instanceof ModuleLibraryOrderEntryImpl
) {
110 final ModuleLibraryOrderEntryImpl libraryEntry
= (ModuleLibraryOrderEntryImpl
)entry
;
111 if (libraryName
.equals(libraryEntry
.getLibraryName())) {
112 ModuleStructureConfigurable
.getInstance(getProject()).selectOrderEntry(module
, libraryEntry
);
121 public List
<Artifact
> chooseArtifacts(final List
<?
extends Artifact
> artifacts
, final String title
) {
122 ChooseArtifactsDialog dialog
= new ChooseArtifactsDialog(getProject(), artifacts
, title
, null);
124 return dialog
.isOK() ? dialog
.getChosenElements() : Collections
.<Artifact
>emptyList();
129 public ArtifactModel
getArtifactModel() {
130 return myParent
.getArtifactModel();
134 public ModulesProvider
getModulesProvider() {
135 return myParent
.getModulesProvider();
139 public FacetsProvider
getFacetsProvider() {
140 return myParent
.getFacetsProvider();
143 public void queueValidation() {
144 myEditor
.queueValidation();
148 public ArtifactType
getArtifactType() {
149 return myEditor
.getArtifact().getArtifactType();
152 public ArtifactValidationManagerImpl
getValidationManager() {
153 return myValidationManager
;
156 public void setValidationManager(ArtifactValidationManagerImpl validationManager
) {
157 myValidationManager
= validationManager
;
160 public List
<Module
> chooseModules(final List
<Module
> modules
, final String title
) {
161 ChooseModulesDialog dialog
= new ChooseModulesDialog(getProject(), modules
, title
, null);
163 List
<Module
> selected
= dialog
.getChosenElements();
164 return dialog
.isOK() ? selected
: Collections
.<Module
>emptyList();
167 public List
<Library
> chooseLibraries(final List
<Library
> libraries
, final String title
) {
168 ChooseLibrariesDialog dialog
= new ChooseLibrariesDialog(getProject(), libraries
, title
, null);
170 return dialog
.isOK() ? dialog
.getChosenElements() : Collections
.<Library
>emptyList();