1
1
package com.coder.gateway.views
2
2
3
- import com.jetbrains.toolbox.gateway.ui.RunnableActionDescription
4
- import com.jetbrains.toolbox.gateway.ui.UiField
5
- import com.jetbrains.toolbox.gateway.ui.UiPage
6
- import com.jetbrains.toolbox.gateway.ui.ValidationErrorField
3
+ import com.jetbrains.toolbox.api.core.ui.icons.SvgIcon
4
+ import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
5
+ import com.jetbrains.toolbox.api.ui.components.UiField
6
+ import com.jetbrains.toolbox.api.ui.components.UiPage
7
+ import com.jetbrains.toolbox.api.ui.components.ValidationErrorField
7
8
import org.slf4j.LoggerFactory
8
- import java.util.function.BiConsumer
9
9
import java.util.function.Consumer
10
- import java.util.function.Function
11
10
12
11
/* *
13
12
* Base page that handles the icon, displaying error notifications, and
@@ -35,7 +34,7 @@ abstract class CoderPage(
35
34
private var notifier: Consumer <Throwable >? = null
36
35
37
36
/* * Used to get field values. */
38
- private var getter : Function < UiField , * > ? = null
37
+ private var stateAccessor : UiPage . UiFieldStateAccessor ? = null
39
38
40
39
/* * Let Toolbox know the fields should be updated. */
41
40
protected var listener: Consumer <UiField ?>? = null
@@ -48,12 +47,13 @@ abstract class CoderPage(
48
47
*
49
48
* This seems to only work on the first page.
50
49
*/
51
- override fun getSvgIcon (): ByteArray =
52
- if (showIcon) {
53
- this ::class .java.getResourceAsStream(" /icon.svg" )?.readAllBytes() ? : byteArrayOf()
50
+ override fun getSvgIcon (): SvgIcon {
51
+ return if (showIcon) {
52
+ SvgIcon ( this ::class .java.getResourceAsStream(" /icon.svg" )?.readAllBytes() ? : byteArrayOf() )
54
53
} else {
55
- byteArrayOf()
54
+ SvgIcon ( byteArrayOf() )
56
55
}
56
+ }
57
57
58
58
/* *
59
59
* Show an error as a popup on this page.
@@ -70,9 +70,8 @@ abstract class CoderPage(
70
70
* TODO@JB: Is this really meant to be used with casting? I kind of expected
71
71
* to be able to do `myField.value`.
72
72
*/
73
- fun get (field : UiField ): Any {
74
- val getter = getter ? : throw Exception (" Page is not being displayed" )
75
- return getter.apply (field)
73
+ fun get (field : UiField ): Any? {
74
+ return stateAccessor?.get(field)
76
75
}
77
76
78
77
/* *
@@ -82,11 +81,9 @@ abstract class CoderPage(
82
81
this .listener = listener
83
82
}
84
83
85
- /* *
86
- * The setter is unused but the getter is used to get field values.
87
- */
88
- override fun setStateAccessor (setter : BiConsumer <UiField , Any >? , getter : Function <UiField , * >? ) {
89
- this .getter = getter
84
+
85
+ override fun setStateAccessor (stateAccessor : UiPage .UiFieldStateAccessor ? ) {
86
+ this .stateAccessor = stateAccessor
90
87
}
91
88
92
89
/* *
0 commit comments