Skip to content

Commit 067570c

Browse files
authored
should open webview on clicking 'Install A New JDK' button (#1068)
1 parent 78d6b0c commit 067570c

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/java-runtime/assets/ToolingJDKPanel.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import { provideReactWrapper } from '@microsoft/fast-react-wrapper';
55
import * as webviewUI from "@vscode/webview-ui-toolkit";
66
import * as React from "react";
7-
import { encodeCommandUriWithTelemetry } from '../../utils/webview';
87
import { JavaRuntimeEntry } from "../types";
9-
import { onWillBrowseForJDK } from './vscode.api';
8+
import { onWillBrowseForJDK, onWillRunCommandFromWebview } from './vscode.api';
109

1110
const REQUIRED_JDK_VERSION = 17;
1211
const { wrap } = provideReactWrapper(React);
@@ -25,8 +24,7 @@ interface State {
2524
export class ToolingJDKPanel extends React.Component<Props, State> {
2625
render = () => {
2726
const { javaHomeError } = this.props;
28-
const downloadJDKCommand = encodeCommandUriWithTelemetry("java.runtime", "download", "java.installJdk");
29-
27+
3028
return (
3129
<div className="container">
3230
<h1>Configure Runtime for Language Server</h1>
@@ -39,7 +37,7 @@ export class ToolingJDKPanel extends React.Component<Props, State> {
3937
{this?.state?.isDirty && <Button><a href="command:workbench.action.reloadWindow">Reload</a></Button> }
4038
</div>
4139
<div className="jdk-action">
42-
<Button appearance="secondary"><a href={downloadJDKCommand}>Install a <b>New JDK</b></a></Button>
40+
<Button appearance="secondary" onClick={this.onClickInstallButton}><a href="#">Install a <b>New JDK</b></a></Button>
4341
</div>
4442
</div>
4543
);
@@ -49,4 +47,8 @@ export class ToolingJDKPanel extends React.Component<Props, State> {
4947
onWillBrowseForJDK();
5048
this.setState({ isDirty: true });
5149
}
50+
51+
onClickInstallButton = () => {
52+
onWillRunCommandFromWebview("java.runtime", "download", "java.installJdk");
53+
}
5254
}

src/java-runtime/assets/vscode.api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ export function onWillBrowseForJDK() {
4646
command: "onWillBrowseForJDK"
4747
});
4848
}
49+
50+
export function onWillRunCommandFromWebview(webview: string, identifier: string, command: string, args?: any[]) {
51+
vscode.postMessage({
52+
command: "onWillRunCommandFromWebview",
53+
wrappedArgs: {
54+
webview,
55+
identifier,
56+
command,
57+
args
58+
}
59+
});
60+
}

src/java-runtime/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ async function initializeJavaRuntimeView(context: vscode.ExtensionContext, webvi
129129
}
130130
break;
131131
}
132+
case "onWillRunCommandFromWebview": {
133+
const { wrappedArgs } = e;
134+
vscode.commands.executeCommand("java.webview.runCommand", wrappedArgs);
135+
break;
136+
}
132137
default:
133138
break;
134139
}

0 commit comments

Comments
 (0)