From c01439b3fa572add4cf0c3b667b0f941272ea6c2 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 24 Feb 2010 15:18:18 +0300 Subject: [PATCH] suggest javadoc url for known jdk (IDEA-51887) --- .../com/intellij/ide/impl/NewProjectUtil.java | 25 ++------------- .../openapi/projectRoots/ui/PathEditor.java | 6 +++- .../openapi/projectRoots/ui/SdkEditor.java | 32 +------------------ .../openapi/projectRoots/ui/Util.java | 8 +++-- .../configuration/OrderRootTypeUIFactory.java | 29 +++++++++++++++-- .../AnnotationsOrderRootTypeUIFactory.java | 5 +-- .../ClassesOrderRootTypeUIFactory.java | 6 ++-- .../JavadocOrderRootTypeUIFactory.java | 6 ++-- .../SourcesOrderRootTypeUIFactory.java | 6 ++-- .../openapi/module/LanguageLevelUtil.java | 23 +++++++++++++ 10 files changed, 79 insertions(+), 67 deletions(-) diff --git a/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java b/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java index da9e84693775..05d9d746d8c8 100644 --- a/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java +++ b/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java @@ -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; - } } diff --git a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java index 3fe0236751a6..9ae5ada1ad55 100644 --- a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/PathEditor.java @@ -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){ diff --git a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/SdkEditor.java b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/SdkEditor.java index 1e1fda075583..22c487df3dcc 100644 --- a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/SdkEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/SdkEditor.java @@ -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); diff --git a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/Util.java b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/Util.java index caf893365494..ff23ce84c6cd 100644 --- a/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/Util.java +++ b/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/Util.java @@ -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; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java index d672dcfaac9a..0723886593b7 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/OrderRootTypeUIFactory.java @@ -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 FACTORY = new KeyedExtensionFactory(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 ""; + } } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/AnnotationsOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/AnnotationsOrderRootTypeUIFactory.java index ef2d5d4419a2..0b4ab2759abe 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/AnnotationsOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/AnnotationsOrderRootTypeUIFactory.java @@ -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); } } \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java index ee05e932fed2..c74af974f0a7 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java @@ -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); } } \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java index 948103ba9d58..73f24a24a68a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/JavadocOrderRootTypeUIFactory.java @@ -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); } } \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/SourcesOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/SourcesOrderRootTypeUIFactory.java index 5f157be39eb9..d485ba0743f7 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/SourcesOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/SourcesOrderRootTypeUIFactory.java @@ -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); diff --git a/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java b/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java index 2b52e0c05863..a4b005a1c12d 100644 --- a/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java +++ b/java/openapi/src/com/intellij/openapi/module/LanguageLevelUtil.java @@ -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; + } }