Skip to content

Commit f5d8436

Browse files
committed
impl: ability to open templates in the dashboard
- allows user to click anywhere on the Coder Template column and open up the template in the dashboard
1 parent 88580d7 commit f5d8436

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
## Unreleased
66

7+
### Added
8+
- ability to open a template in the Dashboard
9+
710
## 2.1.3 - 2022-12-09
811

912
### Added

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

+65-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ import kotlinx.coroutines.withContext
6868
import org.zeroturnaround.exec.ProcessExecutor
6969
import java.awt.Component
7070
import java.awt.Dimension
71+
import java.awt.event.MouseEvent
72+
import java.awt.event.MouseListener
73+
import java.awt.event.MouseMotionListener
74+
import java.awt.font.TextAttribute
75+
import java.awt.font.TextAttribute.UNDERLINE_ON
7176
import javax.swing.Icon
7277
import javax.swing.JTable
7378
import javax.swing.JTextField
@@ -80,6 +85,8 @@ private const val CODER_URL_KEY = "coder-url"
8085

8186
private const val SESSION_TOKEN = "session-token"
8287

88+
private const val MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW = "MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW"
89+
8390
class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : CoderWorkspacesWizardStep, Disposable {
8491
private val cs = CoroutineScope(Dispatchers.Main)
8592
private var localWizardModel = CoderWorkspacesWizardModel()
@@ -123,6 +130,49 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
123130
}
124131
updateWorkspaceActions()
125132
}
133+
134+
addMouseListener(object : MouseListener {
135+
override fun mouseClicked(e: MouseEvent?) {
136+
if (e?.source is TableView<*>) {
137+
val tblView = e.source as TableView<WorkspaceAgentModel>
138+
val col = tblView.selectedColumn
139+
val workspace = tblView.selectedObject
140+
141+
if (col == 2 && workspace != null) {
142+
BrowserUtil.browse(coderClient.coderURL.toURI().resolve("/templates/${workspace.templateName}"))
143+
}
144+
}
145+
}
146+
147+
override fun mousePressed(e: MouseEvent?) {
148+
}
149+
150+
override fun mouseReleased(e: MouseEvent?) {
151+
}
152+
153+
override fun mouseEntered(e: MouseEvent?) {
154+
}
155+
156+
override fun mouseExited(e: MouseEvent?) {
157+
}
158+
})
159+
addMouseMotionListener(object : MouseMotionListener {
160+
override fun mouseMoved(e: MouseEvent?) {
161+
if (e?.source is TableView<*>) {
162+
val tblView = e.source as TableView<WorkspaceAgentModel>
163+
val row = tblView.rowAtPoint(e.point)
164+
if (tblView.columnAtPoint(e.point) == 2 && row in 0 until tblView.listTableModel.rowCount) {
165+
tblView.putClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW, row)
166+
} else {
167+
tblView.putClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW, -1)
168+
}
169+
}
170+
171+
}
172+
173+
override fun mouseDragged(e: MouseEvent?) {
174+
}
175+
})
126176
}
127177

128178
private val goToDashboardAction = GoToDashboardAction()
@@ -570,7 +620,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
570620

571621
override fun getTableCellRendererComponent(table: JTable?, value: Any?, selected: Boolean, focus: Boolean, row: Int, column: Int): Component {
572622
super.getTableCellRendererComponent(table, value, selected, focus, row, column).apply {
573-
border = JBUI.Borders.empty(10, 10)
623+
border = JBUI.Borders.empty(10)
574624
}
575625
return this
576626
}
@@ -604,14 +654,27 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
604654
}
605655

606656
override fun getRenderer(item: WorkspaceAgentModel?): TableCellRenderer {
657+
val simpleH3 = JBFont.h3()
658+
659+
val h3AttributesWithUnderlining = simpleH3.attributes as MutableMap<TextAttribute, Any>
660+
h3AttributesWithUnderlining[TextAttribute.UNDERLINE] = UNDERLINE_ON
661+
val underlinedH3 = JBFont.h3().deriveFont(h3AttributesWithUnderlining)
607662
return object : DefaultTableCellRenderer() {
608663
override fun getTableCellRendererComponent(table: JTable, value: Any, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component {
609664
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
610665
if (value is String) {
611666
text = value
612667
}
613-
font = JBFont.h3()
614668
border = JBUI.Borders.empty()
669+
670+
if (table.getClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW) != null) {
671+
val mouseOverRow = table.getClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW) as Int
672+
if (mouseOverRow >= 0 && mouseOverRow == row) {
673+
font = underlinedH3
674+
return this
675+
}
676+
}
677+
font = simpleH3
615678
return this
616679
}
617680
}

0 commit comments

Comments
 (0)