10
10
******************************************************************************/
11
11
package com.redhat.devtools.intellij.kubernetes.actions
12
12
13
+ import com.intellij.icons.AllIcons
13
14
import com.intellij.openapi.actionSystem.AnActionEvent
14
15
import com.intellij.openapi.diagnostic.logger
15
16
import com.intellij.openapi.progress.Progressive
@@ -23,6 +24,7 @@ import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService
23
24
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.PROP_RESOURCE_KIND
24
25
import com.redhat.devtools.intellij.kubernetes.telemetry.TelemetryService.getKinds
25
26
import io.fabric8.kubernetes.api.model.HasMetadata
27
+ import javax.swing.JCheckBox
26
28
import javax.swing.tree.TreePath
27
29
28
30
class DeleteResourceAction : StructureTreeAction () {
@@ -34,15 +36,16 @@ class DeleteResourceAction: StructureTreeAction() {
34
36
override fun actionPerformed (event : AnActionEvent ? , path : Array <out TreePath >? , selected : Array <out Any >? ) {
35
37
val model = getResourceModel() ? : return
36
38
val toDelete = selected?.map { it.getDescriptor()?.element as HasMetadata } ? : return
37
- if (! userConfirmed(toDelete)) {
39
+ val operation = userConfirms(toDelete)
40
+ if (operation.isNo) {
38
41
return
39
42
}
40
43
run (" Deleting ${toMessage(toDelete, 30 )} ..." , true ,
41
44
Progressive {
42
45
val telemetry = TelemetryService .instance.action(" delete resource" )
43
46
.property(PROP_RESOURCE_KIND , getKinds(toDelete))
44
47
try {
45
- model.delete(toDelete)
48
+ model.delete(toDelete, operation.isForce )
46
49
Notification ().info(" Resources Deleted" , toMessage(toDelete, 30 ))
47
50
telemetry.success().send()
48
51
} catch (e: MultiResourceException ) {
@@ -54,12 +57,18 @@ class DeleteResourceAction: StructureTreeAction() {
54
57
})
55
58
}
56
59
57
- private fun userConfirmed (resources : List <HasMetadata >): Boolean {
58
- val answer = Messages .showYesNoDialog (
60
+ private fun userConfirms (resources : List <HasMetadata >): DeleteOperation {
61
+ val answer = Messages .showCheckboxMessageDialog (
59
62
" Delete ${toMessage(resources, 30 )} ?" ,
60
- " Delete resources?" ,
61
- Messages .getQuestionIcon())
62
- return answer == Messages .OK
63
+ " Delete" ,
64
+ arrayOf(Messages .getYesButton(), Messages .getNoButton()),
65
+ " Force (immediate)" ,
66
+ false ,
67
+ 0 ,
68
+ 0 ,
69
+ AllIcons .General .QuestionDialog ,
70
+ DeleteOperation .processDialogReturnValue)
71
+ return DeleteOperation (answer)
63
72
}
64
73
65
74
override fun isVisible (selected : Array <out Any >? ): Boolean {
@@ -72,4 +81,29 @@ class DeleteResourceAction: StructureTreeAction() {
72
81
return element != null
73
82
&& ! hasDeletionTimestamp(element)
74
83
}
75
- }
84
+
85
+ private class DeleteOperation (private val dialogReturn : Int ) {
86
+
87
+ companion object {
88
+ const val FORCE_MASK = 0b1000000
89
+
90
+ val processDialogReturnValue = { exitCode: Int , checkbox: JCheckBox ->
91
+ if (exitCode == - 1 ) {
92
+ Messages .CANCEL
93
+ } else {
94
+ exitCode or (if (checkbox.isSelected) FORCE_MASK else 0 )
95
+ }
96
+ }
97
+ }
98
+
99
+ val isForce: Boolean
100
+ get() {
101
+ return (dialogReturn and FORCE_MASK ) == FORCE_MASK
102
+ }
103
+
104
+ val isNo: Boolean
105
+ get() {
106
+ return (dialogReturn and Messages .NO ) == Messages .NO
107
+ }
108
+ }
109
+ }
0 commit comments