find usages & validation in project structure reworked
[fedora-idea.git] / java / idea-ui / src / com / intellij / openapi / roots / ui / configuration / projectRoot / ModuleConfigurable.java
blobaa645ed865fb50baa711a53a0c5aba0ef837730f
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.
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;
37 import javax.swing.*;
39 /**
40 * User: anna
41 * Date: 04-Jun-2006
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,
50 Module module,
51 final Runnable updateTree) {
52 super(true, updateTree);
53 myModule = module;
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) {
61 name = name.trim();
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
65 try {
66 modifiableModuleModel.renameModule(myModule, name);
68 catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) {
69 //do nothing
71 myConfigurator.moduleRenamed(myModule, myModuleName, name);
72 myModuleName = name;
73 myConfigurator.setModified(!Comparing.strEqual(myModuleName, myModule.getName()));
76 @Override
77 public ProjectStructureElement getProjectStructureElement() {
78 return myProjectStructureElement;
81 public Module getEditableObject() {
82 return myModule;
85 public String getBannerSlogan() {
86 return ProjectBundle.message("project.roots.module.banner.text", myModuleName);
89 public String getDisplayName() {
90 return myModuleName;
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() {
102 return myModule;
105 @Nullable
106 @NonNls
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() {
118 return false;
121 public void apply() throws ConfigurationException {
122 //do nothing
125 public void reset() {
126 //do nothing
129 public void disposeUIResources() {
130 //do nothing
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) {