do not reset on project structure configuration apply

This commit is contained in:
Alexey Pegov
2009-10-19 20:01:53 +04:00
parent 3ae3867c05
commit 346a1f3a4f
28 changed files with 639 additions and 230 deletions
@@ -60,9 +60,19 @@ public class ProjectFacetsConfigurator implements FacetsProvider, ModuleEditor.C
private final Project myProject;
private UserDataHolderBase myProjectData = new UserDataHolderBase();
public ProjectFacetsConfigurator(final StructureConfigurableContext context, Project project) {
public ProjectFacetsConfigurator(final StructureConfigurableContext context, Project project, ProjectFacetsConfigurator facetsConfigurator) {
myContext = context;
myProject = project;
if (facetsConfigurator != null) {
initFrom(facetsConfigurator);
}
}
private void initFrom(ProjectFacetsConfigurator facetsConfigurator) {
myFacet2Info.putAll(facetsConfigurator.myFacet2Info);
myInfo2Facet.putAll(facetsConfigurator.myInfo2Facet);
myTreeModels.putAll(facetsConfigurator.myTreeModels);
}
public List<Facet> removeFacet(Facet facet) {
@@ -1,54 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.module.impl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.util.UserDataHolderBase;
public class ModuleConfigurationStateImpl extends UserDataHolderBase implements ModuleConfigurationState {
private final ModulesProvider myProvider;
private final ModifiableRootModel myRootModel;
private final Project myProject;
private final FacetsProvider myFacetsProvider;
public ModuleConfigurationStateImpl(Project project, ModulesProvider provider, ModifiableRootModel rootModel,
final FacetsProvider facetsProvider) {
myFacetsProvider = facetsProvider;
myProvider = provider;
myRootModel = rootModel;
myProject = project;
}
public ModulesProvider getModulesProvider() {
return myProvider;
}
public FacetsProvider getFacetsProvider() {
return myFacetsProvider;
}
public ModifiableRootModel getRootModel() {
return myRootModel;
}
public Project getProject() {
return myProject;
}
}
@@ -17,9 +17,7 @@ package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.AnnotationOrderRootType;
import com.intellij.openapi.roots.ui.util.CellAppearance;
import com.intellij.openapi.roots.ui.util.CellAppearanceUtils;
@@ -31,9 +29,9 @@ import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.ui.ColoredTableCellRenderer;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TableUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.ItemRemovable;
import com.intellij.util.ui.Table;
import com.intellij.util.ArrayUtil;
import javax.swing.*;
import javax.swing.border.Border;
@@ -58,8 +56,8 @@ public class AnnotationsEditor extends ModuleElementsEditor {
public static final String NAME = ProjectBundle.message("project.roots.external.annotations.tab.title");
public static final Icon ICON = IconLoader.getIcon("/modules/annotation.png");
public AnnotationsEditor(Project project, ModifiableRootModel model) {
super(project, model);
public AnnotationsEditor(final ModuleConfigurationState state) {
super(state);
}
public String getHelpTopic() {
@@ -82,7 +80,7 @@ public class AnnotationsEditor extends ModuleElementsEditor {
final TableItem item = ((MyTableModel)myTable.getModel()).getTableItemAt(row);
urls[row] = item.getUrl();
}
myModel.setRootUrls(AnnotationOrderRootType.getInstance(), urls);
getModel().setRootUrls(AnnotationOrderRootType.getInstance(), urls);
}
public JComponent createComponentImpl() {
@@ -143,7 +141,7 @@ public class AnnotationsEditor extends ModuleElementsEditor {
protected DefaultTableModel createModel() {
final MyTableModel tableModel = new MyTableModel();
final String[] urls = myModel.getRootUrls(AnnotationOrderRootType.getInstance());
final String[] urls = getModel().getRootUrls(AnnotationOrderRootType.getInstance());
for (String javadocUrl : urls) {
tableModel.addTableItem(new TableItem(javadocUrl));
}
@@ -24,10 +24,8 @@ package com.intellij.openapi.roots.ui.configuration;
import com.intellij.ide.util.BrowseFilesListener;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
@@ -57,11 +55,9 @@ public class BuildElementsEditor extends ModuleElementsEditor {
private JCheckBox myCbExcludeOutput;
private JLabel myOutputLabel;
private JLabel myTestOutputLabel;
public CompilerModuleExtension myCompilerExtension;
protected BuildElementsEditor(final Project project, final ModifiableRootModel model) {
super(project, model);
myCompilerExtension = myModel.getModuleExtension(CompilerModuleExtension.class);
protected BuildElementsEditor(final ModuleConfigurationState state) {
super(state);
}
public JComponent createComponentImpl() {
@@ -82,21 +78,21 @@ public class BuildElementsEditor extends ModuleElementsEditor {
myOutputPathPanel = createOutputPathPanel(ProjectBundle.message("module.paths.output.title"), new CommitPathRunnable() {
public void saveUrl(String url) {
if (myCompilerExtension.isCompilerOutputPathInherited()) return; //do not override settings if any
myCompilerExtension.setCompilerOutputPath(url);
if (getCompilerExtension().isCompilerOutputPathInherited()) return; //do not override settings if any
getCompilerExtension().setCompilerOutputPath(url);
}
});
myTestsOutputPathPanel = createOutputPathPanel(ProjectBundle.message("module.paths.test.output.title"), new CommitPathRunnable() {
public void saveUrl(String url) {
if (myCompilerExtension.isCompilerOutputPathInherited()) return; //do not override settings if any
myCompilerExtension.setCompilerOutputPathForTests(url);
if (getCompilerExtension().isCompilerOutputPathInherited()) return; //do not override settings if any
getCompilerExtension().setCompilerOutputPathForTests(url);
}
});
myCbExcludeOutput = new JCheckBox(ProjectBundle.message("module.paths.exclude.output.checkbox"), myCompilerExtension.isExcludeOutput());
myCbExcludeOutput = new JCheckBox(ProjectBundle.message("module.paths.exclude.output.checkbox"), getCompilerExtension().isExcludeOutput());
myCbExcludeOutput.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
myCompilerExtension.setExcludeOutput(myCbExcludeOutput.isSelected());
getCompilerExtension().setExcludeOutput(myCbExcludeOutput.isSelected());
}
});
@@ -130,7 +126,7 @@ public class BuildElementsEditor extends ModuleElementsEditor {
updateOutputPathPresentation();
//compiler settings
final boolean outputPathInherited = myCompilerExtension.isCompilerOutputPathInherited();
final boolean outputPathInherited = getCompilerExtension().isCompilerOutputPathInherited();
myInheritCompilerOutput.setSelected(outputPathInherited);
myPerModuleCompilerOutput.setSelected(!outputPathInherited);
enableCompilerSettings(!outputPathInherited);
@@ -142,26 +138,26 @@ public class BuildElementsEditor extends ModuleElementsEditor {
}
private void updateOutputPathPresentation() {
if (myCompilerExtension.isCompilerOutputPathInherited()) {
if (getCompilerExtension().isCompilerOutputPathInherited()) {
final String baseUrl = ProjectStructureConfigurable.getInstance(myProject).getProjectConfig().getCompilerOutputUrl();
moduleCompileOutputChanged(baseUrl, myModel.getModule().getName());
moduleCompileOutputChanged(baseUrl, getModel().getModule().getName());
} else {
final VirtualFile compilerOutputPath = myCompilerExtension.getCompilerOutputPath();
final VirtualFile compilerOutputPath = getCompilerExtension().getCompilerOutputPath();
if (compilerOutputPath != null) {
myOutputPathPanel.setText(FileUtil.toSystemDependentName(compilerOutputPath.getPath()));
}
else {
final String compilerOutputUrl = myCompilerExtension.getCompilerOutputUrl();
final String compilerOutputUrl = getCompilerExtension().getCompilerOutputUrl();
if (compilerOutputUrl != null) {
myOutputPathPanel.setText(FileUtil.toSystemDependentName(VfsUtil.urlToPath(compilerOutputUrl)));
}
}
final VirtualFile testsOutputPath = myCompilerExtension.getCompilerOutputPathForTests();
final VirtualFile testsOutputPath = getCompilerExtension().getCompilerOutputPathForTests();
if (testsOutputPath != null) {
myTestsOutputPathPanel.setText(FileUtil.toSystemDependentName(testsOutputPath.getPath()));
}
else {
final String testsOutputUrl = myCompilerExtension.getCompilerOutputUrlForTests();
final String testsOutputUrl = getCompilerExtension().getCompilerOutputUrlForTests();
if (testsOutputUrl != null) {
myTestsOutputPathPanel.setText(FileUtil.toSystemDependentName(VfsUtil.urlToPath(testsOutputUrl)));
}
@@ -175,7 +171,7 @@ public class BuildElementsEditor extends ModuleElementsEditor {
UIUtil.setEnabled(myTestsOutputPathPanel, enabled, true);
UIUtil.setEnabled(myTestOutputLabel, enabled, true);
myCbExcludeOutput.setEnabled(enabled);
myCompilerExtension.inheritCompilerOutputPath(!enabled);
getCompilerExtension().inheritCompilerOutputPath(!enabled);
updateOutputPathPresentation();
}
@@ -187,7 +183,7 @@ public class BuildElementsEditor extends ModuleElementsEditor {
final Runnable commitRunnable = new Runnable() {
public void run() {
if (!myModel.isWritable()) {
if (!getModel().isWritable()) {
return;
}
final String path = textField.getText().trim();
@@ -225,7 +221,7 @@ public class BuildElementsEditor extends ModuleElementsEditor {
public void saveData() {
myOutputPathPanel.commit();
myTestsOutputPathPanel.commit();
myCompilerExtension.commit();
getCompilerExtension().commit();
}
public String getDisplayName() {
@@ -245,11 +241,11 @@ public class BuildElementsEditor extends ModuleElementsEditor {
public void moduleStateChanged() {
//if content enties tree was changed
myCbExcludeOutput.setSelected(myCompilerExtension.isExcludeOutput());
myCbExcludeOutput.setSelected(getCompilerExtension().isExcludeOutput());
}
public void moduleCompileOutputChanged(final String baseUrl, final String moduleName) {
if (myCompilerExtension.isCompilerOutputPathInherited()) {
if (getCompilerExtension().isCompilerOutputPathInherited()) {
if (baseUrl != null) {
myOutputPathPanel.setText(FileUtil.toSystemDependentName(VfsUtil.urlToPath(baseUrl + "/" + CompilerModuleExtension
.PRODUCTION + "/" + moduleName)));
@@ -263,6 +259,10 @@ public class BuildElementsEditor extends ModuleElementsEditor {
}
}
public CompilerModuleExtension getCompilerExtension() {
return getModel().getModuleExtension(CompilerModuleExtension.class);
}
private static interface CommitPathRunnable {
void saveUrl(String url);
}
@@ -15,11 +15,12 @@
*/
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.ProjectTopics;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.storage.ClasspathStorage;
import com.intellij.openapi.roots.impl.storage.ClasspathStorageProvider;
import com.intellij.openapi.util.IconLoader;
@@ -37,18 +38,23 @@ import java.util.Map;
* Date: Oct 4, 2003
* Time: 6:54:57 PM
*/
public class ClasspathEditor extends ModuleElementsEditor {
public class ClasspathEditor extends ModuleElementsEditor implements ModuleRootListener {
public static final String NAME = ProjectBundle.message("modules.classpath.title");
public static final Icon ICON = IconLoader.getIcon("/modules/classpath.png");
private ClasspathPanel myPanel;
private final ModulesProvider myModulesProvider;
private ClasspathFormatPanel myClasspathFormatPanel;
public ClasspathEditor(Project project, ModifiableRootModel model, final ModulesProvider modulesProvider) {
super(project, model);
myModulesProvider = modulesProvider;
public ClasspathEditor(final ModuleConfigurationState state) {
super(state);
final Disposable disposable = new Disposable() {
public void dispose() {}
};
state.getProject().getMessageBus().connect(disposable).subscribe(ProjectTopics.PROJECT_ROOTS, this);
registerDisposable(disposable);
}
public boolean isModified() {
@@ -83,12 +89,12 @@ public class ClasspathEditor extends ModuleElementsEditor {
super.canApply();
if (myClasspathFormatPanel != null) {
final String storageID = myClasspathFormatPanel.getSelectedClasspathFormat();
ClasspathStorage.getProvider(storageID).assertCompatible(myModel);
ClasspathStorage.getProvider(storageID).assertCompatible(getModel());
}
}
public JComponent createComponentImpl() {
myPanel = new ClasspathPanel(myProject, myModel, myModulesProvider);
myPanel = new ClasspathPanel(getState());
myPanel.addListener(new OrderPanelListener() {
public void entryMoved() {
@@ -101,7 +107,12 @@ public class ClasspathEditor extends ModuleElementsEditor {
panel.add(myPanel, BorderLayout.CENTER);
final ModuleJdkConfigurable jdkConfigurable =
new ModuleJdkConfigurable(this, myModel, ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel());
new ModuleJdkConfigurable(this, ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel()) {
@Override
protected ModifiableRootModel getRootModel() {
return getState().getRootModel();
}
};
panel.add(jdkConfigurable.createComponent(), BorderLayout.NORTH);
jdkConfigurable.reset();
registerDisposable(jdkConfigurable);
@@ -117,7 +128,7 @@ public class ClasspathEditor extends ModuleElementsEditor {
public void flushChangesToModel() {
List<OrderEntry> entries = myPanel.getEntries();
myModel.rearrangeOrderEntries(entries.toArray(new OrderEntry[entries.size()]));
getModel().rearrangeOrderEntries(entries.toArray(new OrderEntry[entries.size()]));
}
public void selectOrderEntry(@NotNull final OrderEntry entry) {
@@ -130,6 +141,37 @@ public class ClasspathEditor extends ModuleElementsEditor {
}
}
public void beforeRootsChange(ModuleRootEvent event) {
}
public void rootsChanged(ModuleRootEvent event) {
myPanel.rootsChanged();
}
public Sdk setSdk(final Sdk newJDK) {
final ModifiableRootModel model = getModel();
final Sdk oldSdk = model.getSdk();
//final List<OrderEntry> entries = myPanel.getEntries();
//for (OrderEntry entry : entries) {
// if (entry instanceof JdkOrderEntry) {
//
// }
//}
if (newJDK != null) {
model.setSdk(newJDK);
}
else {
model.inheritSdk();
}
myPanel.forceInitFromModel();
flushChangesToModel();
return oldSdk;
}
private class ClasspathFormatPanel extends JPanel {
private final JComboBox cbClasspathFormat;
@@ -168,7 +210,7 @@ public class ClasspathEditor extends ModuleElementsEditor {
@NotNull
private String getModuleClasspathFormat() {
return ClasspathStorage.getStorageType(myModel.getModule());
return ClasspathStorage.getStorageType(getModel().getModule());
}
boolean isModified () {
@@ -177,8 +219,8 @@ public class ClasspathEditor extends ModuleElementsEditor {
void apply () throws ConfigurationException {
final String storageID = getSelectedClasspathFormat();
ClasspathStorage.getProvider(storageID).assertCompatible(myModel);
ClasspathStorage.setStorageType(myModel, storageID);
ClasspathStorage.getProvider(storageID).assertCompatible(getModel());
ClasspathStorage.setStorageType(getModel(), storageID);
}
}
}
@@ -77,22 +77,19 @@ import java.util.List;
public class ClasspathPanel extends JPanel {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.ClasspathPanel");
private final Project myProject;
private final ModifiableRootModel myRootModel;
private final ModulesProvider myModulesProvider;
private final Table myEntryTable;
private final MyTableModel myModel;
private final EventDispatcher<OrderPanelListener> myListeners = EventDispatcher.create(OrderPanelListener.class);
private PopupAction[] myPopupActions = null;
private Icon[] myIcons = null;
private JButton myEditButton;
private ModuleConfigurationState myState;
protected ClasspathPanel(Project project, ModifiableRootModel rootModel, final ModulesProvider modulesProvider) {
protected ClasspathPanel(ModuleConfigurationState state) {
super(new BorderLayout());
myProject = project;
myRootModel = rootModel;
myModulesProvider = modulesProvider;
myModel = new MyTableModel(rootModel);
myState = state;
myModel = new MyTableModel(state);
myEntryTable = new Table(myModel);
myEntryTable.setShowGrid(false);
myEntryTable.setDragEnabled(false);
@@ -216,7 +213,7 @@ public class ClasspathPanel extends JPanel {
private void navigate(boolean openLibraryEditor) {
final int selectedRow = myEntryTable.getSelectedRow();
final OrderEntry entry = myModel.getItemAt(selectedRow).getEntry();
final ProjectStructureConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject);
final ProjectStructureConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myState.getProject());
if (entry instanceof ModuleOrderEntry){
Module module = ((ModuleOrderEntry)entry).getModule();
if (module != null) {
@@ -334,7 +331,8 @@ public class ClasspathPanel extends JPanel {
if (orderEntry == null) {
continue;
}
myRootModel.removeOrderEntry(orderEntry);
ModuleStructureConfigurable.getInstance(myState.getProject()).getContext().clearCaches(orderEntry);
getRootModel().removeOrderEntry(orderEntry);
}
final int[] selectedRows = myEntryTable.getSelectedRows();
myModel.fireTableDataChanged();
@@ -362,7 +360,7 @@ public class ClasspathPanel extends JPanel {
final LibraryTableModifiableModelProvider provider;
final LibraryTable table = library.getTable();
if (table == null) {
final LibraryTable moduleLibraryTable = myRootModel.getModuleLibraryTable();
final LibraryTable moduleLibraryTable = getRootModel().getModuleLibraryTable();
provider = new LibraryTableModifiableModelProvider() {
public LibraryTable.ModifiableModel getModifiableModel() {
return moduleLibraryTable.getModifiableModel();
@@ -382,13 +380,13 @@ public class ClasspathPanel extends JPanel {
};
}
else {
provider = ProjectStructureConfigurable.getInstance(myProject).getContext().createModifiableModelProvider(table.getTableLevel(), false);
provider = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext().createModifiableModelProvider(table.getTableLevel(), false);
}
final LibraryTableEditor editor = LibraryTableEditor.editLibrary(provider, library);
editor.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, myRootModel.getModule());
editor.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, getRootModel().getModule());
editor.openDialog(ClasspathPanel.this, Collections.singletonList(library), true);
myEntryTable.repaint();
ModuleStructureConfigurable.getInstance(myProject).getTree().repaint();
ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
}
});
return panel;
@@ -408,6 +406,14 @@ public class ClasspathPanel extends JPanel {
);
}
private ModifiableRootModel getRootModel() {
return myState.getRootModel();
}
public void rootsChanged() {
forceInitFromModel();
}
private abstract class ButtonAction implements ActionListener {
public final void actionPerformed(ActionEvent e) {
execute();
@@ -478,7 +484,7 @@ public class ClasspathPanel extends JPanel {
if (chosen.size() == 0) {
return;
}
final ModuleStructureConfigurable rootConfigurable = ModuleStructureConfigurable.getInstance(myProject);
final ModuleStructureConfigurable rootConfigurable = ModuleStructureConfigurable.getInstance(myState.getProject());
//int insertionIndex = myEntryTable.getSelectedRow();
for (ItemType item : chosen) {
//myModel.addItemAt(createTableItem(item), insertionIndex++);
@@ -511,12 +517,12 @@ public class ClasspathPanel extends JPanel {
private void initPopupActions() {
if (myPopupActions == null) {
final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(myProject).getContext();
final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext();
int actionIndex = 1;
final List<PopupAction> actions = new ArrayList<PopupAction>(Arrays.<PopupAction>asList(
new ChooseAndAddAction<Library>(actionIndex++, ProjectBundle.message("classpath.add.simple.module.library.action"), Icons.JAR_ICON) {
protected TableItem createTableItem(final Library item) {
final OrderEntry[] entries = myRootModel.getOrderEntries();
final OrderEntry[] entries = getRootModel().getOrderEntries();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
@@ -530,12 +536,12 @@ public class ClasspathPanel extends JPanel {
}
protected ChooserDialog<Library> createChooserDialog() {
return new ChooseModuleLibrariesDialog(ClasspathPanel.this, myRootModel.getModuleLibraryTable(), null);
return new ChooseModuleLibrariesDialog(ClasspathPanel.this, getRootModel().getModuleLibraryTable(), null);
}
},
new ChooseAndAddAction<Library>(actionIndex++, ProjectBundle.message("classpath.add.module.library.action"), Icons.JAR_ICON) {
protected TableItem createTableItem(final Library item) {
final OrderEntry[] entries = myRootModel.getOrderEntries();
final OrderEntry[] entries = getRootModel().getOrderEntries();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
@@ -549,7 +555,7 @@ public class ClasspathPanel extends JPanel {
}
protected ChooserDialog<Library> createChooserDialog() {
return new CreateModuleLibraryDialog(ClasspathPanel.this, myRootModel.getModuleLibraryTable());
return new CreateModuleLibraryDialog(ClasspathPanel.this, getRootModel().getModuleLibraryTable());
}
},
new ChooseNamedLibraryAction(actionIndex++, ProjectBundle.message("classpath.add.project.library.action"), context.getProjectLibrariesProvider(true)),
@@ -562,7 +568,7 @@ public class ClasspathPanel extends JPanel {
actions.add(new ChooseAndAddAction<Module>(actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"),
StdModuleTypes.JAVA.getNodeIcon(false)) {
protected TableItem createTableItem(final Module item) {
return new ModuleItem(myRootModel.addModuleOrderEntry(item));
return new ModuleItem(getRootModel().addModuleOrderEntry(item));
}
protected ChooserDialog<Module> createChooserDialog() {
final List<Module> chooseItems = getDependencyModules();
@@ -632,7 +638,7 @@ public class ClasspathPanel extends JPanel {
TableUtil.scrollSelectionToVisible(myEntryTable);
}
}
IdeFocusManager.getInstance(myProject).requestFocus(myEntryTable, true);
IdeFocusManager.getInstance(myState.getProject()).requestFocus(myEntryTable, true);
}
private int moveRow(final int row, final int increment) {
@@ -665,7 +671,7 @@ public class ClasspathPanel extends JPanel {
}
}
private void forceInitFromModel() {
void forceInitFromModel() {
final int[] selection = myEntryTable.getSelectedRows();
myModel.clear();
myModel.init();
@@ -682,10 +688,11 @@ public class ClasspathPanel extends JPanel {
filtered.add(((ModuleOrderEntry)entry).getModuleName());
}
}
final Module self = myModulesProvider.getModule(myRootModel.getModule().getName());
final ModulesProvider modulesProvider = myState.getModulesProvider();
final Module self = modulesProvider.getModule(getRootModel().getModule().getName());
filtered.add(self.getName());
final Module[] modules = myModulesProvider.getModules();
final Module[] modules = modulesProvider.getModules();
final List<Module> elements = new ArrayList<Module>(modules.length);
for (final Module module : modules) {
if (!filtered.contains(module.getName())) {
@@ -800,15 +807,19 @@ public class ClasspathPanel extends JPanel {
public static final int ITEM_COLUMN = 1;
public static final int SCOPE_COLUMN = 2;
private final List<TableItem> myItems = new ArrayList<TableItem>();
private final ModifiableRootModel myRootModel;
private ModuleConfigurationState myState;
public MyTableModel(final ModifiableRootModel rootModel) {
myRootModel = rootModel;
public MyTableModel(final ModuleConfigurationState state) {
myState = state;
init();
}
private ModifiableRootModel getModel() {
return myState.getRootModel();
}
public void init() {
final OrderEntry[] orderEntries = myRootModel.getOrderEntries();
final OrderEntry[] orderEntries = getModel().getOrderEntries();
boolean hasJdkOrderEntry = false;
for (final OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof JdkOrderEntry) {
@@ -1108,7 +1119,7 @@ public class ClasspathPanel extends JPanel {
@Nullable
protected TableItem createTableItem(final Library item) {
// clear invalid order entry corresponding to added library if any
final OrderEntry[] orderEntries = myRootModel.getOrderEntries();
final OrderEntry[] orderEntries = getRootModel().getOrderEntries();
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry ) {
if (item.getName().equals(((LibraryOrderEntry)orderEntry).getLibraryName())) {
@@ -1117,12 +1128,12 @@ public class ClasspathPanel extends JPanel {
ProjectBundle.message("classpath.title.adding.dependency"));
return null;
} else {
myRootModel.removeOrderEntry(orderEntry);
getRootModel().removeOrderEntry(orderEntry);
}
}
}
}
return new LibItem(myRootModel.addLibraryEntry(item));
return new LibItem(getRootModel().addLibraryEntry(item));
}
protected ChooserDialog<Library> createChooserDialog() {
@@ -1130,7 +1141,7 @@ public class ClasspathPanel extends JPanel {
}
private Collection<Library> getAlreadyAddedLibraries() {
final OrderEntry[] orderEntries = myRootModel.getOrderEntries();
final OrderEntry[] orderEntries = getRootModel().getOrderEntries();
final Set<Library> result = new HashSet<Library>(orderEntries.length);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
@@ -1148,14 +1159,14 @@ public class ClasspathPanel extends JPanel {
private boolean myIsOk;
MyChooserDialog(){
myEditor = LibraryTableEditor.editLibraryTable(myLibraryTableModelProvider, myProject);
myEditor = LibraryTableEditor.editLibraryTable(myLibraryTableModelProvider, myState.getProject());
Disposer.register(this, myEditor);
}
public List<Library> getChosenElements() {
final List<Library> chosen = new ArrayList<Library>(Arrays.asList(myEditor.getSelectedLibraries()));
chosen.removeAll(getAlreadyAddedLibraries());
final Module module = myRootModel.getModule();
final Module module = getRootModel().getModule();
final Project project = module.getProject();
return chosen;
}
@@ -1176,7 +1187,7 @@ public class ClasspathPanel extends JPanel {
private class MyFindUsagesAction extends FindUsagesInProjectStructureActionBase {
private MyFindUsagesAction() {
super(myEntryTable, myProject);
super(myEntryTable, myState.getProject());
}
protected boolean isEnabled() {
@@ -16,8 +16,7 @@
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
import javax.swing.*;
import java.awt.*;
@@ -30,8 +29,8 @@ import java.awt.*;
public class ContentEntriesEditor extends JavaContentEntriesEditor {
private LanguageLevelConfigurable myLanguageLevelConfigurable;
public ContentEntriesEditor(Project project, String moduleName, ModifiableRootModel model, ModulesProvider modulesProvider) {
super(project, moduleName, model, modulesProvider);
public ContentEntriesEditor(String moduleName, final ModuleConfigurationState state) {
super(moduleName, state);
}
public void disposeUIResources() {
@@ -44,7 +43,12 @@ public class ContentEntriesEditor extends JavaContentEntriesEditor {
}
protected void addAdditionalSettingsToPanel(final JPanel mainPanel) {
myLanguageLevelConfigurable = new LanguageLevelConfigurable(myModel);
myLanguageLevelConfigurable = new LanguageLevelConfigurable() {
@Override
public LanguageLevelModuleExtension getLanguageLevelExtension() {
return getModel().getModuleExtension(LanguageLevelModuleExtension.class);
}
};
mainPanel.add(myLanguageLevelConfigurable.createComponent(), BorderLayout.NORTH);
myLanguageLevelConfigurable.reset();
}
@@ -28,23 +28,23 @@ public class DefaultModuleConfigurationEditorFactoryImpl extends DefaultModuleCo
final ModifiableRootModel rootModel = state.getRootModel();
final Module module = rootModel.getModule();
final String moduleName = module.getName();
return new ContentEntriesEditor(state.getProject(), moduleName, rootModel, state.getModulesProvider());
return new ContentEntriesEditor(moduleName, state);
}
public ModuleConfigurationEditor createClasspathEditor(ModuleConfigurationState state) {
return new ClasspathEditor(state.getProject(), state.getRootModel(), state.getModulesProvider());
return new ClasspathEditor(state);
}
public ModuleConfigurationEditor createJavadocEditor(ModuleConfigurationState state) {
return new JavadocEditor(state.getProject(), state.getRootModel());
return new JavadocEditor(state);
}
public ModuleConfigurationEditor createOutputEditor(ModuleConfigurationState state) {
return new OutputEditor(state.getProject(), state.getRootModel());
return new OutputEditor(state);
}
@Deprecated
public ModuleConfigurationEditor createCompilerOutputEditor(ModuleConfigurationState state) {
return new BuildElementsEditor(state.getProject(), state.getRootModel());
return new BuildElementsEditor(state);
}
}
@@ -18,7 +18,6 @@ package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleComponent;
import com.intellij.openapi.module.ModuleConfigurationEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import org.jetbrains.annotations.NotNull;
@@ -41,12 +40,10 @@ public class DefaultModuleEditorsProvider implements ModuleComponent, ModuleConf
ModifiableRootModel rootModel = state.getRootModel();
Module module = rootModel.getModule();
String moduleName = module.getName();
ModulesProvider provider = state.getModulesProvider();
Project project = state.getProject();
List<ModuleConfigurationEditor> editors = new ArrayList<ModuleConfigurationEditor>();
editors.add(new ContentEntriesEditor(project, moduleName, rootModel, provider));
editors.add(new OutputEditor(project, rootModel));
editors.add(new ClasspathEditor(project, rootModel, provider));
editors.add(new ContentEntriesEditor(moduleName, state));
editors.add(new OutputEditor(state));
editors.add(new ClasspathEditor(state));
return editors.toArray(new ModuleConfigurationEditor[editors.size()]);
}
}
@@ -25,7 +25,6 @@ import com.intellij.openapi.progress.util.SmoothProgressAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
@@ -40,12 +39,12 @@ import java.util.List;
import java.util.Map;
public class JavaContentEntriesEditor extends CommonContentEntriesEditor {
public JavaContentEntriesEditor(Project project, String moduleName, ModifiableRootModel model, ModulesProvider modulesProvider) {
super(project, moduleName, model, modulesProvider);
public JavaContentEntriesEditor(String moduleName, ModuleConfigurationState state) {
super(moduleName, state);
}
protected ContentEntryEditor createContentEntryEditor(ContentEntry contentEntry) {
return new JavaContentEntryEditor(contentEntry, myModel);
return new JavaContentEntryEditor(contentEntry, getModel());
}
protected ContentEntryTreeEditor createContentEntryTreeEditor(Project project) {
@@ -17,11 +17,9 @@ package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.ui.Util;
import com.intellij.openapi.roots.JavadocOrderRootType;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.util.CellAppearance;
import com.intellij.openapi.roots.ui.util.CellAppearanceUtils;
import com.intellij.openapi.roots.ui.util.SimpleTextCellAppearance;
@@ -32,9 +30,9 @@ import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.ui.ColoredTableCellRenderer;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TableUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.ItemRemovable;
import com.intellij.util.ui.Table;
import com.intellij.util.ArrayUtil;
import javax.swing.*;
import javax.swing.border.Border;
@@ -60,8 +58,8 @@ public class JavadocEditor extends ModuleElementsEditor {
public static final String NAME = ProjectBundle.message("module.javadoc.title");
public static final Icon ICON = IconLoader.getIcon("/modules/javadoc.png");
public JavadocEditor(Project project, ModifiableRootModel model) {
super(project, model);
public JavadocEditor(ModuleConfigurationState state) {
super(state);
}
public String getHelpTopic() {
@@ -84,7 +82,7 @@ public class JavadocEditor extends ModuleElementsEditor {
final TableItem item = ((MyTableModel)myTable.getModel()).getTableItemAt(row);
urls[row] = item.getUrl();
}
myModel.setRootUrls(JavadocOrderRootType.getInstance(), urls);
getModel().setRootUrls(JavadocOrderRootType.getInstance(), urls);
}
public JComponent createComponentImpl() {
@@ -148,7 +146,7 @@ public class JavadocEditor extends ModuleElementsEditor {
protected DefaultTableModel createModel() {
final MyTableModel tableModel = new MyTableModel();
final String[] javadocUrls = myModel.getRootUrls(JavadocOrderRootType.getInstance());
final String[] javadocUrls = getModel().getRootUrls(JavadocOrderRootType.getInstance());
for (String javadocUrl : javadocUrls) {
tableModel.addTableItem(new TableItem(javadocUrl));
}
@@ -20,7 +20,6 @@ import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.pom.java.LanguageLevel;
import javax.swing.*;
@@ -32,18 +31,16 @@ import java.awt.event.ActionListener;
* User: anna
* Date: 06-Jun-2006
*/
public class LanguageLevelConfigurable implements UnnamedConfigurable {
public abstract class LanguageLevelConfigurable implements UnnamedConfigurable {
private LanguageLevelCombo myLanguageLevelCombo;
private JPanel myPanel = new JPanel(new GridBagLayout());
public LanguageLevelModuleExtension myLanguageLevelExtension;
public LanguageLevelConfigurable(ModifiableRootModel rootModule) {
myLanguageLevelExtension = rootModule.getModuleExtension(LanguageLevelModuleExtension.class);
public LanguageLevelConfigurable() {
myLanguageLevelCombo = new LanguageLevelCombo();
myLanguageLevelCombo.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
final Object languageLevel = myLanguageLevelCombo.getSelectedItem();
myLanguageLevelExtension.setLanguageLevel(languageLevel instanceof LanguageLevel ? (LanguageLevel)languageLevel : null);
getLanguageLevelExtension().setLanguageLevel(languageLevel instanceof LanguageLevel ? (LanguageLevel)languageLevel : null);
}
});
myLanguageLevelCombo.insertItemAt(LanguageLevelCombo.USE_PROJECT_LANGUAGE_LEVEL, 0);
@@ -56,20 +53,21 @@ public class LanguageLevelConfigurable implements UnnamedConfigurable {
}
public boolean isModified() {
return myLanguageLevelExtension.isChanged();
return getLanguageLevelExtension().isChanged();
}
public void apply() throws ConfigurationException {
myLanguageLevelExtension.commit();
getLanguageLevelExtension().commit();
}
public void reset() {
myLanguageLevelCombo.setSelectedItem(myLanguageLevelExtension.getLanguageLevel());
myLanguageLevelCombo.setSelectedItem(getLanguageLevelExtension().getLanguageLevel());
}
public void disposeUIResources() {
myPanel = null;
myLanguageLevelCombo = null;
myLanguageLevelExtension = null;
}
public abstract LanguageLevelModuleExtension getLanguageLevelExtension();
}
@@ -32,7 +32,6 @@ import com.intellij.openapi.roots.impl.ModuleRootManagerImpl;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.TabbedPaneWrapper;
import com.intellij.ui.navigation.History;
import com.intellij.ui.navigation.Place;
@@ -56,7 +55,7 @@ import java.util.List;
* Time: 6:29:56 PM
*/
@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod"})
public class ModuleEditor implements Place.Navigator {
public abstract class ModuleEditor implements Place.Navigator, Disposable {
private final Project myProject;
private JPanel myGenericSettingsPanel;
@@ -77,18 +76,10 @@ public class ModuleEditor implements Place.Navigator {
private History myHistory;
private final ProjectFacetsConfigurator myFacetsConfigurator;
private final Disposable myDisposable = new Disposable() {
public void dispose() {
}
};
public ModuleEditor(Project project, ModulesProvider modulesProvider, ProjectFacetsConfigurator facetsConfigurator,
public ModuleEditor(Project project, ModulesProvider modulesProvider,
@NotNull Module module) {
myProject = project;
myModulesProvider = modulesProvider;
myFacetsConfigurator = facetsConfigurator;
addChangeListener(facetsConfigurator);
myModule = module;
myName = module.getName();
}
@@ -105,6 +96,7 @@ public class ModuleEditor implements Place.Navigator {
setSelectedTabName(selectedTab);
}
public abstract ProjectFacetsConfigurator getFacetsConfigurator();
public interface ChangeListener extends EventListener {
void moduleStateChanged(ModifiableRootModel moduleRootModel);
@@ -185,8 +177,17 @@ public class ModuleEditor implements Place.Navigator {
}
public ModuleConfigurationState createModuleConfigurationState() {
return new ModuleConfigurationStateImpl(myProject, myModulesProvider, getModifiableRootModelProxy(),
myFacetsConfigurator);
return new ModuleConfigurationStateImpl(myProject, myModulesProvider) {
@Override
public ModifiableRootModel getRootModel() {
return getModifiableRootModel();
}
@Override
public FacetsProvider getFacetsProvider() {
return getFacetsConfigurator();
}
};
}
private void processEditorsProvider(final ModuleConfigurationEditorProvider provider, final ModuleConfigurationState state) {
@@ -206,7 +207,7 @@ public class ModuleEditor implements Place.Navigator {
myGenericSettingsPanel.add(northPanel, BorderLayout.NORTH);
myTabbedPane = new TabbedPaneWrapper(myDisposable);
myTabbedPane = new TabbedPaneWrapper(this);
for (ModuleConfigurationEditor editor : myEditors) {
myTabbedPane.addTab(editor.getDisplayName(), editor.getIcon(), editor.createComponent(), null);
@@ -283,9 +284,8 @@ public class ModuleEditor implements Place.Navigator {
}
}
public ModifiableRootModel dispose() {
public void dispose() {
try {
Disposer.dispose(myDisposable);
for (final ModuleConfigurationEditor myEditor : myEditors) {
myEditor.disposeUIResources();
}
@@ -297,10 +297,11 @@ public class ModuleEditor implements Place.Navigator {
myTabbedPane = null;
}
if (myModifiableRootModel != null) {
myModifiableRootModel.dispose();
}
myGenericSettingsPanel = null;
return myModifiableRootModel;
}
finally {
myModifiableRootModel = null;
@@ -308,19 +309,25 @@ public class ModuleEditor implements Place.Navigator {
}
}
public ModifiableRootModel applyAndDispose() throws ConfigurationException {
for (ModuleConfigurationEditor editor : myEditors) {
if (editor instanceof ModuleElementsEditor) {
((ModuleElementsEditor)editor).canApply();
public ModifiableRootModel apply() throws ConfigurationException {
try {
for (ModuleConfigurationEditor editor : myEditors) {
if (editor instanceof ModuleElementsEditor) {
((ModuleElementsEditor)editor).canApply();
}
}
}
for (ModuleConfigurationEditor editor : myEditors) {
editor.saveData();
editor.apply();
}
for (ModuleConfigurationEditor editor : myEditors) {
editor.saveData();
editor.apply();
}
return dispose();
return myModifiableRootModel;
}
finally {
myModifiableRootModel = null;
myModifiableRootModelProxy = null;
}
}
public String getName() {
@@ -42,10 +42,9 @@ import java.awt.event.ActionListener;
* User: anna
* Date: 05-Jun-2006
*/
public class ModuleJdkConfigurable implements Disposable {
public abstract class ModuleJdkConfigurable implements Disposable {
private JdkComboBox myCbModuleJdk;
private Sdk mySelectedModuleJdk = null;
private final ModifiableRootModel myRootModel;
private JPanel myJdkPanel;
private ClasspathEditor myModuleEditor;
private final ProjectJdksModel myJdksModel;
@@ -68,9 +67,8 @@ public class ModuleJdkConfigurable implements Disposable {
}
};
public ModuleJdkConfigurable(ClasspathEditor moduleEditor, ModifiableRootModel model, ProjectJdksModel jdksModel) {
public ModuleJdkConfigurable(ClasspathEditor moduleEditor, ProjectJdksModel jdksModel) {
myModuleEditor = moduleEditor;
myRootModel = model;
myJdksModel = jdksModel;
myJdksModel.addListener(myListener);
init();
@@ -94,11 +92,13 @@ public class ModuleJdkConfigurable implements Disposable {
private void reloadModel() {
myFreeze = true;
myCbModuleJdk.reloadModel(new JdkComboBox.ProjectJdkComboBoxItem(), myRootModel.getModule().getProject());
myCbModuleJdk.reloadModel(new JdkComboBox.ProjectJdkComboBoxItem(), getRootModel().getModule().getProject());
reset();
myFreeze = false;
}
protected abstract ModifiableRootModel getRootModel();
private void init() {
myJdkPanel = new JPanel(new GridBagLayout());
myCbModuleJdk = new JdkComboBox(myJdksModel);
@@ -106,14 +106,14 @@ public class ModuleJdkConfigurable implements Disposable {
myCbModuleJdk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (myFreeze) return;
final Sdk oldJdk = myRootModel.getSdk();
final Sdk oldJdk = getRootModel().getSdk();
mySelectedModuleJdk = myCbModuleJdk.getSelectedJdk();
final Sdk selectedModuleJdk = getSelectedModuleJdk();
if (selectedModuleJdk != null) {
myRootModel.setSdk(selectedModuleJdk);
getRootModel().setSdk(selectedModuleJdk);
}
else {
myRootModel.inheritSdk();
getRootModel().inheritSdk();
}
clearCaches(oldJdk, selectedModuleJdk);
myModuleEditor.flushChangesToModel();
@@ -124,7 +124,7 @@ public class ModuleJdkConfigurable implements Disposable {
myJdkPanel.add(myCbModuleJdk, new GridBagConstraints(1, 0, 1, 1, 0, 1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(6, 6, 12, 0), 0, 0));
final Project project = myRootModel.getModule().getProject();
final Project project = getRootModel().getModule().getProject();
final JButton setUpButton = myCbModuleJdk
.createSetupButton(project, myJdksModel, new JdkComboBox.ProjectJdkComboBoxItem(), new Condition<Sdk>(){
public boolean value(Sdk jdk) {
@@ -146,16 +146,16 @@ public class ModuleJdkConfigurable implements Disposable {
myJdkPanel.add(setUpButton, new GridBagConstraints(2, 0, 1, 1, 0, 0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0, 4, 7, 0), 0, 0));
myCbModuleJdk.appendEditButton(myRootModel.getModule().getProject(), myJdkPanel, new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 4, 7, 0), 0, 0) , new Computable<Sdk>() {
myCbModuleJdk.appendEditButton(getRootModel().getModule().getProject(), myJdkPanel, new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 4, 7, 0), 0, 0) , new Computable<Sdk>() {
@Nullable
public Sdk compute() {
return myRootModel.getSdk();
return getRootModel().getSdk();
}
});
}
private void clearCaches(final Sdk oldJdk, final Sdk selectedModuleJdk) {
final Module module = myRootModel.getModule();
final Module module = getRootModel().getModule();
final Project project = module.getProject();
final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(project).getContext();
context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, module));
@@ -163,8 +163,8 @@ public class ModuleJdkConfigurable implements Disposable {
public void reset() {
myFreeze = true;
final String jdkName = myRootModel.getSdkName();
if (jdkName != null && !myRootModel.isSdkInherited()) {
final String jdkName = getRootModel().getSdkName();
if (jdkName != null && !getRootModel().isSdkInherited()) {
mySelectedModuleJdk = myJdksModel.findSdk(jdkName);
if (mySelectedModuleJdk != null) {
myCbModuleJdk.setSelectedJdk(mySelectedModuleJdk);
@@ -23,6 +23,7 @@ import com.intellij.facet.impl.ui.FacetEditorImpl;
import com.intellij.ide.util.newProjectWizard.AddModuleWizard;
import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.ide.util.projectWizard.ProjectBuilder;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.ModifiableModuleModel;
import com.intellij.openapi.module.Module;
@@ -44,6 +45,7 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProj
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ModifiableArtifactModel;
import com.intellij.projectImport.ProjectImportBuilder;
@@ -106,10 +108,7 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
for (final ModuleEditor moduleEditor : myModuleEditors) {
final ModifiableRootModel model = moduleEditor.dispose();
if (model != null) {
model.dispose();
}
Disposer.dispose(moduleEditor);
}
myModuleEditors.clear();
@@ -171,10 +170,7 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
for (final ModuleEditor moduleEditor : myModuleEditors) {
moduleEditor.removeChangeListener(ModulesConfigurator.this);
}
myModuleEditors.clear();
assert myModuleEditors.isEmpty();
final Module[] modules = myModuleModel.getModules();
if (modules.length > 0) {
for (Module module : modules) {
@@ -189,9 +185,24 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
}
public void createModuleEditor(final Module module) {
final ModuleEditor moduleEditor = new ModuleEditor(myProject, this, myFacetsConfigurator, module);
final ModuleEditor moduleEditor = new ModuleEditor(myProject, this, module) {
@Override
public ProjectFacetsConfigurator getFacetsConfigurator() {
return myFacetsConfigurator;
}
};
final ProjectFacetsConfigurator configurator = myFacetsConfigurator;
moduleEditor.addChangeListener(configurator);
myModuleEditors.add(moduleEditor);
moduleEditor.addChangeListener(this);
Disposer.register(moduleEditor, new Disposable() {
public void dispose() {
moduleEditor.removeChangeListener(ModulesConfigurator.this);
moduleEditor.removeChangeListener(configurator);
}
});
}
public void moduleStateChanged(final ModifiableRootModel moduleRootModel) {
@@ -217,7 +228,7 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
myFacetsConfigurator.applyEditors();
final List<ModifiableRootModel> models = new ArrayList<ModifiableRootModel>(myModuleEditors.size());
for (final ModuleEditor moduleEditor : myModuleEditors) {
final ModifiableRootModel model = moduleEditor.applyAndDispose();
final ModifiableRootModel model = moduleEditor.apply();
if (model != null) {
models.add(model);
}
@@ -234,10 +245,25 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
finally {
myFacetsConfigurator.disposeEditors();
ModuleStructureConfigurable.getInstance(myProject).getFacetEditorFacade().clearMaps();
for (final ModuleEditor moduleEditor : myModuleEditors) {
moduleEditor.removeChangeListener(myFacetsConfigurator);
}
myFacetsConfigurator = createFacetsConfigurator();
myModuleModel = ModuleManager.getInstance(myProject).getModifiableModel();
final ProjectFacetsConfigurator configurator = myFacetsConfigurator;
for (final ModuleEditor moduleEditor : myModuleEditors) {
moduleEditor.addChangeListener(configurator);
Disposer.register(moduleEditor, new Disposable() {
public void dispose() {
moduleEditor.removeChangeListener(configurator);
}
});
}
}
ApplicationManager.getApplication().saveAll();
}
});
@@ -245,13 +271,11 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
throw ex[0];
}
ApplicationManager.getApplication().saveAll();
myModified = false;
}
private ProjectFacetsConfigurator createFacetsConfigurator() {
return new ProjectFacetsConfigurator(myContext, myProject);
return new ProjectFacetsConfigurator(myContext, myProject, myFacetsConfigurator);
}
public void setModified(final boolean modified) {
@@ -383,10 +407,12 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change
final ModifiableRootModel modifiableRootModel = moduleEditor.getModifiableRootModelProxy();
modifiableRootModels.add(modifiableRootModel);
}
// destroyProcess editor
final ModifiableRootModel model = selectedEditor.dispose();
ModuleDeleteProvider.removeModule(moduleToRemove, model, modifiableRootModels, myModuleModel);
ModuleDeleteProvider.removeModule(moduleToRemove, null, modifiableRootModels, myModuleModel);
processModuleCountChanged();
Disposer.dispose(selectedEditor);
return true;
}
@@ -22,9 +22,7 @@
*/
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ModifiableRootModel;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -36,11 +34,11 @@ public class OutputEditor extends ModuleElementsEditor {
private final JavadocEditor myJavadocEditor;
private final AnnotationsEditor myAnnotationsEditor;
protected OutputEditor(final Project project, final ModifiableRootModel model) {
super(project, model);
myCompilerOutputEditor = new BuildElementsEditor(project, model);
myJavadocEditor = new JavadocEditor(project, model);
myAnnotationsEditor = new AnnotationsEditor(project, model);
protected OutputEditor(final ModuleConfigurationState state) {
super(state);
myCompilerOutputEditor = new BuildElementsEditor(state);
myJavadocEditor = new JavadocEditor(state);
myAnnotationsEditor = new AnnotationsEditor(state);
}
protected JComponent createComponentImpl() {
@@ -95,4 +93,4 @@ public class OutputEditor extends ModuleElementsEditor {
public String getHelpTopic() {
return "projectStructure.modules.paths";
}
}
}
@@ -267,14 +267,8 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
}
}
//cleanup
myContext.getDaemonAnalyzer().clearCaches();
SwingUtilities.invokeLater(new Runnable(){
public void run() {
if (myWasUiDisposed) return;
reset();
}
});
myContext.clearCaches(false);
myContext.resetLibraries();
}
public void reset() {
@@ -188,6 +188,8 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
}.execute();
myPackagingEditorContext.resetModifiableModel();
}
reset(); // TODO: fix to not reset on apply!
}
@Override
@@ -314,7 +314,7 @@ public class LibraryTableEditor implements Disposable {
}
private Object[] getSelectedElements() {
if (myTreeBuilder.isDisposed()) return ArrayUtil.EMPTY_OBJECT_ARRAY;
if (myTreeBuilder == null || myTreeBuilder.isDisposed()) return ArrayUtil.EMPTY_OBJECT_ARRAY;
final TreePath[] selectionPaths = myTreeBuilder.getTree().getSelectionPaths();
if (selectionPaths == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
@@ -351,7 +351,7 @@ public class LibraryTableEditor implements Disposable {
@Nullable
private Library getSelectedLibrary() {
if (myTreeBuilder.getTreeStructure() instanceof LibraryTreeStructure) {
if (myTreeBuilder != null && myTreeBuilder.getTreeStructure() instanceof LibraryTreeStructure) {
return ((LibraryTreeStructure)myTreeBuilder.getTreeStructure()).getLibrary();
} else {
return convertElementToLibrary(getSelectedElement());
@@ -423,7 +423,7 @@ public class LibraryTableEditor implements Disposable {
}
public void dispose() {
myTreeBuilder = null;
}
private class AddLibraryAction implements ActionListener {
@@ -195,6 +195,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
if (table != null) {
getModelProvider(true).getModifiableModel().removeLibrary(library);
myContext.getDaemonAnalyzer().removeElement(new LibraryProjectStructureElement(myContext, library));
// TODO: myContext.invalidateModules(myContext.myLibraryDependencyCache.get(library.getName()));
}
}
@@ -311,6 +311,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
((DefaultTreeModel)myTree.getModel()).reload(parent);
}
myContext.getDaemonAnalyzer().removeElement(new LibraryProjectStructureElement(myContext, library));
// TODO: myContext.invalidateModules(myContext.myLibraryDependencyCache.get(library.getName()));
}
}
@@ -321,8 +322,6 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
}
public void reset() {
myContext.reset();
super.reset();
}
@@ -342,6 +341,7 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
public void disposeUIResources() {
super.disposeUIResources();
myFacetEditorFacade.clearMaps();
myContext.clearCaches(true);
myContext.myModulesConfigurator.disposeUIResources();
ModuleStructureConfigurable.super.disposeUIResources();
}
@@ -456,6 +456,14 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
}
modelProxy.addLibraryEntry(library);
myContext.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(myContext, module));
/* TODO
Set<String> modules = myContext.myLibraryDependencyCache.get(library.getName());
if (modules == null) {
modules = new HashSet<String>();
myContext.myLibraryDependencyCache.put(library.getName(), modules);
}
modules.add(module.getName());
*/
myTree.repaint();
}
@@ -38,6 +38,21 @@ import java.util.Map;
public class StructureConfigurableContext implements Disposable {
private final ProjectStructureDaemonAnalyzer myDaemonAnalyzer;
private static final Logger LOG = Logger.getInstance("#" + StructureConfigurableContext.class.getName());
public enum ValidityLevel { VALID, WARNING, ERROR }
public static final String NO_JDK = ProjectBundle.message("project.roots.module.jdk.problem.message");
public static final String DUPLICATE_MODULE_NAME = ProjectBundle.message("project.roots.module.duplicate.name.message");
@NonNls public static final String DELETED_LIBRARIES = "lib";
public final Map<String, Set<String>> myLibraryDependencyCache = new HashMap<String, Set<String>>();
public final Map<Sdk, Set<String>> myJdkDependencyCache = new HashMap<Sdk, Set<String>>();
public final Map<Module, Map<String, Set<String>>> myValidityCache = new HashMap<Module, Map<String, Set<String>>>();
public final Map<Library, ValidityLevel> myLibraryPathValidityCache = new HashMap<Library, ValidityLevel>(); //can be invalidated on startup only
public final Map<Module, Set<String>> myModulesDependencyCache = new HashMap<Module, Set<String>>();
private final ModuleManager myModuleManager;
public final ModulesConfigurator myModulesConfigurator;
public final Map<String, LibrariesModifiableModel> myLevel2Providers = new THashMap<String, LibrariesModifiableModel>();
private final Project myProject;
@@ -58,13 +73,299 @@ public class StructureConfigurableContext implements Disposable {
return myDaemonAnalyzer;
}
@Nullable
public Set<String> getCachedDependencies(final Object selectedObject, boolean force) {
if (selectedObject instanceof Library){
final Library library = (Library)selectedObject;
if (myLibraryDependencyCache.containsKey(library.getName())){
return myLibraryDependencyCache.get(library.getName());
}
} else if (selectedObject instanceof Sdk){
final Sdk projectJdk = (Sdk)selectedObject;
if (myJdkDependencyCache.containsKey(projectJdk)){
return myJdkDependencyCache.get(projectJdk);
}
} else if (selectedObject instanceof Module) {
final Module module = (Module)selectedObject;
if (myModulesDependencyCache.containsKey(module)) {
return myModulesDependencyCache.get(module);
}
}
if (force){
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
final Set<String> dep = getDependencies(selectedObject);
updateCache(selectedObject, dep);
return dep;
} else {
myUpdateDependenciesAlarm.addRequest(new Runnable(){
public void run() {
final Set<String> dep = getDependencies(selectedObject);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (!myDisposed) {
updateCache(selectedObject, dep);
fireOnCacheChanged();
}
}
});
}
}, 100);
return null;
}
}
private void updateCache(final Object selectedObject, final Set<String> dep) {
if (selectedObject instanceof Library) {
myLibraryDependencyCache.put(((Library)selectedObject).getName(), dep);
}
else if (selectedObject instanceof Sdk) {
myJdkDependencyCache.put((Sdk)selectedObject, dep);
}
else if (selectedObject instanceof Module) {
myModulesDependencyCache.put((Module)selectedObject, dep);
}
}
private Set<String> getDependencies(final Condition<OrderEntry> condition) {
final Set<String> result = new TreeSet<String>();
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
final Module[] modules = myModulesConfigurator.getModules();
for (final Module module : modules) {
final ModuleEditor moduleEditor = myModulesConfigurator.getModuleEditor(module);
if (moduleEditor != null) {
final OrderEntry[] entries = moduleEditor.getOrderEntries();
for (OrderEntry entry : entries) {
if (myDisposed) return;
if (condition.value(entry)) {
result.add(module.getName());
break;
}
}
}
}
}
});
return result;
}
@Nullable
private Set<String> getDependencies(final Object selectedObject) {
if (selectedObject instanceof Module) {
return getDependencies(new Condition<OrderEntry>() {
public boolean value(final OrderEntry orderEntry) {
return orderEntry instanceof ModuleOrderEntry && Comparing.equal(((ModuleOrderEntry)orderEntry).getModule(), selectedObject);
}
});
}
else if (selectedObject instanceof Library) {
Library library = (Library)selectedObject;
if (library.getTable() == null) { //module library navigation
HashSet<String> deps = new HashSet<String>();
Module module = ((LibraryImpl)library).getModule();
if (module != null) {
deps.add(module.getName());
}
return deps;
}
return getDependencies(new Condition<OrderEntry>() {
@SuppressWarnings({"SimplifiableIfStatement"})
public boolean value(final OrderEntry orderEntry) {
if (orderEntry instanceof LibraryOrderEntry){
final LibraryImpl library = (LibraryImpl)((LibraryOrderEntry)orderEntry).getLibrary();
if (Comparing.equal(library, selectedObject)) return true;
return library != null && Comparing.equal(library.getSource(), selectedObject);
}
return false;
}
});
}
else if (selectedObject instanceof Sdk) {
return getDependencies(new Condition<OrderEntry>() {
public boolean value(final OrderEntry orderEntry) {
return orderEntry instanceof JdkOrderEntry && Comparing.equal(((JdkOrderEntry)orderEntry).getJdk(), selectedObject);
}
});
}
return null;
}
public void dispose() {
clearCaches(true);
myDisposed = true;
}
public void invalidateModules(final Set<String> modules) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (modules != null) {
for (String module : modules) {
myValidityCache.remove(myModuleManager.findModuleByName(module));
}
}
}
});
}
public void invalidateModuleName(final Module module) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final Map<String, Set<String>> problems = myValidityCache.remove(module);
if (problems != null) {
fireOnCacheChanged();
}
}
});
}
public ModulesConfigurator getModulesConfigurator() {
return myModulesConfigurator;
}
public void clearCaches(final boolean cleanCacheUpdaters) {
myJdkDependencyCache.clear();
myLibraryDependencyCache.clear();
myValidityCache.clear();
myLibraryPathValidityCache.clear();
myModulesDependencyCache.clear();
fireOnCacheChanged();
if (cleanCacheUpdaters) {
myCacheUpdaters.clear();
}
}
public void clearCaches(final Module module, final List<Library> chosen) {
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
for (Library library : chosen) {
myLibraryDependencyCache.remove(library.getName());
}
myValidityCache.remove(module);
fireOnCacheChanged();
}
public void clearCaches(final Module module, final Sdk oldJdk, final Sdk selectedModuleJdk) {
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
myJdkDependencyCache.remove(oldJdk);
myJdkDependencyCache.remove(selectedModuleJdk);
myValidityCache.remove(module);
fireOnCacheChanged();
}
public void clearCaches(final OrderEntry entry) {
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
if (entry instanceof ModuleOrderEntry) {
final Module module = ((ModuleOrderEntry)entry).getModule();
myValidityCache.remove(module);
myModulesDependencyCache.remove(module);
} else if (entry instanceof JdkOrderEntry) {
invalidateModules(myJdkDependencyCache.remove(((JdkOrderEntry)entry).getJdk()));
} else if (entry instanceof LibraryOrderEntry) {
invalidateModules(myLibraryDependencyCache.remove(((LibraryOrderEntry)entry).getLibraryName()));
}
fireOnCacheChanged();
}
public ValidityLevel isInvalid(final Object object) {
if (object instanceof Module){
final Module module = (Module)object;
if (myValidityCache.containsKey(module)) {
boolean valid = myValidityCache.get(module) == null;
return valid ? ValidityLevel.VALID : ValidityLevel.ERROR;
}
myUpdateDependenciesAlarm.addRequest(new Runnable(){
public void run() {
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
updateModuleValidityCache(module);
}
});
}
}, 100);
} else if (object instanceof LibraryEx) {
final LibraryEx library = (LibraryEx)object;
if (myLibraryPathValidityCache.containsKey(library)) return myLibraryPathValidityCache.get(library);
myUpdateDependenciesAlarm.addRequest(new Runnable(){
public void run() {
ApplicationManager.getApplication().runReadAction(new Runnable() {
public void run() {
updateLibraryValidityCache(library);
}
});
}
}, 100);
}
return ValidityLevel.VALID;
}
private void updateLibraryValidityCache(final LibraryEx library) {
if (myLibraryPathValidityCache.containsKey(library)) return; //do not check twice
ValidityLevel level = ValidityLevel.VALID;
if (!(library.allPathsValid(JavadocOrderRootType.getInstance()) && library.allPathsValid(OrderRootType.SOURCES))) {
level = ValidityLevel.WARNING;
}
if (!library.allPathsValid(OrderRootType.CLASSES)) {
level = ValidityLevel.ERROR;
}
final ValidityLevel finalLevel = level;
SwingUtilities.invokeLater(new Runnable(){
public void run() {
if (!myDisposed){
myLibraryPathValidityCache.put(library, finalLevel);
fireOnCacheChanged();
}
}
});
}
private void updateModuleValidityCache(final Module module) {
if (myValidityCache.containsKey(module)) return; //do not check twice
if (myDisposed) return;
Map<String, Set<String>> problems = null;
final ModifiableModuleModel moduleModel = myModulesConfigurator.getModuleModel();
final Module[] all = moduleModel.getModules();
for (Module each : all) {
if (each != module && getRealName(each).equals(getRealName(module))) {
problems = new HashMap<String, Set<String>>();
problems.put(DUPLICATE_MODULE_NAME, null);
break;
}
}
final ModuleRootModel rootModel = myModulesConfigurator.getRootModel(module);
if (rootModel == null) return; //already disposed
final OrderEntry[] entries = rootModel.getOrderEntries();
for (OrderEntry entry : entries) {
if (myDisposed) return;
if (!entry.isValid()){
if (problems == null) {
problems = new HashMap<String, Set<String>>();
}
if (entry instanceof JdkOrderEntry && ((JdkOrderEntry)entry).getJdkName() == null) {
problems.put(NO_JDK, null);
} else {
Set<String> deletedLibraries = problems.get(DELETED_LIBRARIES);
if (deletedLibraries == null){
deletedLibraries = new HashSet<String>();
problems.put(DELETED_LIBRARIES, deletedLibraries);
}
deletedLibraries.add(entry.getPresentableName());
}
}
}
final Map<String, Set<String>> finalProblems = problems;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (!myDisposed) {
myValidityCache.put(module, finalProblems);
fireOnCacheChanged();
}
}
});
}
public Module[] getModules() {
return myModulesConfigurator.getModules();
}
@@ -36,9 +36,8 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.JavaContentEntriesEditor;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
import com.intellij.openapi.ui.DialogWrapperPeerFactory;
import com.intellij.openapi.ui.PackageChooser;
import com.intellij.openapi.ui.SplitterProportionsData;
@@ -251,9 +250,8 @@ public class PeerFactoryImpl extends PeerFactory {
return projectJdk;
}
public ModuleConfigurationEditor createModuleConfigurationEditor(final Project project, final String moduleName, final ModifiableRootModel model,
final ModulesProvider modulesProvider) {
return new JavaContentEntriesEditor(project, moduleName, model, modulesProvider);
public ModuleConfigurationEditor createModuleConfigurationEditor(final String moduleName, ModuleConfigurationState state) {
return new JavaContentEntriesEditor(moduleName, state);
}
}
@@ -29,8 +29,7 @@ import com.intellij.openapi.module.ModuleConfigurationEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
import com.intellij.openapi.ui.DialogWrapperPeerFactory;
import com.intellij.openapi.vcs.FileStatusFactory;
import com.intellij.openapi.vcs.actions.VcsContextFactory;
@@ -89,6 +88,5 @@ public abstract class PeerFactory {
public abstract Sdk createProjectJdk(String name, final String version, final String homePath, SdkType sdkType);
public abstract ModuleConfigurationEditor createModuleConfigurationEditor(Project project, String moduleName, ModifiableRootModel model,
ModulesProvider modulesProvider);
public abstract ModuleConfigurationEditor createModuleConfigurationEditor(String moduleName, ModuleConfigurationState state);
}