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
.openapi
.roots
.ui
.configuration
.projectRoot
;
19 import com
.intellij
.openapi
.module
.ModifiableModuleModel
;
20 import com
.intellij
.openapi
.module
.Module
;
21 import com
.intellij
.openapi
.module
.ModuleWithNameAlreadyExists
;
22 import com
.intellij
.openapi
.options
.ConfigurationException
;
23 import com
.intellij
.openapi
.project
.ProjectBundle
;
24 import com
.intellij
.openapi
.roots
.ui
.configuration
.ModuleEditor
;
25 import com
.intellij
.openapi
.roots
.ui
.configuration
.ModulesConfigurator
;
26 import com
.intellij
.openapi
.roots
.ui
.configuration
.projectRoot
.daemon
.ModuleProjectStructureElement
;
27 import com
.intellij
.openapi
.roots
.ui
.configuration
.projectRoot
.daemon
.ProjectStructureElement
;
28 import com
.intellij
.openapi
.util
.ActionCallback
;
29 import com
.intellij
.openapi
.util
.Comparing
;
30 import com
.intellij
.openapi
.util
.text
.StringUtil
;
31 import com
.intellij
.ui
.navigation
.History
;
32 import com
.intellij
.ui
.navigation
.Place
;
33 import org
.jetbrains
.annotations
.NonNls
;
34 import org
.jetbrains
.annotations
.NotNull
;
35 import org
.jetbrains
.annotations
.Nullable
;
43 public class ModuleConfigurable
extends ProjectStructureElementConfigurable
<Module
> implements Place
.Navigator
{
44 private final Module myModule
;
45 private final ModulesConfigurator myConfigurator
;
46 private String myModuleName
;
47 private final ModuleProjectStructureElement myProjectStructureElement
;
49 public ModuleConfigurable(ModulesConfigurator modulesConfigurator
,
51 final Runnable updateTree
) {
52 super(true, updateTree
);
54 myModuleName
= myModule
.getName();
55 myConfigurator
= modulesConfigurator
;
56 final StructureConfigurableContext context
= ModuleStructureConfigurable
.getInstance(myModule
.getProject()).getContext();
57 myProjectStructureElement
= new ModuleProjectStructureElement(context
, myModule
);
60 public void setDisplayName(String name
) {
62 final ModifiableModuleModel modifiableModuleModel
= myConfigurator
.getModuleModel();
63 if (StringUtil
.isEmpty(name
)) return; //empty string comes on double click on module node
64 if (Comparing
.strEqual(name
, myModuleName
)) return; //nothing changed
66 modifiableModuleModel
.renameModule(myModule
, name
);
68 catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists
) {
71 myConfigurator
.moduleRenamed(myModule
, myModuleName
, name
);
73 myConfigurator
.setModified(!Comparing
.strEqual(myModuleName
, myModule
.getName()));
77 public ProjectStructureElement
getProjectStructureElement() {
78 return myProjectStructureElement
;
81 public Module
getEditableObject() {
85 public String
getBannerSlogan() {
86 return ProjectBundle
.message("project.roots.module.banner.text", myModuleName
);
89 public String
getDisplayName() {
93 public Icon
getIcon() {
94 return myModule
.getModuleType().getNodeIcon(false);
97 public Icon
getIcon(final boolean open
) {
98 return myModule
.getModuleType().getNodeIcon(open
);
101 public Module
getModule() {
107 public String
getHelpTopic() {
108 final ModuleEditor moduleEditor
= getModuleEditor();
109 return moduleEditor
!= null ? moduleEditor
.getHelpTopic() : null;
113 public JComponent
createOptionsPanel() {
114 return getModuleEditor().getPanel();
117 public boolean isModified() {
121 public void apply() throws ConfigurationException
{
125 public void reset() {
129 public void disposeUIResources() {
133 ModuleEditor
getModuleEditor() {
134 return myConfigurator
.getModuleEditor(myModule
);
137 public ActionCallback
navigateTo(@Nullable final Place place
, final boolean requestFocus
) {
138 return getModuleEditor().navigateTo(place
, requestFocus
);
141 public void queryPlace(@NotNull final Place place
) {
142 final ModuleEditor editor
= getModuleEditor();
143 if (editor
!= null) {
144 editor
.queryPlace(place
);
148 public void setHistory(final History history
) {