@@ -20,9 +20,11 @@ import com.coder.gateway.util.DialogUi
2020import com.coder.gateway.util.InvalidVersionException
2121import com.coder.gateway.util.OS
2222import com.coder.gateway.util.SemVer
23+ import com.coder.gateway.util.WebUrlValidationResult
2324import com.coder.gateway.util.humanizeConnectionError
2425import com.coder.gateway.util.isCancellation
2526import com.coder.gateway.util.toURL
27+ import com.coder.gateway.util.validateStrictWebUrl
2628import com.coder.gateway.util.withoutNull
2729import com.intellij.icons.AllIcons
2830import com.intellij.ide.ActivityTracker
@@ -78,6 +80,8 @@ import javax.swing.JLabel
7880import javax.swing.JTable
7981import javax.swing.JTextField
8082import javax.swing.ListSelectionModel
83+ import javax.swing.event.DocumentEvent
84+ import javax.swing.event.DocumentListener
8185import javax.swing.table.DefaultTableCellRenderer
8286import javax.swing.table.TableCellRenderer
8387
@@ -133,7 +137,6 @@ class CoderWorkspacesStepView :
133137 private var tfUrl: JTextField ? = null
134138 private var tfUrlComment: JLabel ? = null
135139 private var cbExistingToken: JCheckBox ? = null
136- private var cbFallbackOnSignature: JCheckBox ? = null
137140
138141 private val notificationBanner = NotificationBanner ()
139142 private var tableOfWorkspaces =
@@ -219,6 +222,31 @@ class CoderWorkspacesStepView :
219222 // Reconnect when the enter key is pressed.
220223 maybeAskTokenThenConnect()
221224 }
225+ // Add document listener to clear error when user types
226+ document.addDocumentListener(object : DocumentListener {
227+ override fun insertUpdate (e : DocumentEvent ? ) = clearErrorState()
228+ override fun removeUpdate (e : DocumentEvent ? ) = clearErrorState()
229+ override fun changedUpdate (e : DocumentEvent ? ) = clearErrorState()
230+
231+ private fun clearErrorState () {
232+ tfUrlComment?.apply {
233+ foreground = UIUtil .getContextHelpForeground()
234+ if (tfUrl?.text.equals(client?.url?.toString())) {
235+ text =
236+ CoderGatewayBundle .message(
237+ " gateway.connector.view.coder.workspaces.connect.text.connected" ,
238+ client!! .url.host,
239+ )
240+ } else {
241+ text = CoderGatewayBundle .message(
242+ " gateway.connector.view.coder.workspaces.connect.text.comment" ,
243+ CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text" ),
244+ )
245+ }
246+ icon = null
247+ }
248+ }
249+ })
222250 }.component
223251 button(CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text" )) {
224252 // Reconnect when the connect button is pressed.
@@ -268,15 +296,15 @@ class CoderWorkspacesStepView :
268296 }
269297 row {
270298 cell() // For alignment.
271- checkBox(CoderGatewayBundle .message(" gateway.connector.settings.fallback-on-coder-for-signatures.title" ))
272- .bindSelected(state::fallbackOnCoderForSignatures).applyToComponent {
273- addActionListener { event ->
274- state.fallbackOnCoderForSignatures = (event.source as JBCheckBox ).isSelected
275- }
299+ checkBox(CoderGatewayBundle .message(" gateway.connector.settings.fallback-on-coder-for-signatures.title" ))
300+ .bindSelected(state::fallbackOnCoderForSignatures).applyToComponent {
301+ addActionListener { event ->
302+ state.fallbackOnCoderForSignatures = (event.source as JBCheckBox ).isSelected
276303 }
277- .comment(
278- CoderGatewayBundle .message(" gateway.connector.settings.fallback-on-coder-for-signatures.comment" ),
279- )
304+ }
305+ .comment(
306+ CoderGatewayBundle .message(" gateway.connector.settings.fallback-on-coder-for-signatures.comment" ),
307+ )
280308
281309 }.layout(RowLayout .PARENT_GRID )
282310 row {
@@ -539,6 +567,15 @@ class CoderWorkspacesStepView :
539567 component.apply () // Force bindings to be filled.
540568 val newURL = fields.coderURL.toURL()
541569 if (settings.requireTokenAuth) {
570+ val result = newURL.toURI().validateStrictWebUrl()
571+ if (result is WebUrlValidationResult .Invalid ) {
572+ tfUrlComment.apply {
573+ this ?.foreground = UIUtil .getErrorForeground()
574+ this ?.text = result.reason
575+ this ?.icon = UIUtil .getBalloonErrorIcon()
576+ }
577+ return
578+ }
542579 val pastedToken =
543580 dialogUi.askToken(
544581 newURL,
0 commit comments