Skip to content

Commit

Permalink
Different default documentation URL for different types of SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-doroshko committed Feb 24, 2012
1 parent 5d8d56e commit f9cbfe7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.ui.SdkPathEditor;
import com.intellij.openapi.projectRoots.ui.Util;
import com.intellij.openapi.roots.JavadocOrderRootType;
import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.AnActionButton;
import com.intellij.ui.AnActionButtonUpdater;
Expand Down Expand Up @@ -86,29 +85,14 @@ public boolean isEnabled(AnActionEvent e) {
}

private void onSpecifyUrlButtonClicked() {
VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel, getInitialValue());
final String defaultDocsUrl = mySdk == null ? "" : StringUtil.notNullize(mySdk.getSdkType().getDefaultDocumentationUrl(mySdk), "");
VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myPanel, defaultDocsUrl);
if(virtualFile != null){
addElement(virtualFile);
setModified(true);
requestDefaultFocus();
setSelectedRoots(new Object[]{virtualFile});
}
}

private String getInitialValue() {
if (mySdk != null) {
final JavaSdkVersion version = JavaSdk.getInstance().getVersion(mySdk);
if (version == JavaSdkVersion.JDK_1_5) {
return "http://download.oracle.com/javase/1.5.0/docs/api/";
}
else if (version == JavaSdkVersion.JDK_1_6) {
return "http://download.oracle.com/javase/6/docs/api/";
}
else if (version == JavaSdkVersion.JDK_1_7) {
return "http://download.oracle.com/javase/7/docs/api/";
}
}
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ public Icon getIconForAddAction() {
return ADD_ICON;
}

@Nullable
public String getDefaultDocumentationUrl(final @NotNull Sdk sdk) {
final JavaSdkVersion version = getVersion(sdk);
if (version == JavaSdkVersion.JDK_1_5) {
return "http://download.oracle.com/javase/1.5.0/docs/api/";
}
else if (version == JavaSdkVersion.JDK_1_6) {
return "http://download.oracle.com/javase/6/docs/api/";
}
else if (version == JavaSdkVersion.JDK_1_7) {
return "http://download.oracle.com/javase/7/docs/api/";
}
return null;
}

@Override
public AdditionalDataConfigurable createAdditionalDataConfigurable(SdkModel sdkModel, SdkModificator sdkModificator) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public String getHomeFieldLabel() {
return ProjectBundle.message("sdk.configure.type.home.path", getPresentableName());
}

@Nullable
public String getDefaultDocumentationUrl(final @NotNull Sdk sdk) {
return null;
}

public static SdkType[] getAllTypes() {
List<SdkType> allTypes = new ArrayList<SdkType>();
Collections.addAll(allTypes, ApplicationManager.getApplication().getComponents(SdkType.class));
Expand Down
4 changes: 4 additions & 0 deletions plugins/devkit/src/projectRoots/IdeaJdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,8 @@ public boolean isRootTypeApplicable(OrderRootType type) {
type == JavadocOrderRootType.getInstance() ||
type == AnnotationOrderRootType.getInstance();
}

public String getDefaultDocumentationUrl(final @NotNull Sdk sdk) {
return JavaSdk.getInstance().getDefaultDocumentationUrl(sdk);
}
}

0 comments on commit f9cbfe7

Please sign in to comment.