diff --git a/java/idea-ui/src/com/intellij/ide/projectView/actions/CreateLibraryFromFilesDialog.java b/java/idea-ui/src/com/intellij/ide/projectView/actions/CreateLibraryFromFilesDialog.java index a75eb5d5ce5a..0b35148283dc 100644 --- a/java/idea-ui/src/com/intellij/ide/projectView/actions/CreateLibraryFromFilesDialog.java +++ b/java/idea-ui/src/com/intellij/ide/projectView/actions/CreateLibraryFromFilesDialog.java @@ -26,7 +26,7 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil; import com.intellij.openapi.roots.impl.libraries.LibraryTypeServiceImpl; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.ui.OrderRoot; -import com.intellij.openapi.roots.ui.configuration.ModulesCombobox; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryNameAndLevelPanel; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory; @@ -50,7 +50,7 @@ import java.util.List; */ public class CreateLibraryFromFilesDialog extends DialogWrapper { private final LibraryNameAndLevelPanel myNameAndLevelPanel; - private final ModulesCombobox myModulesCombobox; + private final ModulesComboBox myModulesComboBox; private final Project myProject; private final List myRoots; private final JPanel myPanel; @@ -67,10 +67,10 @@ public class CreateLibraryFromFilesDialog extends DialogWrapper { myNameAndLevelPanel = new LibraryNameAndLevelPanel(builder, myDefaultName, Arrays.asList(LibrariesContainer.LibraryLevel.values()), LibrariesContainer.LibraryLevel.PROJECT); myNameAndLevelPanel.setDefaultName(myDefaultName); - myModulesCombobox = new ModulesCombobox(); - myModulesCombobox.fillModules(myProject); - myModulesCombobox.setSelectedModule(findModule(roots)); - builder.addLabeledComponent("&Add to module:", myModulesCombobox); + myModulesComboBox = new ModulesComboBox(); + myModulesComboBox.fillModules(myProject); + myModulesComboBox.setSelectedModule(findModule(roots)); + builder.addLabeledComponent("&Add to module:", myModulesComboBox); myPanel = builder.getPanel(); myNameAndLevelPanel.getLibraryNameField().selectAll(); myNameAndLevelPanel.getLevelComboBox().addActionListener(new ActionListener() { @@ -134,7 +134,7 @@ public class CreateLibraryFromFilesDialog extends DialogWrapper { final LibrariesContainer.LibraryLevel level = myNameAndLevelPanel.getLibraryLevel(); AccessToken token = WriteAction.start(); try { - final Module module = myModulesCombobox.getSelectedModule(); + final Module module = myModulesComboBox.getSelectedModule(); final String libraryName = myNameAndLevelPanel.getLibraryName(); if (level == LibrariesContainer.LibraryLevel.MODULE) { final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddModuleDependencyFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddModuleDependencyFix.java index 348d052a81b4..f3b95702eac7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddModuleDependencyFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddModuleDependencyFix.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.daemon.impl.quickfix; +import com.intellij.application.options.ModuleListCellRenderer; import com.intellij.codeInsight.daemon.QuickFixBundle; import com.intellij.codeInsight.daemon.impl.actions.AddImportAction; import com.intellij.compiler.ModuleCompilerUtil; @@ -22,7 +23,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.*; @@ -32,13 +32,11 @@ import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; -import com.intellij.ui.ListCellRendererWrapper; import com.intellij.ui.components.JBList; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -115,15 +113,7 @@ class AddModuleDependencyFix extends OrderEntryFix { } else { final JBList list = new JBList(myModules); - list.setCellRenderer(new ListCellRendererWrapper() { - @Override - public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) { - if (module != null) { - setIcon(ModuleType.get(module).getIcon()); - setText(module.getName()); - } - } - }); + list.setCellRenderer(new ModuleListCellRenderer()); final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list) .setTitle("Choose Module to Add Dependency on") .setMovable(false) diff --git a/platform/lang-impl/src/com/intellij/application/options/ModulesComboBox.java b/platform/lang-impl/src/com/intellij/application/options/ModulesComboBox.java new file mode 100644 index 000000000000..17434cb0c7ba --- /dev/null +++ b/platform/lang-impl/src/com/intellij/application/options/ModulesComboBox.java @@ -0,0 +1,93 @@ +/* + * Copyright 2000-2012 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.application.options; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; +import com.intellij.openapi.ui.ComboBox; +import com.intellij.ui.ComboboxSpeedSearch; +import com.intellij.ui.SortedComboBoxModel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +/** + * @author nik + */ +public class ModulesComboBox extends ComboBox { + private final SortedComboBoxModel myModel; + + public ModulesComboBox() { + this(new SortedComboBoxModel(ModulesAlphaComparator.INSTANCE)); + } + + private ModulesComboBox(final SortedComboBoxModel model) { + super(model); + myModel = model; + new ComboboxSpeedSearch(this){ + @Override + protected String getElementText(Object element) { + if (element instanceof Module) { + return ((Module)element).getName(); + } else if (element == null) { + return ""; + } + return super.getElementText(element); + } + }; + setRenderer(new ModuleListCellRenderer()); + } + + public void setModules(@NotNull Collection modules) { + myModel.setAll(modules); + } + + public void fillModules(@NotNull Project project) { + fillModules(project, null); + } + + public void fillModules(@NotNull Project project, final @Nullable ModuleType moduleType) { + Module[] allModules = ModuleManager.getInstance(project).getModules(); + if (moduleType == null) { + setModules(Arrays.asList(allModules)); + } + else { + List modules = new ArrayList(); + for (Module module : allModules) { + if (moduleType.equals(ModuleType.get(module))) { + modules.add(module); + } + } + setModules(modules); + } + } + + public void setSelectedModule(@Nullable Module module) { + myModel.setSelectedItem(module); + } + + @Nullable + public Module getSelectedModule() { + return myModel.getSelectedItem(); + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java index ab14685b0c12..5c5ea6463e2b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ModulesCombobox.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -15,77 +15,12 @@ */ package com.intellij.openapi.roots.ui.configuration; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.module.ModuleType; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.ComboBox; -import com.intellij.ui.ComboboxSpeedSearch; -import com.intellij.ui.ListCellRendererWrapper; -import com.intellij.ui.SortedComboBoxModel; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; +import com.intellij.application.options.ModulesComboBox; /** * @author nik + * @deprecated use {@link com.intellij.application.options.ModulesComboBox} instead */ -//todo[nik] use this class where possible -public class ModulesCombobox extends ComboBox { - private final SortedComboBoxModel myModel; - - public ModulesCombobox() { - this(new SortedComboBoxModel(ModulesAlphaComparator.INSTANCE)); - } - - private ModulesCombobox(final SortedComboBoxModel model) { - super(model); - myModel = model; - new ComboboxSpeedSearch(this){ - @Override - protected String getElementText(Object element) { - if (element instanceof Module) { - return ((Module)element).getName(); - } else if (element == null) { - return ""; - } - return super.getElementText(element); - } - }; - setRenderer(new ListCellRendererWrapper() { - @Override - public void customize(JList list, Module value, int index, boolean selected, boolean hasFocus) { - if (value != null) { - setText(value.getName()); - setIcon(ModuleType.get(value).getIcon()); - } - else { - setText("[none]"); - } - } - }); - } - - public void fillModules(@NotNull Project project) { - fillModules(project, null); - } - - public void fillModules(@NotNull Project project, final @Nullable ModuleType moduleType) { - myModel.clear(); - for (Module module : ModuleManager.getInstance(project).getModules()) { - if (moduleType == null || moduleType.equals(ModuleType.get(module))) { - myModel.add(module); - } - } - } - - public void setSelectedModule(@Nullable Module module) { - myModel.setSelectedItem(module); - } - - @Nullable - public Module getSelectedModule() { - return myModel.getSelectedItem(); - } +@Deprecated +public class ModulesCombobox extends ModulesComboBox { } diff --git a/plugins/devkit/src/run/PluginRunConfigurationEditor.java b/plugins/devkit/src/run/PluginRunConfigurationEditor.java index a5165334b1df..f65bd28a8fc4 100644 --- a/plugins/devkit/src/run/PluginRunConfigurationEditor.java +++ b/plugins/devkit/src/run/PluginRunConfigurationEditor.java @@ -24,7 +24,7 @@ import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.ui.configuration.ModulesCombobox; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.ui.LabeledComponent; import com.intellij.ui.PanelWithAnchor; import com.intellij.ui.RawCommandLineEditor; @@ -49,7 +49,7 @@ import java.io.IOException; import java.util.ArrayList; public class PluginRunConfigurationEditor extends SettingsEditor implements PanelWithAnchor { - private final ModulesCombobox myModules = new ModulesCombobox(); + private final ModulesComboBox myModules = new ModulesComboBox(); private final JBLabel myModuleLabel = new JBLabel(ExecutionBundle.message("application.configuration.use.classpath.and.jdk.of.module.label")); private final LabeledComponent myVMParameters = new LabeledComponent(); private final LabeledComponent myProgramParameters = new LabeledComponent(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.form b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.form index 688fe451db4c..a86aade6a66f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.form +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.form @@ -39,7 +39,7 @@ - + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.java index 68f6d50ae80d..d81ce98ffec6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunConfigurationEditor.java @@ -20,13 +20,13 @@ import com.intellij.execution.configuration.EnvironmentVariablesComponent; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.DocumentAdapter; import com.intellij.ui.PanelWithAnchor; import com.intellij.ui.RawCommandLineEditor; import com.intellij.ui.components.JBLabel; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.mvc.util.ModuleCellRenderer; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -35,8 +35,7 @@ import java.io.File; import java.util.HashMap; public class MvcRunConfigurationEditor extends SettingsEditor implements PanelWithAnchor { - private DefaultComboBoxModel myModulesModel; - protected JComboBox myModulesBox; + protected ModulesComboBox myModulesBox; private JPanel myMainPanel; private RawCommandLineEditor myVMParameters; private JTextField myCommandLine; @@ -67,11 +66,8 @@ public class MvcRunConfigurationEditor extends Se myCommandLine.setText(configuration.cmdLine); - myModulesModel.removeAllElements(); - for (Module module : configuration.getValidModules()) { - myModulesModel.addElement(module); - } - myModulesModel.setSelectedItem(configuration.getModule()); + myModulesBox.setModules(configuration.getValidModules()); + myModulesBox.setSelectedModule(configuration.getModule()); commandLineChanged(getCommandLine()); @@ -142,7 +138,7 @@ public class MvcRunConfigurationEditor extends Se } protected Module getSelectedModule() { - return (Module)myModulesBox.getSelectedItem(); + return myModulesBox.getSelectedModule(); } public void addExtension(JComponent component) { @@ -152,10 +148,6 @@ public class MvcRunConfigurationEditor extends Se @Override @NotNull protected JComponent createEditor() { - myModulesModel = new DefaultComboBoxModel(); - myModulesBox.setModel(myModulesModel); - myModulesBox.setRenderer(new ModuleCellRenderer(myModulesBox.getRenderer())); - return myMainPanel; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.form b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.form index 3d086ca296b6..cafff50f6c2a 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.form +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.form @@ -69,7 +69,7 @@ - + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.java index 2b629bb668a1..65c6b4be97b4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcRunTargetDialog.java @@ -22,14 +22,17 @@ import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.fileTypes.PlainTextFileType; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.ui.*; +import com.intellij.ui.EditorComboBoxEditor; +import com.intellij.ui.EditorComboBoxRenderer; +import com.intellij.ui.EditorTextField; +import com.intellij.ui.StringComboboxEditor; import com.intellij.util.TextFieldCompletionProvider; import com.intellij.util.TextFieldCompletionProviderDumbAware; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.mvc.util.ModuleCellRenderer; import org.jetbrains.plugins.groovy.mvc.util.MvcTargetDialogCompletionUtils; import javax.swing.*; @@ -47,7 +50,7 @@ public class MvcRunTargetDialog extends DialogWrapper { private JLabel myTargetLabel; private JPanel myFakePanel; private EditorTextField myVmOptionsField; - private JComboBox myModuleBox; + private ModulesComboBox myModuleBox; private JLabel myModuleLabel; private JLabel myVmOptionLabel; private ComboBox myTargetField; @@ -114,18 +117,17 @@ public class MvcRunTargetDialog extends DialogWrapper { assert mvcModules.contains(myModule); myModuleLabel.setLabelFor(myModuleBox); - myModuleBox.setModel(new CollectionComboBoxModel(mvcModules, myModule)); + myModuleBox.setModules(mvcModules); + myModuleBox.setSelectedModule(myModule); myModuleBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - myModule = (Module)myModuleBox.getSelectedItem(); + myModule = myModuleBox.getSelectedModule(); if (myInteractiveRunAction != null) { myInteractiveRunAction.setEnabled(myFramework.isInteractiveConsoleSupported(myModule)); } } }); - - myModuleBox.setRenderer(new ModuleCellRenderer(myModuleBox.getRenderer())); } @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java deleted file mode 100644 index 208de7bbcfbc..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/util/ModuleCellRenderer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2012 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 org.jetbrains.plugins.groovy.mvc.util; - -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; -import com.intellij.ui.ListCellRendererWrapper; - -import javax.swing.*; - -/** - * @author Sergey Evdokimov - */ -public class ModuleCellRenderer extends ListCellRendererWrapper { - public ModuleCellRenderer(ListCellRenderer renderer) { - super(); - } - - @Override - public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) { - if (module != null) { - setIcon(ModuleType.get(module).getIcon()); - setText(module.getName()); - } - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.form b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.form index 31e26e527258..a5ffd20bd1d2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.form +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.form @@ -74,7 +74,7 @@ - + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java index 46a0d0389f49..e41164f7442d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java @@ -19,26 +19,22 @@ package org.jetbrains.plugins.groovy.runner; import com.intellij.execution.configuration.EnvironmentVariablesComponent; import com.intellij.ide.util.BrowseFilesListener; import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; -import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.*; +import com.intellij.ui.FieldPanel; +import com.intellij.ui.PanelWithAnchor; +import com.intellij.ui.RawCommandLineEditor; import com.intellij.ui.components.JBLabel; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyFileType; import javax.swing.*; import java.awt.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; public class GroovyRunConfigurationEditor extends SettingsEditor implements PanelWithAnchor { - private DefaultComboBoxModel myModulesModel; - private JComboBox myModulesBox; + private ModulesComboBox myModulesBox; private JPanel myMainPanel; private RawCommandLineEditor myVMParameters; private RawCommandLineEditor myParameters; @@ -93,20 +89,15 @@ public class GroovyRunConfigurationEditor extends SettingsEditor modules = new ArrayList(configuration.getValidModules()); - Collections.sort(modules, ModulesAlphaComparator.INSTANCE); - for (Module module : modules) { - myModulesModel.addElement(module); - } - myModulesModel.setSelectedItem(configuration.getModule()); + myModulesBox.setModules(configuration.getValidModules()); + myModulesBox.setSelectedModule(configuration.getModule()); myEnvVariables.setEnvs(configuration.getEnvs()); } @Override public void applyEditorTo(GroovyScriptRunConfiguration configuration) throws ConfigurationException { - configuration.setModule((Module) myModulesBox.getSelectedItem()); + configuration.setModule(myModulesBox.getSelectedModule()); configuration.setVMParameters(myVMParameters.getText()); configuration.setDebugEnabled(myDebugCB.isSelected()); configuration.setScriptParameters(myParameters.getText()); @@ -118,27 +109,8 @@ public class GroovyRunConfigurationEditor extends SettingsEditor() { - @Override - public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) { - if (module != null) { - setIcon(ModuleType.get(module).getIcon()); - setText(module.getName()); - } - } - }); - new ComboboxSpeedSearch(myModulesBox) { - @Override - protected String getElementText(Object element) { - return element instanceof Module ? ((Module)element).getName() : ""; - } - }; - return myMainPanel; } diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.form b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.form index c87e145b593f..ff5481019391 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.form +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.form @@ -58,7 +58,7 @@ - + diff --git a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java index 554f54daf5c2..4e15b28864d0 100644 --- a/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java +++ b/plugins/xpath/xpath-view/src/org/intellij/plugins/xpathView/search/ScopePanel.java @@ -20,14 +20,12 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.ComboBox; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.Disposer; import com.intellij.ui.ComboboxWithBrowseButton; import com.intellij.ui.DocumentAdapter; -import com.intellij.ui.ListCellRendererWrapper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,7 +44,7 @@ public class ScopePanel extends JPanel implements Disposable{ private JRadioButton myWholeProjectScope; private JRadioButton myModuleScope; - private ComboBox myModuleSelection; + private ModulesComboBox myModuleSelection; private JRadioButton myDirectoryScope; private TextFieldWithBrowseButton myDirectory; @@ -91,16 +89,7 @@ public class ScopePanel extends JPanel implements Disposable{ myCustomScope.addItemListener(stateListener); myCustomScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.CUSTOM); - myModuleSelection.setModel(createModel(ModuleManager.getInstance(myProject).getModules())); - myModuleSelection.setRenderer(new ListCellRendererWrapper() { - @Override - public void customize(JList list, Module m, int index, boolean selected, boolean hasFocus) { - if (m != null) { - setIcon(ModuleType.get(m).getIcon()); - setText(m.getName()); - } - } - }); + myModuleSelection.fillModules(myProject); Module m; if (scope.getModuleName() != null) { @@ -111,7 +100,7 @@ public class ScopePanel extends JPanel implements Disposable{ m = currentModule; } if (m != null) { - myModuleSelection.setSelectedItem(m); + myModuleSelection.setSelectedModule(m); } myModuleSelection.addItemListener(scopeListener); @@ -148,7 +137,7 @@ public class ScopePanel extends JPanel implements Disposable{ @Nullable private String getModuleName() { - final Module module = ((Module)myModuleSelection.getSelectedItem()); + final Module module = myModuleSelection.getSelectedModule(); return module != null ? module.getName() : null; } diff --git a/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.form b/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.form index 108b9af1902f..b732b517538b 100644 --- a/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.form +++ b/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.form @@ -80,7 +80,7 @@ - + diff --git a/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.java b/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.java index 94e991240001..3b590371e610 100644 --- a/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.java +++ b/python/ide/src/com/jetbrains/python/PyIdeCommonOptionsForm.java @@ -26,6 +26,7 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkModel; import com.intellij.openapi.projectRoots.impl.SdkListCellRenderer; import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.ui.TextFieldWithBrowseButton; @@ -40,7 +41,6 @@ import com.intellij.util.PathMappingSettings; import com.jetbrains.python.configuration.PyConfigurableInterpreterList; import com.jetbrains.python.configuration.PyConfigureInterpretersLinkPanel; import com.jetbrains.python.run.AbstractPyCommonOptionsForm; -import com.intellij.application.options.ModuleListCellRenderer; import com.jetbrains.python.run.PyCommonOptionsFormData; import com.jetbrains.python.sdk.PySdkUtil; import com.jetbrains.python.sdk.PythonSdkType; @@ -64,7 +64,7 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm { private JComboBox myInterpreterComboBox; private JBLabel myPythonInterpreterJBLabel; private JLabel myProjectLabel; - private JComboBox myModuleCombo; + private ModulesComboBox myModuleCombo; private JPanel myConfigureInterpretersPanel; private String mySelectedSdkHome = null; private PathMappingsComponent myPathMappingsComponent; @@ -97,15 +97,15 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm { else { final List validModules = data.getValidModules(); Module selection = validModules.size() > 0 ? validModules.get(0) : null; - myModuleCombo.setModel(new CollectionComboBoxModel(validModules, selection)); - myModuleCombo.setRenderer(new ModuleListCellRenderer()); + myModuleCombo.setModules(validModules); + myModuleCombo.setSelectedModule(selection); myModuleCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - updateDefaultInterpreter((Module)myModuleCombo.getSelectedItem()); + updateDefaultInterpreter(myModuleCombo.getSelectedModule()); } }); - updateDefaultInterpreter((Module)myModuleCombo.getSelectedItem()); + updateDefaultInterpreter(myModuleCombo.getSelectedModule()); } setAnchor(myEnvsComponent.getLabel()); @@ -200,7 +200,7 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm { @Nullable @Override public Module getModule() { - final Module selectedItem = (Module)myModuleCombo.getSelectedItem(); + final Module selectedItem = myModuleCombo.getSelectedModule(); if (selectedItem != null) { return selectedItem; } @@ -213,7 +213,7 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm { @Override public void setModule(Module module) { - myModuleCombo.setSelectedItem(module); + myModuleCombo.setSelectedModule(module); updateDefaultInterpreter(module); } diff --git a/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.form b/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.form index edec809c4952..0332fda9195b 100644 --- a/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.form +++ b/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.form @@ -75,7 +75,7 @@ - + diff --git a/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.java b/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.java index 4a1957e9e631..cf0e440353a4 100644 --- a/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.java +++ b/python/pluginSrc/com/jetbrains/python/run/PyPluginCommonOptionsForm.java @@ -15,7 +15,6 @@ */ package com.jetbrains.python.run; -import com.intellij.application.options.ModuleListCellRenderer; import com.intellij.execution.configuration.EnvironmentVariablesComponent; import com.intellij.execution.util.PathMappingsComponent; import com.intellij.ide.util.PropertiesComponent; @@ -27,6 +26,7 @@ import com.intellij.openapi.projectRoots.impl.SdkListCellRenderer; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; +import com.intellij.application.options.ModulesComboBox; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.io.FileUtil; import com.intellij.ui.CollectionComboBoxModel; @@ -58,7 +58,7 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm { private RawCommandLineEditor myInterpreterOptionsTextField; private JComboBox myInterpreterComboBox; private JRadioButton myUseModuleSdkRadioButton; - private JComboBox myModuleComboBox; + private ModulesComboBox myModuleComboBox; private JPanel myMainPanel; private JRadioButton myUseSpecifiedSdkRadioButton; private JBLabel myPythonInterpreterJBLabel; @@ -77,8 +77,8 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm { final List validModules = data.getValidModules(); Collections.sort(validModules, new ModulesAlphaComparator()); Module selection = validModules.size() > 0 ? validModules.get(0) : null; - myModuleComboBox.setModel(new CollectionComboBoxModel(validModules, selection)); - myModuleComboBox.setRenderer(new ModuleListCellRenderer()); + myModuleComboBox.setModules(validModules); + myModuleComboBox.setSelectedModule(selection); myInterpreterComboBox.setRenderer(new SdkListCellRenderer("")); myWorkingDirectoryTextField.addBrowseFolderListener("Select Working Directory", "", data.getProject(), @@ -181,11 +181,11 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm { } public Module getModule() { - return (Module)myModuleComboBox.getSelectedItem(); + return myModuleComboBox.getSelectedModule(); } public void setModule(Module module) { - myModuleComboBox.setSelectedItem(module); + myModuleComboBox.setSelectedModule(module); } public boolean isUseModuleSdk() {