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.
17 package com
.intellij
.facet
.impl
.ui
;
19 import com
.intellij
.facet
.Facet
;
20 import com
.intellij
.facet
.impl
.DefaultFacetsProvider
;
21 import com
.intellij
.facet
.ui
.FacetEditorContext
;
22 import com
.intellij
.openapi
.module
.Module
;
23 import com
.intellij
.openapi
.roots
.ModifiableRootModel
;
24 import com
.intellij
.openapi
.roots
.ModuleRootModel
;
25 import com
.intellij
.openapi
.roots
.OrderRootType
;
26 import com
.intellij
.openapi
.roots
.libraries
.Library
;
27 import com
.intellij
.openapi
.roots
.libraries
.LibraryTablesRegistrar
;
28 import com
.intellij
.openapi
.roots
.ui
.configuration
.FacetsProvider
;
29 import com
.intellij
.openapi
.roots
.ui
.configuration
.ModulesProvider
;
30 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.ArtifactsStructureConfigurableContext
;
31 import com
.intellij
.openapi
.roots
.ui
.configuration
.projectRoot
.LibrariesContainer
;
32 import com
.intellij
.openapi
.util
.Key
;
33 import com
.intellij
.openapi
.util
.UserDataHolder
;
34 import com
.intellij
.openapi
.util
.UserDataHolderBase
;
35 import com
.intellij
.openapi
.vfs
.VirtualFile
;
36 import com
.intellij
.util
.EventDispatcher
;
37 import org
.jetbrains
.annotations
.NotNull
;
38 import org
.jetbrains
.annotations
.Nullable
;
43 public abstract class FacetEditorContextBase
extends UserDataHolderBase
implements FacetEditorContext
{
44 private final FacetsProvider myFacetsProvider
;
45 @Nullable private final FacetEditorContext myParentContext
;
46 private final ModulesProvider myModulesProvider
;
47 private final Facet myFacet
;
48 private final UserDataHolder mySharedModuleData
;
49 private final EventDispatcher
<FacetContextChangeListener
> myFacetContextChangeDispatcher
= EventDispatcher
.create(FacetContextChangeListener
.class);
50 private final UserDataHolder mySharedProjectData
;
52 public FacetEditorContextBase(@NotNull Facet facet
, final @Nullable FacetEditorContext parentContext
, final @Nullable FacetsProvider facetsProvider
,
53 final @NotNull ModulesProvider modulesProvider
,
54 final UserDataHolder sharedModuleData
,
55 final UserDataHolder sharedProjectData
) {
57 mySharedProjectData
= sharedProjectData
;
58 mySharedModuleData
= sharedModuleData
;
59 myParentContext
= parentContext
;
60 myModulesProvider
= modulesProvider
;
61 myFacetsProvider
= facetsProvider
!= null ? facetsProvider
: DefaultFacetsProvider
.INSTANCE
;
64 public Library
[] getLibraries() {
65 return LibraryTablesRegistrar
.getInstance().getLibraryTable(getProject()).getLibraries();
69 public String
getFacetName() {
70 return myFacet
.getName();
73 public VirtualFile
[] getLibraryFiles(final Library library
, final OrderRootType rootType
) {
74 return library
.getFiles(rootType
);
78 public Library
findLibrary(@NotNull String name
) {
79 for (Library library
: getLibraries()) {
80 if (name
.equals(library
.getName())) {
88 public UserDataHolder
getSharedProjectData() {
89 return mySharedProjectData
;
92 //todo[nik] pull up to open API?
93 public UserDataHolder
getSharedModuleData() {
94 return mySharedModuleData
;
98 public abstract ArtifactsStructureConfigurableContext
getArtifactsStructureContext();
101 public <T
> T
getUserData(final Key
<T
> key
) {
102 T t
= super.getUserData(key
);
103 if (t
== null && myParentContext
!= null) {
104 t
= myParentContext
.getUserData(key
);
110 public FacetsProvider
getFacetsProvider() {
111 return myFacetsProvider
;
115 public ModulesProvider
getModulesProvider() {
116 return myModulesProvider
;
120 public ModuleRootModel
getRootModel() {
121 return getModifiableRootModel();
124 public void addFacetContextChangeListener(FacetContextChangeListener facetContextChangeListener
) {
125 myFacetContextChangeDispatcher
.addListener(facetContextChangeListener
);
128 public void fireModuleRootsChanged(final ModifiableRootModel moduleRootModel
) {
129 myFacetContextChangeDispatcher
.getMulticaster().moduleRootsChanged(moduleRootModel
);
132 public void fireFacetModelChanged(final Module module
) {
133 myFacetContextChangeDispatcher
.getMulticaster().facetModelChanged(module
);
136 public abstract LibrariesContainer
getContainer();
139 public Facet
getFacet() {
144 public Facet
getParentFacet() {
145 return myFacet
.getUnderlyingFacet();