how can I bind value of a JCheckBox to enabling and disabling rows in a LayoutBuilder using Kotlin. (in Configurable::createComponent)

Answered

So, following on from my previous question. I'm now adding some fields to do with proxy settings into my createComponent() method, like this:

override fun createComponent(): JComponent = com.intellij.ui.layout.panel {
titledRow("Proxy Settings") {}
row("Use Proxy") { CheckBox("enabled", false)() }
row("host") { JBTextField()(push) }
row("port") { JBTextField()(push) }
}

 

I'd like to dynamically enabled/disable the host and port inputs when the user checks the box for enable proxy. I tried instantiating the Checkbox in the line before so that I could set the rows (for host & port) to enabled based on it's value but that didn't work. Any ideas?

This is a theme that I'll be reusing all over the settings page as I have a lot of fields that are dependant on the choices of related inputs.

0
5 comments
Official comment

See com.intellij.util.net.HttpConfigurable

As before, I've got it working so will show my code:

override fun createComponent(): JComponent = com.intellij.ui.layout.panel {
titledRow("Proxy Settings") {}
val proxyEnabled = CheckBox("enabled", false)
row("Use Proxy") { proxyEnabled() }
row("host") {
val hostField = JBTextField()
hostField.isEditable = proxyEnabled.isSelected
proxyEnabled.addActionListener { hostField.isEditable = proxyEnabled.isSelected }
hostField(push)
}
row("port") {
val portField = JBTextField()
portField.isEditable = proxyEnabled.isSelected
proxyEnabled.addActionListener { portField.isEditable = proxyEnabled.isSelected }
portField(push)
}
// and same again for user/password
}

 

This results in my settings looking like:

 

 

So I'm fairly happy but would like to know the following:

  1. how can I get my JBTextFields to be the same width as the JBPasswordField?
  2. is there a better way to do this?
  3. should I be removing those listeners in disposeUIResources()?
0

Do you really need separate Proxy configuration than the one shared from IDE settings? Preferences | Appearance & Behavior | System Settings | HTTP Proxy

 

(3) no

0

Good point. The proxy settings are an example of the kind of thing I'm doing in the settings for this plugin. In the case of the proxy though, perhaps a good experience would be to keep the checkbox and display the values that would be used if enabled with a link to the IDE wide proxy settings if the user wants to change them. If you can provide any pointers in getting that information I'll give it a go.

0

In case anyone else wants to access IDE proxy settings, this is what I'm doing to give the user the option of using them in my plugin:

titledRow("Proxy Settings") { }
row() {
cell {
CheckBox("Use IDE proxy settings", true)()
if(ideHttpSettings != null && ideHttpSettings.USE_HTTP_PROXY && ideHttpSettings.PROXY_HOST.isNotEmpty()) {
JLabel("(${ideHttpSettings.PROXY_HOST}:${ideHttpSettings.PROXY_PORT})")()
} else {
JLabel("(no proxy configured)")()
}
}
noteRow("Change IDE's <a href=\"\">http settings</a>") {
ShowSettingsUtil.getInstance().showSettingsDialog(project, HttpProxyConfigurable::class.java)
}
}
0

Please sign in to leave a comment.