@@ -11,6 +11,58 @@ import com.intellij.openapi.diagnostic.thisLogger
11
11
import io.gitpod.gitpodprotocol.api.entities.WorkspaceTimeoutDuration
12
12
import io.gitpod.jetbrains.remote.GitpodManager
13
13
import com.intellij.notification.NotificationType
14
+ import com.intellij.openapi.ui.DialogWrapper
15
+ import com.intellij.openapi.ui.ValidationInfo
16
+ import javax.swing.JComponent
17
+ import javax.swing.JTextField
18
+ import javax.swing.JPanel
19
+ import javax.swing.JComboBox
20
+ import javax.swing.BoxLayout
21
+
22
+ fun validate (duration : String ): String {
23
+ try {
24
+ duration.toInt()
25
+ } catch (e: NumberFormatException ) {
26
+ throw IllegalArgumentException (" Duration must be an integer" )
27
+ }
28
+
29
+ return duration
30
+ }
31
+
32
+ class InputDurationDialog : DialogWrapper (null , true ) {
33
+ private val textField = JTextField (10 )
34
+ private val unitComboBox = JComboBox (arrayOf(" minutes" , " hours" ))
35
+
36
+ init {
37
+ init ()
38
+ title = " Set timeout duration"
39
+ }
40
+
41
+ override fun createCenterPanel (): JComponent {
42
+ val customComponent = JPanel ()
43
+ customComponent.layout = BoxLayout (customComponent, BoxLayout .X_AXIS )
44
+ customComponent.add(textField)
45
+ customComponent.add(unitComboBox)
46
+
47
+ textField.text = " 180"
48
+
49
+ return customComponent
50
+ }
51
+
52
+ override fun doValidate (): ValidationInfo ? {
53
+ try {
54
+ validate(textField.text)
55
+ return null
56
+ } catch (e: IllegalArgumentException ) {
57
+ return ValidationInfo (e.message ? : " An unknown error has occured" , textField)
58
+ }
59
+ }
60
+
61
+ fun getDuration (): String {
62
+ val selectedUnit = unitComboBox.selectedItem.toString()
63
+ return " ${textField.text}${selectedUnit[0 ]} "
64
+ }
65
+ }
14
66
15
67
class ExtendWorkspaceTimeoutAction : AnAction () {
16
68
private val manager = service<GitpodManager >()
@@ -21,26 +73,25 @@ class ExtendWorkspaceTimeoutAction : AnAction() {
21
73
" action" to " extend-timeout"
22
74
))
23
75
24
- manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, WorkspaceTimeoutDuration .DURATION_180M .toString()).whenComplete { result, e ->
25
- var message: String
26
- var notificationType: NotificationType
27
-
28
- if (e != null ) {
29
- message = " Cannot extend workspace timeout: ${e.message} "
30
- notificationType = NotificationType .ERROR
31
- thisLogger().error(" gitpod: failed to extend workspace timeout" , e)
32
- } else {
33
- if (result.resetTimeoutOnWorkspaces.isNotEmpty()) {
34
- message = " Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces."
35
- notificationType = NotificationType .WARNING
76
+ val dialog = InputDurationDialog ()
77
+ if (dialog.showAndGet()) {
78
+ val duration = dialog.getDuration()
79
+ manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, duration.toString()).whenComplete { _, e ->
80
+ var message: String
81
+ var notificationType: NotificationType
82
+
83
+ if (e != null ) {
84
+ message = " Cannot extend workspace timeout: ${e.message} "
85
+ notificationType = NotificationType .ERROR
86
+ thisLogger().error(" gitpod: failed to extend workspace timeout" , e)
36
87
} else {
37
- message = " Workspace timeout has been extended to three hours ."
88
+ message = " Workspace timeout has been extended to ${duration} ."
38
89
notificationType = NotificationType .INFORMATION
39
90
}
40
- }
41
91
42
- val notification = manager.notificationGroup.createNotification(message, notificationType)
43
- notification.notify(null )
92
+ val notification = manager.notificationGroup.createNotification(message, notificationType)
93
+ notification.notify(null )
94
+ }
44
95
}
45
96
}
46
97
}
0 commit comments