DSL UI v2 Binding an Enum and Observable Pattern
Hello! I am developing a plugin for python code generation. I am making a popup window with a preview of the generated code. I am trying to take advantage of the bindings feature in the DSL UI, but I am having trouble.
Here is what the popup looks like:
Here is the code that generates that menu: https://github.com/CJCrafter/PythonGettersAndSetters/blob/master/src/main/kotlin/me/cjcrafter/pygetset/GenerateToString.kt#L47-L78
SO HERE IS THE ACTUAL QUESTION
How can I "observe" these changes? How can I bind the value and run a method onValueChange? Currently trying to bind the values to a "model class" and I am using a MapWrapper with a callback. But when I debug this with breakpoints:
The code never reaches the break points (no matter which button in the UI I push.)
Please sign in to leave a comment.
Hi Collin,
In general, Kotlin UI DSL should be used for building forms that are bound to state objects, like settings, and it looks that your case doesn't match it. Kotlin UI DSL fields are bound to the backing object properties when DialogPanel.apply() is invoked (DialogPanel is the object created by `panel {}`).
In your case I suggest using Swing component listeners and adjust other components based on the events.
Thanks for your advice. Swing components solved my problem. As a follow up, I am trying to find examples of the segmentedButton (specifically how they did the binding). I cannot find the code for this tab in IntelliJ's examples (maybe it is outdated?). I would love to use segmented buttons, they look much better then radio buttons. Thank you!

Hi Collin,
The panel implementation is here: https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/internal/ui/uiDslTestAction/SegmentedButtonPanel.kt
I recommend finding such things by searching for UI texts in intellij-community project or using UI Inspector. You can also find more example of using SegmentedButton in the intellij-community project code.
I've made sure to use latest^, but these methods don't seem to exist.
This is the decompiled class for SegmentedButton and I don't see those methods.
Hi Collin,
These methods are pretty new. Please see the history of the SegmentedButton.kt file.
I guess you are using an older platform version. Also, note that the SegmentedButton is in experimental status and and may be changed over time without preserving backward compatibility.
In general, I suggest checking out the community sources. It is a common workflow to analyze the sources to understand what is available or how different APIs are used.
how to use SegmentedButton in swing panel
Hi,
SegmentedButton was implemented specifically for Kotlin UI DSL. If it doesn't expose any getComponent method you can utilize in Swing, I'm afraid you can't use it and you will need to implement your own solution.