diff --git a/platform/lang-impl/src/com/intellij/bootRuntime/Controller.kt b/platform/lang-impl/src/com/intellij/bootRuntime/Controller.kt index 4c9e7b1179c0..b68dec3338fb 100644 --- a/platform/lang-impl/src/com/intellij/bootRuntime/Controller.kt +++ b/platform/lang-impl/src/com/intellij/bootRuntime/Controller.kt @@ -17,6 +17,7 @@ import com.intellij.ui.components.JBOptionButton import com.intellij.util.ui.UIUtil import java.awt.GridBagConstraints import java.awt.Insets +import javax.swing.Action import javax.swing.JButton import javax.swing.SwingUtilities @@ -36,7 +37,10 @@ class Controller(val project: Project, val actionPanel:ActionPanel, val model: M actionPanel.removeAll() val list = runtimeStateToActions(runtime, model.currentState()).toList() - val job = JBOptionButton(list.firstOrNull(), list.subList(1, list.size).toTypedArray()) + val job = if (list.size > 1) + JBOptionButton(list.firstOrNull(), list.subList(1, list.size).toTypedArray()) + else + JButton(list.firstOrNull()) val constraint = GridBagConstraints() constraint.insets = Insets(0,0,0, 0) @@ -69,6 +73,7 @@ class Controller(val project: Project, val actionPanel:ActionPanel, val model: M EXTRACTED -> listOf(produce(INSTALL, runtime), produce(DELETE, runtime)) UNINSTALLED -> listOf(produce(INSTALL, runtime), produce(DELETE, runtime)) INSTALLED -> listOf(produce(UNINSTALL, runtime)) + LOCAL -> listOf(produce(INSTALL, runtime)) } } diff --git a/platform/lang-impl/src/com/intellij/bootRuntime/Model.kt b/platform/lang-impl/src/com/intellij/bootRuntime/Model.kt index 1253d756a7f8..99f9cc31b06b 100644 --- a/platform/lang-impl/src/com/intellij/bootRuntime/Model.kt +++ b/platform/lang-impl/src/com/intellij/bootRuntime/Model.kt @@ -1,12 +1,14 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.bootRuntime +import com.intellij.bootRuntime.bundles.Local import com.intellij.bootRuntime.bundles.Remote import com.intellij.bootRuntime.bundles.Runtime import com.intellij.openapi.util.io.FileUtil enum class BundleState { REMOTE, + LOCAL, DOWNLOADED, EXTRACTED, INSTALLED, @@ -25,6 +27,7 @@ class Model(var selectedBundle: Runtime, val bundles:MutableList) { isExtracted(selectedBundle) -> BundleState.EXTRACTED isDownloaded(selectedBundle) -> BundleState.DOWNLOADED isRemote(selectedBundle) -> BundleState.REMOTE + isLocal(selectedBundle) -> BundleState.LOCAL else -> BundleState.UNINSTALLED } } @@ -38,4 +41,6 @@ class Model(var selectedBundle: Runtime, val bundles:MutableList) { private fun isDownloaded(bundle:Runtime):Boolean = bundle.downloadPath.exists() fun isRemote(bundle:Runtime):Boolean = bundle is Remote + + fun isLocal(bundle:Runtime):Boolean = bundle is Local } diff --git a/platform/lang-impl/src/com/intellij/bootRuntime/command/CommandFactory.java b/platform/lang-impl/src/com/intellij/bootRuntime/command/CommandFactory.java index 096278475383..3d6953313a3f 100644 --- a/platform/lang-impl/src/com/intellij/bootRuntime/command/CommandFactory.java +++ b/platform/lang-impl/src/com/intellij/bootRuntime/command/CommandFactory.java @@ -49,9 +49,7 @@ public class CommandFactory { case INSTALL: return new Install(getInstance().myProject, getInstance().myController, runtime); case UNINSTALL: - Install install = new Install(getInstance().myProject, getInstance().myController, runtime); - install.setEnabled(false); - return install; + return new Uninstall(getInstance().myProject, getInstance().myController, runtime); case DELETE: return new Delete(getInstance().myProject, getInstance().myController, runtime); } diff --git a/platform/lang-impl/src/com/intellij/bootRuntime/command/Uninstall.java b/platform/lang-impl/src/com/intellij/bootRuntime/command/Uninstall.java new file mode 100644 index 000000000000..9cffd1d02356 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/bootRuntime/command/Uninstall.java @@ -0,0 +1,24 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.bootRuntime.command; + +import com.intellij.bootRuntime.BinTrayUtil; +import com.intellij.bootRuntime.Controller; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.bootRuntime.bundles.Runtime; + +import java.awt.event.ActionEvent; + +public class Uninstall extends RuntimeCommand { + public Uninstall(Project project, Controller controller, Runtime runtime) { + super(project, controller, "Uninstall", runtime); + } + + @Override + public void actionPerformed(ActionEvent e) { + runWithProgress("Uninstalling...", indicator -> { + FileUtil.delete(BinTrayUtil.getJdkConfigFilePath()); + myController.restart(); + }); + } +}