Java 类com.intellij.openapi.projectRoots.SdkType 实例源码

项目:educational-plugin    文件:EduIntellijCourseProjectGeneratorBase.java   
protected void setJdk(@NotNull Project project) {
  JdkComboBox.JdkComboBoxItem selectedItem = myJdkComboBox.getSelectedItem();
  if (selectedItem instanceof JdkComboBox.SuggestedJdkItem) {
    SdkType type = ((JdkComboBox.SuggestedJdkItem)selectedItem).getSdkType();
    String path = ((JdkComboBox.SuggestedJdkItem)selectedItem).getPath();
    myModel.addSdk(type, path, sdk -> {
      myJdkComboBox.reloadModel(new JdkComboBox.ActualJdkComboBoxItem(sdk), project);
      myJdkComboBox.setSelectedJdk(sdk);
    });
  }
  try {
    myModel.apply();
  } catch (ConfigurationException e) {
    LOG.error(e);
  }
  ApplicationManager.getApplication().runWriteAction(() -> {
    ProjectRootManager.getInstance(project).setProjectSdk(myJdkComboBox.getSelectedJdk());
  });
}
项目:intellij-ce-playground    文件:JdkChooserPanel.java   
public void fillList(final @Nullable SdkType type, final @Nullable Sdk[] globalSdks) {
  myListModel.clear();
  final Sdk[] jdks;
  if (myProject == null || myProject.isDefault()) {
    final Sdk[] allJdks = globalSdks != null ? globalSdks : ProjectJdkTable.getInstance().getAllJdks();
    jdks = getCompatibleJdks(type, Arrays.asList(allJdks));
  }
  else {
    final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel();
    if (!projectJdksModel.isInitialized()){ //should be initialized
      projectJdksModel.reset(myProject);
    }
    final Collection<Sdk> collection = projectJdksModel.getProjectSdks().values();
    jdks = getCompatibleJdks(type, collection);
  }
  Arrays.sort(jdks, new Comparator<Sdk>() {
    public int compare(final Sdk o1, final Sdk o2) {
      return o1.getName().compareToIgnoreCase(o2.getName());
    }
  });
  for (Sdk jdk : jdks) {
    myListModel.addElement(jdk);
  }
}
项目:intellij-ce-playground    文件:DependentSdkType.java   
protected static Sdk createSdkOfType(final SdkModel sdkModel,
                                final SdkType sdkType,
                                final Consumer<Sdk> sdkCreatedCallback) {
  final Ref<Sdk> result = new Ref<Sdk>(null);
  SdkConfigurationUtil.selectSdkHome(sdkType, new Consumer<String>() {
    @Override
    public void consume(final String home) {
      String newSdkName = SdkConfigurationUtil.createUniqueSdkName(sdkType, home, Arrays.asList(sdkModel.getSdks()));
      final ProjectJdkImpl newJdk = new ProjectJdkImpl(newSdkName, sdkType);
      newJdk.setHomePath(home);

      sdkCreatedCallback.consume(newJdk);
      result.set(newJdk);
    }
  });
  return result.get();
}
项目:intellij-ce-playground    文件:SdkConfigurationUtil.java   
private static FileChooserDescriptor createCompositeDescriptor(final SdkType... sdkTypes) {
  return new FileChooserDescriptor(sdkTypes[0].getHomeChooserDescriptor()) {
    @Override
    public void validateSelectedFiles(final VirtualFile[] files) throws Exception {
      if (files.length > 0) {
        for (SdkType type : sdkTypes) {
          if (type.isValidSdkHome(files[0].getPath())) {
            return;
          }
        }
      }
      String key = files.length > 0 && files[0].isDirectory() ? "sdk.configure.home.invalid.error" : "sdk.configure.home.file.invalid.error";
      throw new Exception(ProjectBundle.message(key, sdkTypes[0].getPresentableName()));
    }
  };
}
项目:intellij-ce-playground    文件:SdkConfigurationUtil.java   
/**
 * Tries to create an SDK identified by path; if successful, add the SDK to the global SDK table.
 *
 * @param path    identifies the SDK
 * @param sdkType
 * @return newly created SDK, or null.
 */
@Nullable
public static Sdk createAndAddSDK(final String path, SdkType sdkType) {
  VirtualFile sdkHome = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
    @Override
    public VirtualFile compute() {
      return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    }
  });
  if (sdkHome != null) {
    final Sdk newSdk = setupSdk(ProjectJdkTable.getInstance().getAllJdks(), sdkHome, sdkType, true, null, null);
    if (newSdk != null) {
      addSdk(newSdk);
    }
    return newSdk;
  }
  return null;
}
项目:intellij-ce-playground    文件:SdkConfigurationUtil.java   
public static void selectSdkHome(@NotNull final SdkType sdkType, @NotNull final Consumer<String> consumer) {
  final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    Sdk sdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(sdkType);
    if (sdk == null) throw new RuntimeException("No SDK of type " + sdkType + " found");
    consumer.consume(sdk.getHomePath());
    return;
  }
  FileChooser.chooseFiles(descriptor, null, getSuggestedSdkRoot(sdkType), new Consumer<List<VirtualFile>>() {
    @Override
    public void consume(final List<VirtualFile> chosen) {
      final String path = chosen.get(0).getPath();
      if (sdkType.isValidSdkHome(path)) {
        consumer.consume(path);
        return;
      }

      final String adjustedPath = sdkType.adjustSelectedSdkHome(path);
      if (sdkType.isValidSdkHome(adjustedPath)) {
        consumer.consume(adjustedPath);
      }
    }
  });
}
项目:tools-idea    文件:JdkChooserPanel.java   
public void fillList(final @Nullable SdkType type, final @Nullable Sdk[] globalSdks) {
  myListModel.clear();
  final Sdk[] jdks;
  if (myProject == null || myProject.isDefault()) {
    final Sdk[] allJdks = globalSdks != null ? globalSdks : ProjectJdkTable.getInstance().getAllJdks();
    jdks = getCompatibleJdks(type, Arrays.asList(allJdks));
  }
  else {
    final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel();
    if (!projectJdksModel.isInitialized()){ //should be initialized
      projectJdksModel.reset(myProject);
    }
    final Collection<Sdk> collection = projectJdksModel.getProjectSdks().values();
    jdks = getCompatibleJdks(type, collection);
  }
  Arrays.sort(jdks, new Comparator<Sdk>() {
    public int compare(final Sdk o1, final Sdk o2) {
      return o1.getName().compareToIgnoreCase(o2.getName());
    }
  });
  for (Sdk jdk : jdks) {
    myListModel.addElement(jdk);
  }
}
项目:tools-idea    文件:DependentSdkType.java   
protected static Sdk createSdkOfType(final SdkModel sdkModel,
                                final SdkType sdkType,
                                final Consumer<Sdk> sdkCreatedCallback) {
  final Ref<Sdk> result = new Ref<Sdk>(null);
  SdkConfigurationUtil.selectSdkHome(sdkType, new Consumer<String>() {
    @Override
    public void consume(final String home) {
      String newSdkName = SdkConfigurationUtil.createUniqueSdkName(sdkType, home, Arrays.asList(sdkModel.getSdks()));
      final ProjectJdkImpl newJdk = new ProjectJdkImpl(newSdkName, sdkType);
      newJdk.setHomePath(home);

      sdkCreatedCallback.consume(newJdk);
      result.set(newJdk);
    }
  });
  return result.get();
}
项目:tools-idea    文件:SdkConfigurationUtil.java   
private static FileChooserDescriptor createCompositeDescriptor(final SdkType... sdkTypes) {
  FileChooserDescriptor descriptor0 = sdkTypes[0].getHomeChooserDescriptor();
  FileChooserDescriptor descriptor = new FileChooserDescriptor(descriptor0.isChooseFiles(), descriptor0.isChooseFolders(),
                                                               descriptor0.isChooseJars(), descriptor0.isChooseJarsAsFiles(),
                                                               descriptor0.isChooseJarContents(), descriptor0.isChooseMultiple()) {

    @Override
    public void validateSelectedFiles(final VirtualFile[] files) throws Exception {
      if (files.length > 0) {
        for (SdkType type : sdkTypes) {
          if (type.isValidSdkHome(files[0].getPath())) {
            return;
          }
        }
      }
      String message = files.length > 0 && files[0].isDirectory()
                       ? ProjectBundle.message("sdk.configure.home.invalid.error", sdkTypes[0].getPresentableName())
                       : ProjectBundle.message("sdk.configure.home.file.invalid.error", sdkTypes[0].getPresentableName());
      throw new Exception(message);
    }
  };
  descriptor.setTitle(descriptor0.getTitle());
  return descriptor;
}
项目:tools-idea    文件:SdkConfigurationUtil.java   
/**
 * Tries to create an SDK identified by path; if successful, add the SDK to the global SDK table.
 *
 * @param path    identifies the SDK
 * @param sdkType
 * @return newly created SDK, or null.
 */
@Nullable
public static Sdk createAndAddSDK(final String path, SdkType sdkType) {
  VirtualFile sdkHome = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
    @Override
    public VirtualFile compute() {
      return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    }
  });
  if (sdkHome != null) {
    final Sdk newSdk = setupSdk(ProjectJdkTable.getInstance().getAllJdks(), sdkHome, sdkType, true, null, null);
    if (newSdk != null) {
      addSdk(newSdk);
    }
    return newSdk;
  }
  return null;
}
项目:tools-idea    文件:SdkConfigurationUtil.java   
public static void selectSdkHome(final SdkType sdkType, @NotNull final Consumer<String> consumer) {
  final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    Sdk sdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(sdkType);
    if (sdk == null) throw new RuntimeException("No SDK of type " + sdkType + " found");
    consumer.consume(sdk.getHomePath());
    return;
  }
  FileChooser.chooseFiles(descriptor, null, getSuggestedSdkRoot(sdkType), new Consumer<List<VirtualFile>>() {
    @Override
    public void consume(final List<VirtualFile> chosen) {
      final String path = chosen.get(0).getPath();
      if (sdkType.isValidSdkHome(path)) {
        consumer.consume(path);
        return;
      }

      final String adjustedPath = sdkType.adjustSelectedSdkHome(path);
      if (sdkType.isValidSdkHome(adjustedPath)) {
        consumer.consume(adjustedPath);
      }
    }
  });
}
项目:tools-idea    文件:PluginModuleCompilationTest.java   
@Override
protected void setUpJdk() {
  super.setUpJdk();
  new WriteAction() {
    protected void run(final Result result) {
      ProjectJdkTable table = ProjectJdkTable.getInstance();
      myPluginSdk = table.createSdk("IDEA plugin SDK", SdkType.findInstance(IdeaJdk.class));
      SdkModificator modificator = myPluginSdk.getSdkModificator();
      modificator.setSdkAdditionalData(new Sandbox(getSandboxPath(), getTestProjectJdk(), myPluginSdk));
      String rootPath = FileUtil.toSystemIndependentName(PathManager.getJarPathForClass(FileUtilRt.class));
      modificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByPath(rootPath), OrderRootType.CLASSES);
      modificator.commitChanges();
      table.addJdk(myPluginSdk);
    }
  }.execute();
}
项目:consulo    文件:SdkConfigurationUtil.java   
private static FileChooserDescriptor createCompositeDescriptor(final SdkType... sdkTypes) {
  FileChooserDescriptor descriptor0 = sdkTypes[0].getHomeChooserDescriptor();
  FileChooserDescriptor descriptor =
    new FileChooserDescriptor(descriptor0.isChooseFiles(), descriptor0.isChooseFolders(), descriptor0.isChooseJars(),
                              descriptor0.isChooseJarsAsFiles(), descriptor0.isChooseJarContents(), descriptor0.isChooseMultiple()) {

      @Override
      public void validateSelectedFiles(final VirtualFile[] files) throws Exception {
        if (files.length > 0) {
          for (SdkType type : sdkTypes) {
            if (type.isValidSdkHome(files[0].getPath())) {
              return;
            }
          }
        }
        String message = files.length > 0 && files[0].isDirectory()
                         ? ProjectBundle.message("sdk.configure.home.invalid.error", sdkTypes[0].getPresentableName())
                         : ProjectBundle.message("sdk.configure.home.file.invalid.error", sdkTypes[0].getPresentableName());
        throw new Exception(message);
      }
    };
  descriptor.setTitle(descriptor0.getTitle());
  return descriptor;
}
项目:consulo    文件:SdkConfigurationUtil.java   
/**
 * Tries to create an SDK identified by path; if successful, add the SDK to the global SDK table.
 *
 * @param path    identifies the SDK
 * @param sdkType
 * @param predefined
 * @return newly created SDK, or null.
 */
@Nullable
public static Sdk createAndAddSDK(final String path, SdkType sdkType, boolean predefined) {
  VirtualFile sdkHome = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
    @Override
    public VirtualFile compute() {
      return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    }
  });
  if (sdkHome != null) {
    final Sdk newSdk = setupSdk(SdkTable.getInstance().getAllSdks(), sdkHome, sdkType, true, predefined, null, null);
    if (newSdk != null) {
      addSdk(newSdk);
    }
    return newSdk;
  }
  return null;
}
项目:consulo    文件:SdkConfigurationUtil.java   
public static void selectSdkHome(final SdkType sdkType, @Nonnull final Consumer<String> consumer) {
  final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    Sdk sdk = SdkTable.getInstance().findMostRecentSdkOfType(sdkType);
    if (sdk == null) throw new RuntimeException("No SDK of type " + sdkType + " found");
    consumer.consume(sdk.getHomePath());
    return;
  }
  FileChooser.chooseFiles(descriptor, null, getSuggestedSdkPath(sdkType), new Consumer<List<VirtualFile>>() {
    @Override
    public void consume(final List<VirtualFile> chosen) {
      final String path = chosen.get(0).getPath();
      if (sdkType.isValidSdkHome(path)) {
        consumer.consume(path);
        return;
      }

      final String adjustedPath = sdkType.adjustSelectedSdkHome(path);
      if (sdkType.isValidSdkHome(adjustedPath)) {
        consumer.consume(adjustedPath);
      }
    }
  });
}
项目:consulo    文件:SdkListConfigurable.java   
public boolean addSdkNode(final Sdk sdk, final boolean selectInTree) {
  if (!myUiDisposed) {
    myContext.getDaemonAnalyzer().queueUpdate(new SdkProjectStructureElement(myContext, sdk));

    MyNode newSdkNode = new MyNode(new SdkConfigurable((SdkImpl)sdk, mySdksTreeModel, TREE_UPDATER, myHistory, myProject));

    final MyNode groupNode = MasterDetailsComponent.findNodeByObject(myRoot, sdk.getSdkType());
    if (groupNode != null) {
      addNode(newSdkNode, groupNode);
    }
    else {
      final MyNode sdkGroupNode = createSdkGroupNode((SdkType)sdk.getSdkType());

      addNode(sdkGroupNode, myRoot);
      addNode(newSdkNode, sdkGroupNode);
    }

    if (selectInTree) {
      selectNodeInTree(newSdkNode);
    }
    return true;
  }
  return false;
}
项目:lua-for-idea    文件:LuaSdkChooserPanel.java   
public LuaSdkChooserPanel(final Project project) {
    myJdkChooser = new JdkChooserPanel(project);

    setLayout(new GridBagLayout());
    setBorder(BorderFactory.createEtchedBorder());

    final JLabel label = new JLabel(LuaBundle.message("sdk.chooser.luabinaries.prompt"));
    label.setUI(new MultiLineLabelUI());
    add(label, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL, new Insets(8, 10, 8, 10), 0, 0));

    final JLabel jdkLabel = new JLabel(LuaBundle.message("sdk.chooser.select.sdk.prompt"));
    jdkLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    add(jdkLabel,
            new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.NONE, new Insets(8, 10, 0, 10), 0, 0));

    add(myJdkChooser,
            new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.BOTH, new Insets(2, 10, 10, 5), 0, 0));
    JButton configureButton = new JButton(LuaBundle.message("sdk.chooser.configure.button"));
    add(configureButton,
            new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.NONE, new Insets(2, 0, 10, 5), 0, 0));

    configureButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myJdkChooser.editJdkTable();
        }
    });

    myJdkChooser.setAllowedJdkTypes(new SdkType[]{LuaSdkType.getInstance()});

    final Sdk selectedJdk = project == null ? null : ProjectRootManager.getInstance(project).getProjectSdk();

    myJdkChooser.fillList(LuaSdkType.getInstance(), null);
    if (selectedJdk != null) {
        myJdkChooser.selectJdk(selectedJdk);
    }
}
项目:intellij-ce-playground    文件:OrderEntryAppearanceServiceImpl.java   
@NotNull
@Override
public CellAppearanceEx forJdk(@Nullable final Sdk jdk, final boolean isInComboBox, final boolean selected, final boolean showVersion) {
  if (jdk == null) {
    return FileAppearanceService.getInstance().forInvalidUrl(NO_JDK);
  }

  String name = jdk.getName();
  CompositeAppearance appearance = new CompositeAppearance();
  SdkType sdkType = (SdkType)jdk.getSdkType();
  appearance.setIcon(sdkType.getIcon());
  SimpleTextAttributes attributes = getTextAttributes(sdkType.sdkHasValidPath(jdk), selected);
  CompositeAppearance.DequeEnd ending = appearance.getEnding();
  ending.addText(name, attributes);

  if (showVersion) {
    String versionString = jdk.getVersionString();
    if (versionString != null && !versionString.equals(name)) {
      SimpleTextAttributes textAttributes = isInComboBox && !selected ? SimpleTextAttributes.SYNTHETIC_ATTRIBUTES :
                                            SystemInfo.isMac && selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, 
                                                                                                    Color.WHITE): SimpleTextAttributes.GRAY_ATTRIBUTES;
      ending.addComment(versionString, textAttributes);
    }
  }

  return ending.getAppearance();
}
项目:intellij-ce-playground    文件:JavadocOrderRootTypeUIFactory.java   
private void onSpecifyUrlButtonClicked() {
  String defaultDocsUrl = mySdk == null ? "" : StringUtil.notNullize(((SdkType)mySdk.getSdkType()).getDefaultDocumentationUrl(mySdk), "");
  VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel, defaultDocsUrl);
  if (virtualFile != null) {
    addElement(virtualFile);
    setModified(true);
    requestDefaultFocus();
    setSelectedRoots(new Object[]{virtualFile});
  }
}
项目:intellij-ce-playground    文件:JdkChooserPanel.java   
public void updateList(final Sdk selectedJdk, final @Nullable SdkType type, final @Nullable Sdk[] globalSdks) {
  final int[] selectedIndices = myList.getSelectedIndices();
  fillList(type, globalSdks);
  // restore selection
  if (selectedJdk != null) {
    TIntArrayList list = new TIntArrayList();
    for (int i = 0; i < myListModel.size(); i++) {
      final Sdk jdk = (Sdk)myListModel.getElementAt(i);
      if (Comparing.strEqual(jdk.getName(), selectedJdk.getName())){
        list.add(i);
      }
    }
    final int[] indicesToSelect = list.toNativeArray();
    if (indicesToSelect.length > 0) {
      myList.setSelectedIndices(indicesToSelect);
    }
    else if (myList.getModel().getSize() > 0) {
      myList.setSelectedIndex(0);
    }
  }
  else {
    if (selectedIndices.length > 0) {
      myList.setSelectedIndices(selectedIndices);
    }
    else {
      myList.setSelectedIndex(0);
    }
  }

  myCurrentJdk = (Sdk)myList.getSelectedValue();
}
项目:intellij-ce-playground    文件:JdkChooserPanel.java   
private Sdk[] getCompatibleJdks(final @Nullable SdkType type, final Collection<Sdk> collection) {
  final Set<Sdk> compatibleJdks = new HashSet<Sdk>();
  for (Sdk projectJdk : collection) {
    if (isCompatibleJdk(projectJdk, type)) {
      compatibleJdks.add(projectJdk);
    }
  }
  return compatibleJdks.toArray(new Sdk[compatibleJdks.size()]);
}
项目:intellij-ce-playground    文件:JdkChooserPanel.java   
private boolean isCompatibleJdk(final Sdk projectJdk, final @Nullable SdkType type) {
  if (type != null) {
    return projectJdk.getSdkType() == type;
  }
  if (myAllowedJdkTypes != null) {
    return ArrayUtil.indexOf(myAllowedJdkTypes, projectJdk.getSdkType()) >= 0;
  }
  return true;
}
项目:intellij-ce-playground    文件:ProjectWizardStepFactoryImpl.java   
public ModuleWizardStep createProjectJdkStep(WizardContext context,
                                             SdkType type,
                                             final JavaModuleBuilder builder,
                                             final Computable<Boolean> isVisible,
                                             final Icon icon,
                                             @NonNls final String helpId) {
  return new ProjectJdkForModuleStep(context, type){
    public void updateDataModel() {
      super.updateDataModel();
      builder.setModuleJdk(getJdk());
    }

    public boolean isStepVisible() {
      return isVisible.compute().booleanValue();
    }

    public Icon getIcon() {
      return icon;
    }

    @Override
    public String getName() {
      return "Specify JDK";
    }

    public String getHelpId() {
      return helpId;
    }
  };
}
项目:intellij-ce-playground    文件:ProjectJdkForModuleStep.java   
@Nullable
private static Project getProject(final WizardContext context, final SdkType type) {
  Project project = context.getProject();
  if (type != null && project == null) { //'module' step inside project creation
    project = ProjectManager.getInstance().getDefaultProject();
  }
  return project;
}
项目:intellij-ce-playground    文件:SdkConfigurationUtil.java   
@Nullable
public static Sdk setupSdk(final Sdk[] allSdks,
                           final VirtualFile homeDir, final SdkType sdkType, final boolean silent,
                           @Nullable final SdkAdditionalData additionalData,
                           @Nullable final String customSdkSuggestedName) {
  final List<Sdk> sdksList = Arrays.asList(allSdks);

  final ProjectJdkImpl sdk;
  try {
    String sdkPath = sdkType.sdkPath(homeDir);

    final String sdkName = customSdkSuggestedName == null
                           ? createUniqueSdkName(sdkType, sdkPath, sdksList)
                           : createUniqueSdkName(customSdkSuggestedName, sdksList);
    sdk = new ProjectJdkImpl(sdkName, sdkType);

    if (additionalData != null) {
      // additional initialization.
      // E.g. some ruby sdks must be initialized before
      // setupSdkPaths() method invocation
      sdk.setSdkAdditionalData(additionalData);
    }

    sdk.setHomePath(sdkPath);
    sdkType.setupSdkPaths(sdk);
  }
  catch (Exception e) {
    if (!silent) {
      Messages.showErrorDialog("Error configuring SDK: " +
                               e.getMessage() +
                               ".\nPlease make sure that " +
                               FileUtil.toSystemDependentName(homeDir.getPath()) +
                               " is a valid home path for this SDK type.", "Error Configuring SDK");
    }
    return null;
  }
  return sdk;
}
项目:intellij-ce-playground    文件:SdkConfigurationUtil.java   
public static void configureDirectoryProjectSdk(final Project project,
                                                @Nullable Comparator<Sdk> preferredSdkComparator,
                                                final SdkType... sdkTypes) {
  Sdk existingSdk = ProjectRootManager.getInstance(project).getProjectSdk();
  if (existingSdk != null && ArrayUtil.contains(existingSdk.getSdkType(), sdkTypes)) {
    return;
  }

  Sdk sdk = findOrCreateSdk(preferredSdkComparator, sdkTypes);
  if (sdk != null) {
    setDirectoryProjectSdk(project, sdk);
  }
}
项目:intellij-ce-playground    文件:SdkConfigurationUtil.java   
@NotNull
public static List<String> filterExistingPaths(@NotNull SdkType sdkType, Collection<String> sdkHomes, final Sdk[] sdks) {
  List<String> result = new ArrayList<String>();
  for (String sdkHome : sdkHomes) {
    if (findByPath(sdkType, sdks, sdkHome) == null) {
      result.add(sdkHome);
    }
  }
  return result;
}
项目:intellij-ce-playground    文件:SdkConfigurationUtil.java   
@Nullable
private static Sdk findByPath(@NotNull SdkType sdkType, @NotNull Sdk[] sdks, @NotNull String sdkHome) {
  for (Sdk sdk : sdks) {
    final String path = sdk.getHomePath();
    if (sdk.getSdkType() == sdkType && path != null &&
        FileUtil.pathsEqual(FileUtil.toSystemIndependentName(path), FileUtil.toSystemIndependentName(sdkHome))) {
      return sdk;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:NavBarPresentation.java   
@SuppressWarnings("MethodMayBeStatic")
@Nullable
public Icon getIcon(final Object object) {
  if (!NavBarModel.isValid(object)) return null;
  if (object instanceof Project) return AllIcons.Nodes.Project;
  if (object instanceof Module) return ModuleType.get(((Module)object)).getIcon();
  try {
    if (object instanceof PsiElement) {
      Icon icon = ApplicationManager.getApplication().runReadAction(new Computable<Icon>() {
        @Override
        public Icon compute() {
          return ((PsiElement)object).isValid() ? ((PsiElement)object).getIcon(0) : null;
        }
      });

      if (icon != null && (icon.getIconHeight() > 16 * 2 || icon.getIconWidth() > 16 * 2)) {
        icon = IconUtil.cropIcon(icon, 16 * 2, 16 * 2);
      }
      return icon;
    }
  }
  catch (IndexNotReadyException e) {
    return null;
  }
  if (object instanceof JdkOrderEntry) {
    final SdkTypeId sdkType = ((JdkOrderEntry)object).getJdk().getSdkType();
    return ((SdkType) sdkType).getIcon();
  }
  if (object instanceof LibraryOrderEntry) return AllIcons.Nodes.PpLibFolder;
  if (object instanceof ModuleOrderEntry) return ModuleType.get(((ModuleOrderEntry)object).getModule()).getIcon();
  return null;
}
项目:intellij-ce-playground    文件:NamedLibraryElementNode.java   
private static Icon getJdkIcon(JdkOrderEntry entry) {
  final Sdk sdk = entry.getJdk();
  if (sdk == null) {
    return AllIcons.General.Jdk;
  }
  final SdkType sdkType = (SdkType) sdk.getSdkType();
  return sdkType.getIcon();
}
项目:intellij-ce-playground    文件:PythonMockSdk.java   
public static Sdk create(final String version, @NotNull final VirtualFile ... additionalRoots) {
  final String mock_path = PythonTestUtil.getTestDataPath() + "/MockSdk" + version + "/";

  String sdkHome = new File(mock_path, "bin/python"+version).getPath();
  SdkType sdkType = PythonSdkType.getInstance();


  final Sdk sdk = new ProjectJdkImpl(MOCK_SDK_NAME + " " + version, sdkType) {
    @Override
    public String getVersionString() {
      return "Python " + version + " Mock SDK";
    }
  };
  final SdkModificator sdkModificator = sdk.getSdkModificator();
  sdkModificator.setHomePath(sdkHome);

  File libPath = new File(mock_path, "Lib");
  if (libPath.exists()) {
    sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libPath), OrderRootType.CLASSES);
  }

  PyUserSkeletonsUtil.addUserSkeletonsRoot(PySdkUpdater.fromSdkModificator(sdk, sdkModificator));

  String mock_stubs_path = mock_path + PythonSdkType.SKELETON_DIR_NAME;
  sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByPath(mock_stubs_path), PythonSdkType.BUILTIN_ROOT_TYPE);

  for (final VirtualFile root : additionalRoots) {
    sdkModificator.addRoot(root, OrderRootType.CLASSES);
  }

  sdkModificator.commitChanges();

  final FileBasedIndex index = FileBasedIndex.getInstance();
  index.requestRebuild(StubUpdatingIndex.INDEX_ID);
  index.requestRebuild(PyModuleNameIndex.NAME);

  return sdk;
}
项目:intellij-ce-playground    文件:AndroidSdkComboBoxWithBrowseButton.java   
public AndroidSdkComboBoxWithBrowseButton() {
  final JComboBox sdkCombobox = getComboBox();

  sdkCombobox.setRenderer(new ListCellRendererWrapper() {
    @Override
    public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (value instanceof Sdk) {
        final Sdk sdk = (Sdk)value;
        setText(sdk.getName());
        setIcon(((SdkType) sdk.getSdkType()).getIcon());
      }
      else {
        setText("<html><font color='red'>[none]</font></html>");
      }
    }
  });

  addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      ProjectJdksEditor editor =
        new ProjectJdksEditor(null, ProjectManager.getInstance().getDefaultProject(), AndroidSdkComboBoxWithBrowseButton.this);
      if (editor.showAndGet()) {
        final Sdk selectedJdk = editor.getSelectedJdk();
        rebuildSdksListAndSelectSdk(selectedJdk);
        if (selectedJdk == null || !isAndroidSdk(selectedJdk)) {
          Messages.showErrorDialog(AndroidSdkComboBoxWithBrowseButton.this, AndroidBundle.message("select.platform.error"),
                                   CommonBundle.getErrorTitle());
        }
      }
    }
  });
  getButton().setToolTipText(AndroidBundle.message("android.add.sdk.tooltip"));
}
项目:intellij-ocaml    文件:OCamlSdkChooserPanel.java   
public OCamlSdkChooserPanel(final Project project) {
    myJdkChooser = new JdkChooserPanel(project);

    setLayout(new GridBagLayout());
    setBorder(BorderFactory.createEtchedBorder());

    final JLabel label = new JLabel("Specify the OCaml binaries directory");
    label.setUI(new MultiLineLabelUI());
    add(label, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
        GridBagConstraints.HORIZONTAL, new Insets(8, 10, 8, 10), 0, 0));

    final JLabel jdkLabel = new JLabel("OCaml SDK version:");
    jdkLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    add(jdkLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
        GridBagConstraints.NONE, new Insets(8, 10, 0, 10), 0, 0));

    add(myJdkChooser, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
        GridBagConstraints.BOTH, new Insets(2, 10, 10, 5), 0, 0));
    JButton configureButton = new JButton("Configure...");
    add(configureButton, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
        GridBagConstraints.NONE, new Insets(2, 0, 10, 5), 0, 0));

    configureButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myJdkChooser.editJdkTable();
        }
    });

    myJdkChooser.setAllowedJdkTypes(new SdkType[] { OCamlSdkType.getInstance() });

    final Sdk selectedJdk = project == null ? null : ProjectRootManager.getInstance(project).getProjectJdk();
    myJdkChooser.updateList(selectedJdk, null);
}
项目:tools-idea    文件:OrderEntryAppearanceServiceImpl.java   
@NotNull
@Override
public CellAppearanceEx forJdk(@Nullable final Sdk jdk, final boolean isInComboBox, final boolean selected, final boolean showVersion) {
  if (jdk == null) {
    return FileAppearanceService.getInstance().forInvalidUrl(NO_JDK);
  }

  String name = jdk.getName();
  CompositeAppearance appearance = new CompositeAppearance();
  SdkType sdkType = (SdkType)jdk.getSdkType();
  appearance.setIcon(sdkType.getIcon());
  SimpleTextAttributes attributes = getTextAttributes(sdkType.sdkHasValidPath(jdk), selected);
  CompositeAppearance.DequeEnd ending = appearance.getEnding();
  ending.addText(name, attributes);

  if (showVersion) {
    String versionString = jdk.getVersionString();
    if (versionString != null && !versionString.equals(name)) {
      SimpleTextAttributes textAttributes = isInComboBox && !selected ? SimpleTextAttributes.SYNTHETIC_ATTRIBUTES :
                                            SystemInfo.isMac && selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, 
                                                                                                    Color.WHITE): SimpleTextAttributes.GRAY_ATTRIBUTES;
      ending.addComment(versionString, textAttributes);
    }
  }

  return ending.getAppearance();
}
项目:tools-idea    文件:JavadocOrderRootTypeUIFactory.java   
private void onSpecifyUrlButtonClicked() {
  final String defaultDocsUrl = mySdk == null ? "" : StringUtil.notNullize(((SdkType) mySdk.getSdkType()).getDefaultDocumentationUrl(mySdk), "");
  VirtualFile virtualFile  = Util.showSpecifyJavadocUrlDialog(myPanel, defaultDocsUrl);
  if(virtualFile != null){
    addElement(virtualFile);
    setModified(true);
    requestDefaultFocus();
    setSelectedRoots(new Object[]{virtualFile});
  }
}
项目:tools-idea    文件:JdkChooserPanel.java   
public void updateList(final Sdk selectedJdk, final @Nullable SdkType type, final @Nullable Sdk[] globalSdks) {
  final int[] selectedIndices = myList.getSelectedIndices();
  fillList(type, globalSdks);
  // restore selection
  if (selectedJdk != null) {
    TIntArrayList list = new TIntArrayList();
    for (int i = 0; i < myListModel.size(); i++) {
      final Sdk jdk = (Sdk)myListModel.getElementAt(i);
      if (Comparing.strEqual(jdk.getName(), selectedJdk.getName())){
        list.add(i);
      }
    }
    final int[] indicesToSelect = list.toNativeArray();
    if (indicesToSelect.length > 0) {
      myList.setSelectedIndices(indicesToSelect);
    }
    else if (myList.getModel().getSize() > 0) {
      myList.setSelectedIndex(0);
    }
  }
  else {
    if (selectedIndices.length > 0) {
      myList.setSelectedIndices(selectedIndices);
    }
    else {
      myList.setSelectedIndex(0);
    }
  }

  myCurrentJdk = (Sdk)myList.getSelectedValue();
}
项目:tools-idea    文件:JdkChooserPanel.java   
private Sdk[] getCompatibleJdks(final @Nullable SdkType type, final Collection<Sdk> collection) {
  final Set<Sdk> compatibleJdks = new HashSet<Sdk>();
  for (Sdk projectJdk : collection) {
    if (isCompatibleJdk(projectJdk, type)) {
      compatibleJdks.add(projectJdk);
    }
  }
  return compatibleJdks.toArray(new Sdk[compatibleJdks.size()]);
}
项目:tools-idea    文件:JdkChooserPanel.java   
private boolean isCompatibleJdk(final Sdk projectJdk, final @Nullable SdkType type) {
  if (type != null) {
    return projectJdk.getSdkType() == type;
  }
  if (myAllowedJdkTypes != null) {
    return ArrayUtil.indexOf(myAllowedJdkTypes, projectJdk.getSdkType()) >= 0;
  }
  return true;
}
项目:tools-idea    文件:ProjectWizardStepFactoryImpl.java   
public ModuleWizardStep createProjectJdkStep(WizardContext context,
                                             SdkType type,
                                             final JavaModuleBuilder builder,
                                             final Computable<Boolean> isVisible,
                                             final Icon icon,
                                             @NonNls final String helpId) {
  return new ProjectJdkForModuleStep(context, type){
    public void updateDataModel() {
      super.updateDataModel();
      builder.setModuleJdk(getJdk());
    }

    public boolean isStepVisible() {
      return isVisible.compute().booleanValue();
    }

    public Icon getIcon() {
      return icon;
    }

    @Override
    public String getName() {
      return "Specify JDK";
    }

    public String getHelpId() {
      return helpId;
    }
  };
}
项目:tools-idea    文件:ProjectJdkForModuleStep.java   
@Nullable
private static Project getProject(final WizardContext context, final SdkType type) {
  Project project = context.getProject();
  if (type != null && project == null) { //'module' step inside project creation
    project = ProjectManager.getInstance().getDefaultProject();
  }
  return project;
}