mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suggest javadoc url for known jdk (IDEA-51887)
This commit is contained in:
@@ -25,12 +25,12 @@ import com.intellij.ide.util.projectWizard.ProjectBuilder;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.module.LanguageLevelUtil;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
@@ -168,7 +168,7 @@ public class NewProjectUtil {
|
||||
|
||||
ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(project);
|
||||
rootManager.setProjectJdk(jdk);
|
||||
LanguageLevel level = getDefaultLanguageLevel(versionString);
|
||||
LanguageLevel level = LanguageLevelUtil.getDefaultLanguageLevel(versionString);
|
||||
LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(project);
|
||||
if (level.compareTo(ext.getLanguageLevel()) < 0) {
|
||||
ext.setLanguageLevel(level);
|
||||
@@ -187,25 +187,4 @@ public class NewProjectUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static LanguageLevel getDefaultLanguageLevel(@NotNull String versionString) {
|
||||
if (isOfVersionOrHigher(versionString, "1.7") || isOfVersionOrHigher(versionString, "7.0")) {
|
||||
return LanguageLevel.JDK_1_7;
|
||||
}
|
||||
if (isOfVersionOrHigher(versionString, "1.6") || isOfVersionOrHigher(versionString, "6.0")) {
|
||||
return LanguageLevel.JDK_1_6;
|
||||
}
|
||||
if (isOfVersionOrHigher(versionString, "1.5") || isOfVersionOrHigher(versionString, "5.0")) {
|
||||
return LanguageLevel.JDK_1_5;
|
||||
}
|
||||
|
||||
if (isOfVersionOrHigher(versionString, "1.4")) {
|
||||
return LanguageLevel.JDK_1_4;
|
||||
}
|
||||
|
||||
return LanguageLevel.JDK_1_3;
|
||||
}
|
||||
|
||||
private static boolean isOfVersionOrHigher(@NotNull String versionString, String checkedVersion) {
|
||||
return JavaSdk.getInstance().compareTo(versionString, checkedVersion) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public abstract class PathEditor {
|
||||
});
|
||||
mySpecifyUrlButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel);
|
||||
VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel, getInitialValue());
|
||||
if(virtualFile != null){
|
||||
addElement(virtualFile);
|
||||
setModified(true);
|
||||
@@ -182,6 +182,10 @@ public abstract class PathEditor {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
protected String getInitialValue() {
|
||||
return "";
|
||||
}
|
||||
|
||||
private void itemsRemoved(java.util.List removedItems) {
|
||||
myAllFiles.removeAll(removedItems);
|
||||
if (removedItems.size() > 0){
|
||||
|
||||
@@ -133,7 +133,7 @@ public class SdkEditor implements Configurable, Place.Navigator {
|
||||
myTabbedPane = new TabbedPaneWrapper(myDisposable);
|
||||
for (OrderRootType type : OrderRootType.getAllTypes()) {
|
||||
if (mySdk == null || mySdk.getSdkType().isRootTypeApplicable(type)) {
|
||||
final PathEditor pathEditor = OrderRootTypeUIFactory.FACTORY.getByKey(type).createPathEditor();
|
||||
final PathEditor pathEditor = OrderRootTypeUIFactory.FACTORY.getByKey(type).createPathEditor(mySdk);
|
||||
myTabbedPane.addTab(pathEditor.getDisplayName(), pathEditor.createComponent());
|
||||
myPathEditors.put(type, pathEditor);
|
||||
}
|
||||
@@ -294,36 +294,6 @@ public class SdkEditor implements Configurable, Place.Navigator {
|
||||
return LocalFileSystem.getInstance().findFileByPath(homepath);
|
||||
}
|
||||
|
||||
private static class MyPathsEditor extends PathEditor {
|
||||
private final String myDisplayName;
|
||||
private final OrderRootType myRootType;
|
||||
private final FileChooserDescriptor myDescriptor;
|
||||
private final boolean myCanAddUrl;
|
||||
|
||||
public MyPathsEditor(String displayName, OrderRootType rootType, FileChooserDescriptor descriptor, boolean canAddUrl) {
|
||||
myDisplayName = displayName;
|
||||
myRootType = rootType;
|
||||
myDescriptor = descriptor;
|
||||
myCanAddUrl = canAddUrl;
|
||||
}
|
||||
|
||||
protected OrderRootType getRootType() {
|
||||
return myRootType;
|
||||
}
|
||||
|
||||
protected FileChooserDescriptor createFileChooserDescriptor() {
|
||||
return myDescriptor;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return myDisplayName;
|
||||
}
|
||||
|
||||
protected boolean isShowUrlButton() {
|
||||
return myCanAddUrl;
|
||||
}
|
||||
}
|
||||
|
||||
private void doSelectHomePath(){
|
||||
final SdkType sdkType = mySdk.getSdkType();
|
||||
final String homePath = selectSdkHome(myHomeComponent, sdkType);
|
||||
|
||||
@@ -32,9 +32,13 @@ import java.net.URL;
|
||||
*/
|
||||
public class Util{
|
||||
|
||||
public static VirtualFile showSpecifyJavadocUrlDialog(JComponent parent){
|
||||
public static VirtualFile showSpecifyJavadocUrlDialog(JComponent parent) {
|
||||
return showSpecifyJavadocUrlDialog(parent, "");
|
||||
}
|
||||
|
||||
public static VirtualFile showSpecifyJavadocUrlDialog(JComponent parent, String initialValue){
|
||||
final String url = Messages.showInputDialog(parent, ProjectBundle.message("sdk.configure.javadoc.url.prompt"),
|
||||
ProjectBundle.message("sdk.configure.javadoc.url.title"), Messages.getQuestionIcon(), "", new InputValidator() {
|
||||
ProjectBundle.message("sdk.configure.javadoc.url.title"), Messages.getQuestionIcon(), initialValue, new InputValidator() {
|
||||
public boolean checkInput(String inputString) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+27
-2
@@ -21,11 +21,14 @@
|
||||
package com.intellij.openapi.roots.ui.configuration;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.module.LanguageLevelUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ui.PathEditor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableTreeContentElement;
|
||||
import com.intellij.openapi.util.KeyedExtensionFactory;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
|
||||
public interface OrderRootTypeUIFactory {
|
||||
KeyedExtensionFactory<OrderRootTypeUIFactory, OrderRootType> FACTORY = new KeyedExtensionFactory<OrderRootTypeUIFactory, OrderRootType>(OrderRootTypeUIFactory.class, "com.intellij.OrderRootTypeUI") {
|
||||
@@ -35,19 +38,25 @@ public interface OrderRootTypeUIFactory {
|
||||
};
|
||||
|
||||
LibraryTableTreeContentElement createElement(final LibraryElement parentElement);
|
||||
PathEditor createPathEditor();
|
||||
PathEditor createPathEditor(Sdk sdk);
|
||||
|
||||
class MyPathsEditor extends PathEditor {
|
||||
private final boolean myShowUrl;
|
||||
private final OrderRootType myOrderRootType;
|
||||
private final FileChooserDescriptor myDescriptor;
|
||||
private final String myDisplayName;
|
||||
private final Sdk mySdk;
|
||||
|
||||
public MyPathsEditor(final String displayName, final OrderRootType orderRootType, final FileChooserDescriptor descriptor, final boolean showUrl) {
|
||||
public MyPathsEditor(final String displayName,
|
||||
final OrderRootType orderRootType,
|
||||
final FileChooserDescriptor descriptor,
|
||||
final boolean showUrl,
|
||||
Sdk sdk) {
|
||||
myShowUrl = showUrl;
|
||||
myOrderRootType = orderRootType;
|
||||
myDescriptor = descriptor;
|
||||
myDisplayName = displayName;
|
||||
mySdk = sdk;
|
||||
}
|
||||
|
||||
protected boolean isShowUrlButton() {
|
||||
@@ -65,5 +74,21 @@ public interface OrderRootTypeUIFactory {
|
||||
public String getDisplayName() {
|
||||
return myDisplayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInitialValue() {
|
||||
if (mySdk != null) {
|
||||
final String versionString = mySdk.getVersionString();
|
||||
if (versionString != null) {
|
||||
final LanguageLevel level = LanguageLevelUtil.getDefaultLanguageLevel(versionString);
|
||||
if (level == LanguageLevel.JDK_1_5) {
|
||||
return "http://java.sun.com/j2se/1.5.0/docs/api/";
|
||||
} else if (level == LanguageLevel.JDK_1_6) {
|
||||
return "http://java.sun.com/j2se/6/docs/api/";
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ui.PathEditor;
|
||||
import com.intellij.openapi.roots.AnnotationOrderRootType;
|
||||
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
|
||||
@@ -31,8 +32,8 @@ public class AnnotationsOrderRootTypeUIFactory implements OrderRootTypeUIFactory
|
||||
return new AnnotationElement(parentElement);
|
||||
}
|
||||
|
||||
public PathEditor createPathEditor() {
|
||||
public PathEditor createPathEditor(Sdk sdk) {
|
||||
return new MyPathsEditor(ProjectBundle.message("sdk.configure.annotations.tab"), AnnotationOrderRootType.getInstance(),
|
||||
FileChooserDescriptorFactory.createSingleFolderDescriptor(), false);
|
||||
FileChooserDescriptorFactory.createSingleFolderDescriptor(), false, sdk);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -22,6 +22,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ui.PathEditor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
|
||||
@@ -31,7 +32,8 @@ public class ClassesOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
|
||||
return new ClassesElement(parentElement);
|
||||
}
|
||||
|
||||
public PathEditor createPathEditor() {
|
||||
return new MyPathsEditor(ProjectBundle.message("sdk.configure.classpath.tab"), OrderRootType.CLASSES, new FileChooserDescriptor(true, true, true, false, true, true), false);
|
||||
public PathEditor createPathEditor(Sdk sdk) {
|
||||
return new MyPathsEditor(ProjectBundle.message("sdk.configure.classpath.tab"), OrderRootType.CLASSES, new FileChooserDescriptor(true, true, true, false, true, true), false,
|
||||
sdk);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -22,6 +22,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ui.PathEditor;
|
||||
import com.intellij.openapi.roots.JavadocOrderRootType;
|
||||
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
|
||||
@@ -31,7 +32,8 @@ public class JavadocOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
|
||||
return new JavadocElement(parentElement);
|
||||
}
|
||||
|
||||
public PathEditor createPathEditor() {
|
||||
return new MyPathsEditor(ProjectBundle.message("sdk.configure.javadoc.tab"), JavadocOrderRootType.getInstance(), new FileChooserDescriptor(false, true, true, false, true, true), true);
|
||||
public PathEditor createPathEditor(Sdk sdk) {
|
||||
return new MyPathsEditor(ProjectBundle.message("sdk.configure.javadoc.tab"), JavadocOrderRootType.getInstance(), new FileChooserDescriptor(false, true, true, false, true, true), true,
|
||||
sdk);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -22,6 +22,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ui.PathEditor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
|
||||
@@ -35,8 +36,9 @@ public class SourcesOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
|
||||
return new SourcesElement(parentElement);
|
||||
}
|
||||
|
||||
public PathEditor createPathEditor() {
|
||||
return new MyPathsEditor(ProjectBundle.message("sdk.configure.sourcepath.tab"), OrderRootType.SOURCES, new FileChooserDescriptor(true, true, true, false, true, true), false) {
|
||||
public PathEditor createPathEditor(Sdk sdk) {
|
||||
return new MyPathsEditor(ProjectBundle.message("sdk.configure.sourcepath.tab"), OrderRootType.SOURCES, new FileChooserDescriptor(true, true, true, false, true, true), false,
|
||||
sdk) {
|
||||
@Override
|
||||
protected VirtualFile[] adjustAddedFileSet(final Component component, final VirtualFile[] files) {
|
||||
return PathUIUtils.scanAndSelectDetectedJavaSourceRoots(component, files);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.module;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -48,4 +49,26 @@ public class LanguageLevelUtil {
|
||||
|
||||
return getLanguageLevelForFile(file.getParent());
|
||||
}
|
||||
|
||||
public static LanguageLevel getDefaultLanguageLevel(@NotNull String versionString) {
|
||||
if (isOfVersionOrHigher(versionString, "1.7") || isOfVersionOrHigher(versionString, "7.0")) {
|
||||
return LanguageLevel.JDK_1_7;
|
||||
}
|
||||
if (isOfVersionOrHigher(versionString, "1.6") || isOfVersionOrHigher(versionString, "6.0")) {
|
||||
return LanguageLevel.JDK_1_6;
|
||||
}
|
||||
if (isOfVersionOrHigher(versionString, "1.5") || isOfVersionOrHigher(versionString, "5.0")) {
|
||||
return LanguageLevel.JDK_1_5;
|
||||
}
|
||||
|
||||
if (isOfVersionOrHigher(versionString, "1.4")) {
|
||||
return LanguageLevel.JDK_1_4;
|
||||
}
|
||||
|
||||
return LanguageLevel.JDK_1_3;
|
||||
}
|
||||
|
||||
public static boolean isOfVersionOrHigher(@NotNull String versionString, String checkedVersion) {
|
||||
return JavaSdk.getInstance().compareTo(versionString, checkedVersion) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user