@@ -68,6 +68,11 @@ import kotlinx.coroutines.withContext
68
68
import org.zeroturnaround.exec.ProcessExecutor
69
69
import java.awt.Component
70
70
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
71
76
import javax.swing.Icon
72
77
import javax.swing.JTable
73
78
import javax.swing.JTextField
@@ -80,6 +85,8 @@ private const val CODER_URL_KEY = "coder-url"
80
85
81
86
private const val SESSION_TOKEN = " session-token"
82
87
88
+ private const val MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW = " MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW"
89
+
83
90
class CoderWorkspacesStepView (val enableNextButtonCallback : (Boolean ) -> Unit ) : CoderWorkspacesWizardStep, Disposable {
84
91
private val cs = CoroutineScope (Dispatchers .Main )
85
92
private var localWizardModel = CoderWorkspacesWizardModel ()
@@ -123,6 +130,49 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
123
130
}
124
131
updateWorkspaceActions()
125
132
}
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
+ })
126
176
}
127
177
128
178
private val goToDashboardAction = GoToDashboardAction ()
@@ -570,7 +620,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
570
620
571
621
override fun getTableCellRendererComponent (table : JTable ? , value : Any? , selected : Boolean , focus : Boolean , row : Int , column : Int ): Component {
572
622
super .getTableCellRendererComponent(table, value, selected, focus, row, column).apply {
573
- border = JBUI .Borders .empty(10 , 10 )
623
+ border = JBUI .Borders .empty(10 )
574
624
}
575
625
return this
576
626
}
@@ -604,14 +654,27 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
604
654
}
605
655
606
656
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)
607
662
return object : DefaultTableCellRenderer () {
608
663
override fun getTableCellRendererComponent (table : JTable , value : Any , isSelected : Boolean , hasFocus : Boolean , row : Int , column : Int ): Component {
609
664
super .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
610
665
if (value is String ) {
611
666
text = value
612
667
}
613
- font = JBFont .h3()
614
668
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
615
678
return this
616
679
}
617
680
}
0 commit comments