Skip to content

Commit 0238b9f

Browse files
adietishqwencoder
andcommitted
feat: allow users to dbl click a workspace to connect to it (#23544)
Co-authored-by: Qwen-Coder <[email protected]>
1 parent 1cd2ceb commit 0238b9f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesWorkspacesStepView.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.redhat.devtools.gateway.openshift.Projects
3131
import com.redhat.devtools.gateway.openshift.Utils
3232
import com.redhat.devtools.gateway.util.messageWithoutPrefix
3333
import com.redhat.devtools.gateway.view.ui.Dialogs
34+
import com.redhat.devtools.gateway.view.ui.onDoubleClick
3435
import java.awt.Component
3536
import javax.swing.DefaultListModel
3637
import javax.swing.JButton
@@ -82,6 +83,11 @@ class DevSpacesWorkspacesStepView(private var devSpacesContext: DevSpacesContext
8283

8384
override fun onInit() {
8485
listDevWorkspaces.selectionModel.addListSelectionListener(DevWorkspaceSelection())
86+
listDevWorkspaces.onDoubleClick {
87+
if (!listDevWorkspaces.isSelectionEmpty) {
88+
connect()
89+
}
90+
}
8591
listDevWorkspaces.cellRenderer = DevWorkspaceListRenderer()
8692
listDevWorkspaces.setEmptyText(DevSpacesBundle.message("connector.wizard_step.remote_server_connection.list.empty_text"))
8793
refreshAllDevWorkspaces()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2024 Red Hat, Inc.
3+
* This program and the accompanying materials are made
4+
* available under the terms of the Eclipse Public License 2.0
5+
* which is available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Red Hat, Inc. - initial API and implementation
11+
*/
12+
package com.redhat.devtools.gateway.view.ui
13+
14+
import java.awt.event.MouseAdapter
15+
import java.awt.event.MouseEvent
16+
import javax.swing.JList
17+
18+
fun <T> JList<T>.onDoubleClick(action: (T) -> Unit) {
19+
addMouseListener(object : MouseAdapter() {
20+
override fun mouseClicked(e: MouseEvent) {
21+
if (e.clickCount == 2) {
22+
selectedValue?.let { action(it) }
23+
}
24+
}
25+
})
26+
}

0 commit comments

Comments
 (0)