diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryDependencyAction.java similarity index 92% rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java rename to java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryDependencyAction.java index f5c7a10df676..0249f8955a00 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryDependencyAction.java @@ -40,11 +40,11 @@ import java.util.List; /** * @author nik */ -class AddLibraryAction extends AddItemPopupAction { +class AddLibraryDependencyAction extends AddItemPopupAction { private final StructureConfigurableContext myContext; - public AddLibraryAction(ClasspathPanel classpathPanel, final int index, final String title, - final StructureConfigurableContext context) { + public AddLibraryDependencyAction(ClasspathPanel classpathPanel, final int index, final String title, + final StructureConfigurableContext context) { super(classpathPanel, index, title, PlatformIcons.LIBRARY_ICON); myContext = context; } @@ -59,7 +59,7 @@ class AddLibraryAction extends AddItemPopupAction { return LibraryEditingUtil.createChooseTypeStep(myClasspathPanel, new ParameterizedRunnable() { @Override public void run(LibraryType libraryType) { - new AddNewLibraryItemAction(myClasspathPanel, myContext, libraryType).execute(); + new AddNewLibraryDependencyAction(myClasspathPanel, myContext, libraryType).execute(); } }); } @@ -70,7 +70,7 @@ class AddLibraryAction extends AddItemPopupAction { super.run(); } else { - new AddNewLibraryItemAction(myClasspathPanel, myContext, null).run(); + new AddNewLibraryDependencyAction(myClasspathPanel, myContext, null).run(); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddModuleDependencyAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddModuleDependencyAction.java new file mode 100644 index 000000000000..e320de1d8265 --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddModuleDependencyAction.java @@ -0,0 +1,98 @@ +/* + * Copyright 2000-2011 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.roots.ui.configuration.classpath; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.StdModuleTypes; +import com.intellij.openapi.project.ProjectBundle; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog; +import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; +import com.intellij.openapi.ui.Messages; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +/** +* @author nik +*/ +class AddModuleDependencyAction extends AddItemPopupAction { + private final StructureConfigurableContext myContext; + private final ClasspathPanel myClasspathPanel; + + public AddModuleDependencyAction(final ClasspathPanel classpathPanel, + int actionIndex, + StructureConfigurableContext context) { + super(classpathPanel, actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"), + StdModuleTypes.JAVA.getNodeIcon(false)); + myContext = context; + myClasspathPanel = classpathPanel; + } + + protected ClasspathTableItem createTableItem(final Module item) { + return ClasspathTableItem.createItem(myClasspathPanel.getRootModel().addModuleOrderEntry(item), myContext); + } + + private List getNotAddedModules() { + final ModifiableRootModel rootModel = myClasspathPanel.getRootModel(); + Set addedModules = new HashSet(Arrays.asList(rootModel.getModuleDependencies(true))); + addedModules.add(rootModel.getModule()); + + final Module[] modules = myClasspathPanel.getModuleConfigurationState().getModulesProvider().getModules(); + final List elements = new ArrayList(); + for (final Module module : modules) { + if (!addedModules.contains(module)) { + elements.add(module); + } + } + return elements; + } + + protected ClasspathElementChooser createChooser() { + final List chooseItems = getNotAddedModules(); + if (chooseItems.isEmpty()) { + Messages.showMessageDialog(myClasspathPanel.getComponent(), ProjectBundle.message("message.no.module.dependency.candidates"), getTitle(), + Messages.getInformationIcon()); + return null; + } + return new ModuleChooser(myClasspathPanel, chooseItems, ProjectBundle.message("classpath.chooser.title.add.module.dependency"), + ProjectBundle.message("classpath.chooser.description.add.module.dependency")); + } + + private static class ModuleChooser implements ClasspathElementChooser { + private final List myItems; + private final String myTitle; + private final String myDescription; + private final ClasspathPanel myClasspathPanel; + + public ModuleChooser(final ClasspathPanel classpathPanel, + final List items, + final String title, + String description) { + myItems = items; + myTitle = title; + myDescription = description; + myClasspathPanel = classpathPanel; + } + + @NotNull + public List chooseElements() { + ChooseModulesDialog dialog = new ChooseModulesDialog(myClasspathPanel.getComponent(), myItems, myTitle, myDescription); + dialog.show(); + return dialog.getChosenElements(); + } + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryDependencyAction.java similarity index 93% rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java rename to java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryDependencyAction.java index a8892d9667b4..08b8aba2c769 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryDependencyAction.java @@ -32,12 +32,12 @@ import javax.swing.*; /** * @author nik */ -class AddNewLibraryItemAction extends ChooseAndAddAction { +class AddNewLibraryDependencyAction extends ChooseAndAddAction { private final StructureConfigurableContext myContext; private final LibraryType myLibraryType; - public AddNewLibraryItemAction(final ClasspathPanel classpathPanel, - StructureConfigurableContext context, LibraryType libraryType) { + public AddNewLibraryDependencyAction(final ClasspathPanel classpathPanel, + StructureConfigurableContext context, LibraryType libraryType) { super(classpathPanel); myContext = context; myLibraryType = libraryType; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddModuleLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewModuleLibraryAction.java similarity index 86% rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddModuleLibraryAction.java rename to java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewModuleLibraryAction.java index 520e6be64c96..ef8c3bc6e519 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddModuleLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewModuleLibraryAction.java @@ -27,13 +27,13 @@ import com.intellij.util.PlatformIcons; /** * @author nik */ -class AddModuleLibraryAction extends AddItemPopupAction { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.AddModuleLibraryAction"); +class AddNewModuleLibraryAction extends AddItemPopupAction { + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.AddNewModuleLibraryAction"); private final StructureConfigurableContext myContext; - public AddModuleLibraryAction(final ClasspathPanel classpathPanel, - int actionIndex, - StructureConfigurableContext context) { + public AddNewModuleLibraryAction(final ClasspathPanel classpathPanel, + int actionIndex, + StructureConfigurableContext context) { super(classpathPanel, actionIndex, ProjectBundle.message("classpath.add.simple.module.library.action"), PlatformIcons.JAR_ICON); myContext = context; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java index ac201730ea3c..25ad49d4dd64 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java @@ -17,7 +17,6 @@ package com.intellij.openapi.roots.ui.configuration.classpath; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.StdModuleTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.Sdk; @@ -41,7 +40,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProj import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.SdkProjectStructureElement; import com.intellij.openapi.ui.ComboBoxTableRenderer; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.PopupStep; @@ -67,10 +65,8 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import java.awt.*; import java.awt.event.*; -import java.util.ArrayList; -import java.util.HashSet; +import java.util.*; import java.util.List; -import java.util.Set; public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { private final JBTable myEntryTable; @@ -484,23 +480,9 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { int actionIndex = 1; final List> actions = new ArrayList>(); final StructureConfigurableContext context = getStructureConfigurableContext(); - actions.add(new AddModuleLibraryAction(this, actionIndex++, context)); - actions.add(new AddLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.library.action"), context)); - actions.add(new AddItemPopupAction(this, actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"), - StdModuleTypes.JAVA.getNodeIcon(false)) { - protected ClasspathTableItem createTableItem(final Module item) { - return ClasspathTableItem.createItem(getRootModel().addModuleOrderEntry(item), context); - } - protected ClasspathElementChooser createChooser() { - final List chooseItems = getDependencyModules(); - if (chooseItems.isEmpty()) { - Messages.showMessageDialog(ClasspathPanelImpl.this, ProjectBundle.message("message.no.module.dependency.candidates"), getTitle(), Messages.getInformationIcon()); - return null; - } - return new ModuleChooser(chooseItems, ProjectBundle.message("classpath.chooser.title.add.module.dependency"), - ProjectBundle.message("classpath.chooser.description.add.module.dependency")); - } - } + actions.add(new AddNewModuleLibraryAction(this, actionIndex++, context)); + actions.add(new AddLibraryDependencyAction(this, actionIndex++, ProjectBundle.message("classpath.add.library.action"), context)); + actions.add(new AddModuleDependencyAction(this, actionIndex, context) ); myPopupActions = actions; @@ -602,29 +584,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { TableUtil.selectRows(myEntryTable, selection); } - private List getDependencyModules() { - final int rowCount = myModel.getRowCount(); - final Set filtered = new HashSet(rowCount); - for (int row = 0; row < rowCount; row++) { - final OrderEntry entry = myModel.getItemAt(row).getEntry(); - if (entry instanceof ModuleOrderEntry) { - filtered.add(((ModuleOrderEntry)entry).getModuleName()); - } - } - final ModulesProvider modulesProvider = myState.getModulesProvider(); - final Module self = modulesProvider.getModule(getRootModel().getModule().getName()); - filtered.add(self.getName()); - - final Module[] modules = modulesProvider.getModules(); - final List elements = new ArrayList(modules.length); - for (final Module module : modules) { - if (!filtered.contains(module.getName())) { - elements.add(module); - } - } - return elements; - } - private static CellAppearanceEx getCellAppearance(final ClasspathTableItem item, final StructureConfigurableContext context, final boolean selected) { @@ -677,25 +636,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { } } - private class ModuleChooser implements ClasspathElementChooser { - private final List myItems; - private final String myTitle; - private final String myDescription; - - public ModuleChooser(final List items, final String title, String description) { - myItems = items; - myTitle = title; - myDescription = description; - } - - @NotNull - public List chooseElements() { - ChooseModulesDialog dialog = new ChooseModulesDialog(ClasspathPanelImpl.this, myItems, myTitle, myDescription); - dialog.show(); - return dialog.getChosenElements(); - } - } - private class MyFindUsagesAction extends FindUsagesInProjectStructureActionBase { private MyFindUsagesAction() { super(myEntryTable, myState.getProject()); @@ -735,5 +675,4 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { return new RelativePoint(myEntryTable, location); } } - } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java index 1904b6e4c4bc..09e3e887c7df 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java @@ -169,16 +169,16 @@ public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTa @Override protected void doAction(ActionEvent e) { - AddNewLibraryItemAction.chooseTypeAndCreate(myClasspathPanel, myContext, myCreateLibraryButton, - new AddNewLibraryItemAction.LibraryCreatedCallback() { - @Override - public void libraryCreated(@NotNull Library library) { - if (library.getTable() == null) { - myCreatedModuleLibraries.add(library); - } - queueUpdateAndSelect(library); - } - }); + AddNewLibraryDependencyAction.chooseTypeAndCreate(myClasspathPanel, myContext, myCreateLibraryButton, + new AddNewLibraryDependencyAction.LibraryCreatedCallback() { + @Override + public void libraryCreated(@NotNull Library library) { + if (library.getTable() == null) { + myCreatedModuleLibraries.add(library); + } + queueUpdateAndSelect(library); + } + }); } } }