Merge branch 'master' of git.labs.intellij.net:idea/community
authorkirill.safonov <kirill.safonov@jetbrains.com>
Mon, 30 Jan 2012 15:36:37 +0000 (19:36 +0400)
committerkirill.safonov <kirill.safonov@jetbrains.com>
Mon, 30 Jan 2012 15:36:37 +0000 (19:36 +0400)
java/idea-ui/src/com/intellij/openapi/projectRoots/ui/ProjectJdksEditor.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/JdkComboBox.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectJdksConfigurable.java
platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleJdkOrderEntryImpl.java
platform/platform-resources-en/src/messages/ProjectBundle.properties
platform/platform-resources/src/META-INF/LangExtensionPoints.xml
platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightFixtureTestCase.java
xml/impl/src/com/intellij/xml/util/ColorSampleLookupValue.java

index bb416ccb404748fc2119543a4fd40885a475f193..2739fdea8d4a7cb568e2ff61186b84c30971f291 100644 (file)
@@ -39,8 +39,12 @@ public class ProjectJdksEditor extends DialogWrapper {
 
 
   public ProjectJdksEditor(final Sdk jdk, Project project, Component parent) {
+    this(jdk, parent, new ProjectJdksConfigurable(project));
+  }
+  
+  public ProjectJdksEditor(final Sdk jdk, Component parent, ProjectJdksConfigurable configurable) {
     super(parent, true);
-    myConfigurable = new ProjectJdksConfigurable(project);
+    myConfigurable = configurable;
     SwingUtilities.invokeLater(new Runnable(){
       public void run() {
         myConfigurable.selectNodeInTree(jdk != null ? jdk.getName() : null);
index d06839e6df6c9de1b6a186690003c661a8eec615..97807b9292df2a62d2deaea78ccff1d948e8b877 100644 (file)
@@ -46,7 +46,7 @@ import java.util.Comparator;
  * @author Eugene Zhuravlev
  * @since May 18, 2005
  */
-class JdkComboBox extends ComboBoxWithWidePopup {
+public class JdkComboBox extends ComboBoxWithWidePopup {
 
   public JdkComboBox(@NotNull final ProjectSdksModel jdkModel) {
     super(new JdkComboBoxModel(jdkModel));
@@ -105,6 +105,16 @@ class JdkComboBox extends ComboBoxWithWidePopup {
                                 final JdkComboBoxItem firstItem,
                                 @Nullable final Condition<Sdk> additionalSetup,
                                 final boolean moduleJdkSetup) {
+    setSetupButton(setUpButton, project, jdksModel, firstItem, additionalSetup,
+                   ProjectBundle.message("project.roots.set.up.jdk.title", moduleJdkSetup ? 1 : 2));
+  }
+
+  public void setSetupButton(final JButton setUpButton,
+                                final Project project,
+                                final ProjectSdksModel jdksModel,
+                                final JdkComboBoxItem firstItem,
+                                @Nullable final Condition<Sdk> additionalSetup,
+                                final String actionGroupTitle) {
     setUpButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
         final JdkListConfigurable configurable = JdkListConfigurable.getInstance(project);
@@ -122,7 +132,7 @@ class JdkComboBox extends ComboBoxWithWidePopup {
           }
         });
         JBPopupFactory.getInstance()
-          .createActionGroupPopup(ProjectBundle.message("project.roots.set.up.jdk.title", moduleJdkSetup ? 1 : 2), group,
+          .createActionGroupPopup(actionGroupTitle, group,
                                   DataManager.getInstance().getDataContext(JdkComboBox.this), JBPopupFactory.ActionSelectionAid.MNEMONICS,
                                   false)
           .showUnderneathOf(setUpButton);
@@ -253,6 +263,11 @@ class JdkComboBox extends ComboBoxWithWidePopup {
       return myJdk;
     }
 
+    @Nullable
+    public String getSdkName() {
+      return myJdk != null ? myJdk.getName() : null;
+    }
+    
     public String toString() {
       return myJdk.getName();
     }
@@ -279,15 +294,19 @@ class JdkComboBox extends ComboBoxWithWidePopup {
   }
 
   private static class InvalidJdkComboBoxItem extends JdkComboBoxItem {
-    private final String myName;
+    private final String mySdkName;
 
     public InvalidJdkComboBoxItem(String name) {
       super(null);
-      myName = ProjectBundle.message("jdk.combo.box.invalid.item", name);
+      mySdkName = name;
+    }
+
+    public String getSdkName() {
+      return mySdkName;
     }
 
     public String toString() {
-      return myName;
+      return ProjectBundle.message("jdk.combo.box.invalid.item", mySdkName);
     }
   }
 }
index 456a15a004ea43337fbf164234bdc60fd7439c95..ac6d5cd9ca80f09324f82166c7c8a69207092aeb 100644 (file)
@@ -57,13 +57,16 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent {
 
   private final ProjectSdksModel myProjectJdksModel;
   private final Project myProject;
-  @NonNls 
+  @NonNls
   private static final String SPLITTER_PROPORTION = "project.jdk.splitter";
 
   public ProjectJdksConfigurable(Project project) {
-    super();
+    this(project, ProjectStructureConfigurable.getInstance(project).getProjectJdksModel());
+  }
+
+  public ProjectJdksConfigurable(Project project, ProjectSdksModel sdksModel) {
     myProject = project;
-    myProjectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
+    myProjectJdksModel = sdksModel;
     initTree();
   }
 
index b923084c275d554e4804199a4f18d048880f395b..c90b321c1e3dff2a6a40631025bc4b2f0953c840 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.intellij.openapi.roots.impl;
 
+import com.intellij.openapi.extensions.ExtensionPointName;
 import com.intellij.openapi.projectRoots.ProjectJdkTable;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.roots.ModuleJdkOrderEntry;
@@ -29,6 +30,7 @@ import org.jdom.Attribute;
 import org.jdom.Element;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * @author dsl
@@ -62,8 +64,7 @@ public class ModuleJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl implement
 
     final String jdkName = jdkNameAttribute.getValue();
     final String jdkType = element.getAttributeValue(JDK_TYPE_ATTR);
-    final ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
-    final Sdk jdkByName = projectJdkTable.findJdk(jdkName, jdkType);
+    final Sdk jdkByName = findJdk(jdkName, jdkType);
     if (jdkByName == null) {
       init(null, jdkName, jdkType);
     }
@@ -72,6 +73,26 @@ public class ModuleJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl implement
     }
   }
 
+  public abstract static class SdkFinder {
+    private static final ExtensionPointName<SdkFinder> EP_NAME = ExtensionPointName.create("com.intellij.sdkFinder");
+
+    @Nullable
+    public Sdk findSdk(String name, String sdkType) {
+      return null;
+    }
+  }
+
+  @Nullable
+  private static Sdk findJdk(final String jdkName, final String jdkType) {
+    for (SdkFinder sdkFinder : SdkFinder.EP_NAME.getExtensions()) {
+      final Sdk sdk = sdkFinder.findSdk(jdkName, jdkType);
+      if (sdk != null) {
+        return sdk;
+      }
+    }
+    final ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
+    return projectJdkTable.findJdk(jdkName, jdkType);
+  }
 
 
   private ModuleJdkOrderEntryImpl(ModuleJdkOrderEntryImpl that, RootModelImpl rootModel, ProjectRootManagerImpl projectRootManager) {
index c25a731432336a91f64f8c5a1cac7d258030f265..466de59f09d3037c0efd84098efe3daee064e25b 100644 (file)
@@ -295,7 +295,7 @@ module.library.display.name=Module {0, choice, 1#Library|2#Libraries}
 project.roots.library.banner.text= {1} ''{0}''
 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.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.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. \
index cca38e9c553b38353d7d91a1df1734d3251ccc00..044b1b5cac10f74d9864d14edd86ad407da8b79f 100644 (file)
   <extensionPoint name="library.presentationProvider" interface="com.intellij.openapi.roots.libraries.LibraryPresentationProvider"/>
   <extensionPoint name="library.type" interface="com.intellij.openapi.roots.libraries.LibraryType"/>
 
+  <extensionPoint name="sdkFinder" interface="com.intellij.openapi.roots.impl.ModuleJdkOrderEntryImpl$SdkFinder"/>
+
   <extensionPoint name="lang.implementationTextSelectioner"
                   beanClass="com.intellij.lang.LanguageExtensionPoint"/>
   <extensionPoint name="lang.lineWrapStrategy"
index 45ca8249e70dadf520a5a53546b4ca425ef1115b..d4e56c07982ae8da3daa5105ff6e776de0b08683 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.psi.PsiFile;
 import com.intellij.testFramework.UsefulTestCase;
 import com.intellij.testFramework.builders.EmptyModuleFixtureBuilder;
+import com.intellij.testFramework.builders.ModuleFixtureBuilder;
 import org.jetbrains.annotations.NonNls;
 
 import java.io.File;
@@ -29,7 +30,7 @@ import java.io.File;
 /**
  * @author yole
  */
-public abstract class CodeInsightFixtureTestCase extends UsefulTestCase {
+public abstract class CodeInsightFixtureTestCase<T extends ModuleFixtureBuilder> extends UsefulTestCase {
   protected CodeInsightTestFixture myFixture;
   protected Module myModule;
 
@@ -39,7 +40,7 @@ public abstract class CodeInsightFixtureTestCase extends UsefulTestCase {
 
     final TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder();
     myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
-    final EmptyModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(EmptyModuleFixtureBuilder.class);
+    final T moduleFixtureBuilder = projectBuilder.addModule(getModuleBuilderClass());
     moduleFixtureBuilder.addSourceContentRoot(myFixture.getTempDirPath());
     tuneFixture(moduleFixtureBuilder);
 
@@ -48,6 +49,10 @@ public abstract class CodeInsightFixtureTestCase extends UsefulTestCase {
     myModule = moduleFixtureBuilder.getFixture().getModule();
   }
 
+  protected Class<T> getModuleBuilderClass() {
+    return (Class<T>)EmptyModuleFixtureBuilder.class;
+  }
+  
   @Override
   protected void tearDown() throws Exception {
     myFixture.tearDown();
@@ -56,7 +61,7 @@ public abstract class CodeInsightFixtureTestCase extends UsefulTestCase {
     super.tearDown();
   }
 
-  protected void tuneFixture(final EmptyModuleFixtureBuilder moduleBuilder) {}
+  protected void tuneFixture(final T moduleBuilder) {}
 
   /**
    * Return relative path to the test data. Path is relative to the
index bf21f20bb868d961b6c228dee23624cc9e7f7b63..916c3fcaf3d55740e265caf395596500192e8846 100644 (file)
@@ -323,48 +323,51 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs
 
   public static ColorSampleLookupValue[] getColors() {
     if (ourColors == null) {
-      ourColorNameToHexCodeMap = new HashMap<String, String>(25);
-      ourHexCodeToColorNameMap = new HashMap<String, String>(25);
-      List<ColorSampleLookupValue> colorsList = new LinkedList<ColorSampleLookupValue>();
-      StringTokenizer tokenizer = new StringTokenizer(systemColorsString, "\n");
-
-      while (tokenizer.hasMoreTokens()) {
-        String name = tokenizer.nextToken();
-        colorsList.add(new ColorSampleLookupValue(name, name, false));
-        tokenizer.nextToken();
-      }
-
-      tokenizer = new StringTokenizer(standardColorsString, ", \n");
-      HashMap<String, String> standardColors = new HashMap<String, String>();
-
-      while (tokenizer.hasMoreTokens()) {
-        String name = tokenizer.nextToken();
-        String value = tokenizer.nextToken();
-        standardColors.put(name, name);
-        ourColorNameToHexCodeMap.put(name, value);
-        ourHexCodeToColorNameMap.put(value, name);
-
-        colorsList.add(new ColorSampleLookupValue(name, value, true));
-      }
-
-      tokenizer = new StringTokenizer(colorsString, " \t\n");
-
-      while (tokenizer.hasMoreTokens()) {
-        String name = tokenizer.nextToken();
-        String hexValue = tokenizer.nextToken();
-
-        tokenizer.nextToken(); // skip rgb
-
-        if (!standardColors.containsKey(name)) {
-          colorsList.add(new ColorSampleLookupValue(name, hexValue, false));
-          ourColorNameToHexCodeMap.put(name, hexValue);
-          ourHexCodeToColorNameMap.put(hexValue, name);
+      synchronized (ColorSampleLookupValue.class) {
+        if (ourColors == null) {
+          ourColorNameToHexCodeMap = new HashMap<String, String>(25);
+          ourHexCodeToColorNameMap = new HashMap<String, String>(25);
+          List<ColorSampleLookupValue> colorsList = new LinkedList<ColorSampleLookupValue>();
+          StringTokenizer tokenizer = new StringTokenizer(systemColorsString, "\n");
+
+          while (tokenizer.hasMoreTokens()) {
+            String name = tokenizer.nextToken();
+            colorsList.add(new ColorSampleLookupValue(name, name, false));
+            tokenizer.nextToken();
+          }
+
+          tokenizer = new StringTokenizer(standardColorsString, ", \n");
+          HashMap<String, String> standardColors = new HashMap<String, String>();
+
+          while (tokenizer.hasMoreTokens()) {
+            String name = tokenizer.nextToken();
+            String value = tokenizer.nextToken();
+            standardColors.put(name, name);
+            ourColorNameToHexCodeMap.put(name, value);
+            ourHexCodeToColorNameMap.put(value, name);
+
+            colorsList.add(new ColorSampleLookupValue(name, value, true));
+          }
+
+          tokenizer = new StringTokenizer(colorsString, " \t\n");
+
+          while (tokenizer.hasMoreTokens()) {
+            String name = tokenizer.nextToken();
+            String hexValue = tokenizer.nextToken();
+
+            tokenizer.nextToken(); // skip rgb
+
+            if (!standardColors.containsKey(name)) {
+              colorsList.add(new ColorSampleLookupValue(name, hexValue, false));
+              ourColorNameToHexCodeMap.put(name, hexValue);
+              ourHexCodeToColorNameMap.put(hexValue, name);
+            }
+          }
+
+          colorsList.toArray(ourColors = new ColorSampleLookupValue[colorsList.size()]);
         }
       }
-
-      colorsList.toArray(ourColors = new ColorSampleLookupValue[colorsList.size()]);
     }
-
     return ourColors;
   }
 
@@ -389,12 +392,12 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs
     return myName == null || Character.isLowerCase(myName.charAt(0)) ? HIGHER : NORMAL;
   }
 
-  public static String getHexCodeForColorName(String colorName) {
+  public static synchronized String getHexCodeForColorName(String colorName) {
     getColors(); // to guarantee initialization
     return ourColorNameToHexCodeMap.get(colorName);
   }
 
-  public static String getColorNameForHexCode(String colorName) {
+  public static synchronized String getColorNameForHexCode(String colorName) {
     getColors(); // to guarantee initialization
     return ourHexCodeToColorNameMap.get(colorName);
   }