SDK combobox - better API for 'New' and 'Edit' buttons
authorkirill.safonov <kirill.safonov@jetbrains.com>
Thu, 12 Jan 2012 12:27:17 +0000 (16:27 +0400)
committerkirill.safonov <kirill.safonov@jetbrains.com>
Mon, 30 Jan 2012 14:46:59 +0000 (18:46 +0400)
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/JdkComboBox.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleJdkConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdkConfigurable.java
platform/platform-resources-en/src/messages/ApplicationBundle.properties
platform/platform-resources-en/src/messages/ProjectBundle.properties

index e70b585dac5bf7b6feb17e8d6476e8a971528f3e..d06839e6df6c9de1b6a186690003c661a8eec615 100644 (file)
@@ -18,7 +18,6 @@ package com.intellij.openapi.roots.ui.configuration;
 import com.intellij.ide.DataManager;
 import com.intellij.ide.util.projectWizard.ProjectJdkListRenderer;
 import com.intellij.openapi.actionSystem.DefaultActionGroup;
-import com.intellij.openapi.application.ApplicationBundle;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.projectRoots.Sdk;
@@ -48,7 +47,6 @@ import java.util.Comparator;
  * @since May 18, 2005
  */
 class JdkComboBox extends ComboBoxWithWidePopup {
-  private final JButton myEditButton = new JButton(ApplicationBundle.message("button.edit"));
 
   public JdkComboBox(@NotNull final ProjectSdksModel jdkModel) {
     super(new JdkComboBoxModel(jdkModel));
@@ -101,17 +99,12 @@ class JdkComboBox extends ComboBoxWithWidePopup {
     return minSize;
   }
 
-  public JButton createSetupButton(final Project project, final ProjectSdksModel jdksModel, final JdkComboBoxItem firstItem) {
-    return createSetupButton(project, jdksModel, firstItem, null, false);
-  }
-
-
-  public JButton createSetupButton(final Project project,
-                                   final ProjectSdksModel jdksModel,
-                                   final JdkComboBoxItem firstItem,
-                                   @Nullable final Condition<Sdk> additionalSetup,
-                                   final boolean moduleJdkSetup) {
-    final JButton setUpButton = new JButton(ApplicationBundle.message("button.new"));
+  public void setSetupButton(final JButton setUpButton,
+                                final Project project,
+                                final ProjectSdksModel jdksModel,
+                                final JdkComboBoxItem firstItem,
+                                @Nullable final Condition<Sdk> additionalSetup,
+                                final boolean moduleJdkSetup) {
     setUpButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
         final JdkListConfigurable configurable = JdkListConfigurable.getInstance(project);
@@ -130,15 +123,15 @@ class JdkComboBox extends ComboBoxWithWidePopup {
         });
         JBPopupFactory.getInstance()
           .createActionGroupPopup(ProjectBundle.message("project.roots.set.up.jdk.title", moduleJdkSetup ? 1 : 2), group,
-                                  DataManager.getInstance().getDataContext(JdkComboBox.this), JBPopupFactory.ActionSelectionAid.MNEMONICS, false)
+                                  DataManager.getInstance().getDataContext(JdkComboBox.this), JBPopupFactory.ActionSelectionAid.MNEMONICS,
+                                  false)
           .showUnderneathOf(setUpButton);
       }
     });
-    return setUpButton;
   }
 
-  public void appendEditButton(final Project project, final JPanel panel, GridBagConstraints gc, final Computable<Sdk> retrieveJDK){
-    myEditButton.addActionListener(new ActionListener() {
+  public void setEditButton(final JButton editButton, final Project project, final Computable<Sdk> retrieveJDK){
+    editButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
         final Sdk projectJdk = retrieveJDK.compute();
         if (projectJdk != null) {
@@ -146,17 +139,17 @@ class JdkComboBox extends ComboBoxWithWidePopup {
         }
       }
     });
-    addActionListener(new ActionListener(){
+    addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
         final JdkComboBoxItem selectedItem = getSelectedItem();
         if (selectedItem instanceof ProjectJdkComboBoxItem) {
-          myEditButton.setEnabled(ProjectStructureConfigurable.getInstance(project).getProjectJdksModel().getProjectSdk() != null);
-        } else {
-          myEditButton.setEnabled(!(selectedItem instanceof InvalidJdkComboBoxItem) && selectedItem != null && selectedItem.getJdk() != null);
+          editButton.setEnabled(ProjectStructureConfigurable.getInstance(project).getProjectJdksModel().getProjectSdk() != null);
+        }
+        else {
+          editButton.setEnabled(!(selectedItem instanceof InvalidJdkComboBoxItem) && selectedItem != null && selectedItem.getJdk() != null);
         }
       }
     });
-    panel.add(myEditButton, gc);
   }
 
   public JdkComboBoxItem getSelectedItem() {
index 718f923efcea41898c1a2910c603a4261faaa2af..3dd421d20568b150cadee48acdcd7386618b7876 100644 (file)
@@ -17,6 +17,7 @@
 package com.intellij.openapi.roots.ui.configuration;
 
 import com.intellij.openapi.Disposable;
+import com.intellij.openapi.application.ApplicationBundle;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
@@ -119,17 +120,18 @@ public abstract class ModuleJdkConfigurable implements Disposable {
                                                          GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                                                          new Insets(6, 6, 12, 0), 0, 0));
     final Project project = getRootModel().getModule().getProject();
-    final JButton setUpButton = myCbModuleJdk
-      .createSetupButton(project, myJdksModel, new JdkComboBox.ProjectJdkComboBoxItem(), new Condition<Sdk>(){
+    final JButton setUpButton = new JButton(ApplicationBundle.message("button.new"));
+    myCbModuleJdk
+      .setSetupButton(setUpButton, project, myJdksModel, new JdkComboBox.ProjectJdkComboBoxItem(), new Condition<Sdk>() {
         public boolean value(Sdk jdk) {
           final Sdk projectJdk = myJdksModel.getProjectSdk();
-          if (projectJdk == null){
+          if (projectJdk == null) {
             final int res =
               Messages.showYesNoDialog(myJdkPanel,
                                        ProjectBundle.message("project.roots.no.jdk.on.project.message"),
-                                       ProjectBundle.message("project.roots.no.jdk.on.projecct.title"),
+                                       ProjectBundle.message("project.roots.no.jdk.on.project.title"),
                                        Messages.getInformationIcon());
-            if (res == DialogWrapper.OK_EXIT_CODE){
+            if (res == DialogWrapper.OK_EXIT_CODE) {
               myJdksModel.setProjectSdk(jdk);
               return true;
             }
@@ -140,12 +142,16 @@ public abstract 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(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>() {
+    final JButton editButton = new JButton(ApplicationBundle.message("button.edit"));
+    myCbModuleJdk.setEditButton(editButton, getRootModel().getModule().getProject(), new Computable<Sdk>() {
       @Nullable
       public Sdk compute() {
         return getRootModel().getSdk();
       }
     });
+    myJdkPanel.add(editButton,
+                   new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 1.0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
+                                          new Insets(0, 4, 7, 0), 0, 0));
   }
 
   private void clearCaches() {
index 54a36d3c569f6d58359aee78a02e3635c33ef075..ade16cb422a535e9588d20f463e21c75e9ed56cf 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.intellij.openapi.roots.ui.configuration;
 
+import com.intellij.openapi.application.ApplicationBundle;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.options.UnnamedConfigurable;
 import com.intellij.openapi.project.Project;
@@ -90,14 +91,19 @@ public class ProjectJdkConfigurable implements UnnamedConfigurable {
       });
       myJdkPanel.add(new JLabel(ProjectBundle.message("module.libraries.target.jdk.project.radio")), new GridBagConstraints(0, 0, 3, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 4, 0), 0, 0));
       myJdkPanel.add(myCbProjectJdk, new GridBagConstraints(0, 1, 1, 1, 0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0));
-      final JButton setUpButton = myCbProjectJdk.createSetupButton(myProject, myJdksModel, new JdkComboBox.NoneJdkComboBoxItem());
+      final JButton setUpButton = new JButton(ApplicationBundle.message("button.new"));
+      myCbProjectJdk.setSetupButton(setUpButton, myProject, myJdksModel, new JdkComboBox.NoneJdkComboBoxItem(), null, false);
       myJdkPanel.add(setUpButton, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0));
-      myCbProjectJdk.appendEditButton(myProject, myJdkPanel, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0), new Computable<Sdk>() {
+      final JButton editButton = new JButton(ApplicationBundle.message("button.edit"));
+      myCbProjectJdk.setEditButton(editButton, myProject, new Computable<Sdk>() {
         @Nullable
         public Sdk compute() {
           return myJdksModel.getProjectSdk();
         }
       });
+
+      myJdkPanel.add(editButton, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0, GridBagConstraints.NORTHWEST,
+                                                            GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0));
     }
     return myJdkPanel;
   }
index 8b853b5fa2d225cc742589fda6880e23e40ec2f7..d6dd203561832d2ace489e55bbad4c3dc36595d3 100644 (file)
@@ -528,7 +528,7 @@ exclude.from.imports.no.exclusions=No exclude patterns
 inline.elements=Inline elements:
 don.t.break.if.inline.content=Don't break if inline content:
 edit.code.folding.options=Open code folding options
-button.new=&New
+button.new=&New...
 building.include.indices=Building include indices...
 loading.include.indices=Loading include indices...
 use.external.annotations=Use &external annotations
index 694fc07924eaadd186d5da2e1b75dc0b2a691ad3..c25a731432336a91f64f8c5a1cac7d258030f265 100644 (file)
@@ -297,7 +297,7 @@ facet.banner.text=Facet ''{0}''
 project.roots.project.banner.text=General Settings for Project ''{0}''
 project.roots.set.up.jdk.title=Set up {0, choice, 1#module|2#project} SDK
 project.roots.no.jdk.on.project.message=Set up created sdk on project?
-project.roots.no.jdk.on.projecct.title=No project sdk set up
+project.roots.no.jdk.on.project.title=Create SDK
 project.roots.jdks.node.text=JDK stands for the Java Development Kit, a software development package that is required to write, test and debug Java applications. \
   JDK also contains classes and runtime environment that are used to execute the target application. <br><br>\
   Mobile SDK contains emulator of mobile phone as well as embedded Java SDK to compile/pack/run/debug J2ME applications. <br><br>\