update copyright
[fedora-idea.git] / java / idea-ui / src / com / intellij / openapi / roots / ui / configuration / UIRootConfigurationAccessor.java
blob66a9150e7d04ab2569c4bb9fabd16489d6a9595a
1 /*
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;
18 import com.intellij.openapi.module.Module;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.projectRoots.Sdk;
21 import com.intellij.openapi.roots.ProjectRootManager;
22 import com.intellij.openapi.roots.impl.RootConfigurationAccessor;
23 import com.intellij.openapi.roots.libraries.Library;
24 import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
25 import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectJdksModel;
26 import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
27 import org.jetbrains.annotations.Nullable;
29 /**
30 * @author yole
32 public class UIRootConfigurationAccessor extends RootConfigurationAccessor {
33 private final Project myProject;
35 public UIRootConfigurationAccessor(final Project project) {
36 myProject = project;
39 @Nullable
40 public Library getLibrary(Library library, final String libraryName, final String libraryLevel) {
41 final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(myProject).getContext();
42 if (library == null) {
43 if (libraryName != null) {
44 library = context.getLibrary(libraryName, libraryLevel);
46 } else {
47 library = context.getLibrary(library.getName(), library.getTable().getTableLevel());
49 return library;
52 @Nullable
53 public Sdk getSdk(final Sdk sdk, final String sdkName) {
54 final ProjectJdksModel model = ProjectStructureConfigurable.getInstance(myProject).getJdkConfig().getJdksTreeModel();
55 return sdkName != null ? model.findSdk(sdkName) : sdk;
58 public Module getModule(final Module module, final String moduleName) {
59 if (module == null) {
60 return ModuleStructureConfigurable.getInstance(myProject).getModule(moduleName);
62 return module;
65 public Sdk getProjectSdk(final Project project) {
66 return ProjectJdksModel.getInstance(project).getProjectJdk();
69 public String getProjectSdkName(final Project project) {
70 final String projectJdkName = ProjectRootManager.getInstance(project).getProjectJdkName();
71 final Sdk projectJdk = getProjectSdk(project);
72 if (projectJdk != null) {
73 return projectJdk.getName();
75 else {
76 return ProjectJdksModel.getInstance(project).findSdk(projectJdkName) == null ? projectJdkName : null;