@@ -108,16 +108,9 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
108
108
109
109
private var tfUrl: JTextField ? = null
110
110
private var cbExistingToken: JCheckBox ? = null
111
- private var listTableModelOfWorkspaces = ListTableModel <WorkspaceAgentModel >(
112
- WorkspaceIconColumnInfo (" " ),
113
- WorkspaceNameColumnInfo (" Name" ),
114
- WorkspaceTemplateNameColumnInfo (" Template" ),
115
- WorkspaceVersionColumnInfo (" Version" ),
116
- WorkspaceStatusColumnInfo (" Status" )
117
- )
118
111
119
112
private val notificationBanner = NotificationBanner ()
120
- private var tableOfWorkspaces = TableView (listTableModelOfWorkspaces ).apply {
113
+ private var tableOfWorkspaces = WorkspacesTable ( ).apply {
121
114
setEnableAntialiasing(true )
122
115
rowSelectionAllowed = true
123
116
columnSelectionAllowed = false
@@ -348,7 +341,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
348
341
}
349
342
350
343
override fun onInit (wizardModel : CoderWorkspacesWizardModel ) {
351
- listTableModelOfWorkspaces .items = emptyList()
344
+ tableOfWorkspaces.listTableModel .items = emptyList()
352
345
if (localWizardModel.coderURL.isNotBlank() && localWizardModel.token != null ) {
353
346
triggerWorkspacePolling(true )
354
347
} else {
@@ -454,7 +447,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
454
447
// Clear out old deployment details.
455
448
poller?.cancel()
456
449
tableOfWorkspaces.setEmptyState(" Connecting to $deploymentURL ..." )
457
- listTableModelOfWorkspaces .items = emptyList()
450
+ tableOfWorkspaces.listTableModel .items = emptyList()
458
451
459
452
// Authenticate and load in a background process with progress.
460
453
// TODO: Make this cancelable.
@@ -676,11 +669,9 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
676
669
}
677
670
}
678
671
withContext(Dispatchers .Main ) {
679
- val selectedWorkspace = tableOfWorkspaces.selectedObject?.name
680
- listTableModelOfWorkspaces.items = ws.toList()
681
- if (selectedWorkspace != null ) {
682
- tableOfWorkspaces.selectItem(selectedWorkspace)
683
- }
672
+ val selectedWorkspace = tableOfWorkspaces.selectedObject
673
+ tableOfWorkspaces.listTableModel.items = ws.toList()
674
+ tableOfWorkspaces.selectItem(selectedWorkspace)
684
675
}
685
676
}
686
677
@@ -764,7 +755,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
764
755
else CoderCLIManager .getDataDir(),
765
756
settings.binarySource,
766
757
)
767
- cliManager.configSsh(listTableModelOfWorkspaces .items)
758
+ cliManager.configSsh(tableOfWorkspaces .items)
768
759
769
760
logger.info(" Opening IDE and Project Location window for ${workspace.name} " )
770
761
return true
@@ -776,6 +767,18 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
776
767
cs.cancel()
777
768
}
778
769
770
+ companion object {
771
+ val logger = Logger .getInstance(CoderWorkspacesStepView ::class .java.simpleName)
772
+ }
773
+ }
774
+
775
+ class WorkspacesTableModel : ListTableModel <WorkspaceAgentModel >(
776
+ WorkspaceIconColumnInfo (""),
777
+ WorkspaceNameColumnInfo ("Name "),
778
+ WorkspaceTemplateNameColumnInfo ("Template "),
779
+ WorkspaceVersionColumnInfo ("Version "),
780
+ WorkspaceStatusColumnInfo ("Status ")
781
+ ) {
779
782
private class WorkspaceIconColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
780
783
override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
781
784
return workspace?.templateName
@@ -803,7 +806,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
803
806
}
804
807
}
805
808
806
- private inner class WorkspaceNameColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
809
+ private class WorkspaceNameColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
807
810
override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
808
811
return workspace?.name
809
812
}
@@ -822,15 +825,16 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
822
825
text = value
823
826
}
824
827
825
- font = RelativeFont .BOLD .derive(this @CoderWorkspacesStepView.tableOfWorkspaces .tableHeader.font)
828
+ font = RelativeFont .BOLD .derive(table .tableHeader.font)
826
829
border = JBUI .Borders .empty(0 , 8 )
827
830
return this
828
831
}
829
832
}
830
833
}
831
834
}
832
835
833
- private inner class WorkspaceTemplateNameColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
836
+ private class WorkspaceTemplateNameColumnInfo (columnName : String ) :
837
+ ColumnInfo <WorkspaceAgentModel , String >(columnName) {
834
838
override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
835
839
return workspace?.templateName
836
840
}
@@ -842,11 +846,6 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
842
846
}
843
847
844
848
override fun getRenderer (item : WorkspaceAgentModel ? ): TableCellRenderer {
845
- val simpleH3 = this @CoderWorkspacesStepView.tableOfWorkspaces.tableHeader.font
846
-
847
- val h3AttributesWithUnderlining = simpleH3.attributes as MutableMap <TextAttribute , Any >
848
- h3AttributesWithUnderlining[TextAttribute .UNDERLINE ] = UNDERLINE_ON
849
- val underlinedH3 = JBFont .h3().deriveFont(h3AttributesWithUnderlining)
850
849
return object : DefaultTableCellRenderer () {
851
850
override fun getTableCellRendererComponent (table : JTable , value : Any , isSelected : Boolean , hasFocus : Boolean , row : Int , column : Int ): Component {
852
851
super .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
@@ -855,10 +854,13 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
855
854
}
856
855
border = JBUI .Borders .empty(0 , 8 )
857
856
857
+ val simpleH3 = table.tableHeader.font
858
858
if (table.getClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW ) != null ) {
859
859
val mouseOverRow = table.getClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW ) as Int
860
860
if (mouseOverRow >= 0 && mouseOverRow == row) {
861
- font = underlinedH3
861
+ val h3AttributesWithUnderlining = simpleH3.attributes as MutableMap <TextAttribute , Any >
862
+ h3AttributesWithUnderlining[TextAttribute .UNDERLINE ] = UNDERLINE_ON
863
+ font = JBFont .h3().deriveFont(h3AttributesWithUnderlining)
862
864
return this
863
865
}
864
866
}
@@ -869,7 +871,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
869
871
}
870
872
}
871
873
872
- private inner class WorkspaceVersionColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
874
+ private class WorkspaceVersionColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
873
875
override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
874
876
return workspace?.status?.label
875
877
}
@@ -881,15 +883,15 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
881
883
if (value is String ) {
882
884
text = value
883
885
}
884
- font = this @CoderWorkspacesStepView.tableOfWorkspaces .tableHeader.font
886
+ font = table .tableHeader.font
885
887
border = JBUI .Borders .empty(0 , 8 )
886
888
return this
887
889
}
888
890
}
889
891
}
890
892
}
891
893
892
- private inner class WorkspaceStatusColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
894
+ private class WorkspaceStatusColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
893
895
override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
894
896
return workspace?.agentStatus?.label
895
897
}
@@ -902,41 +904,48 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
902
904
903
905
override fun getRenderer (item : WorkspaceAgentModel ? ): TableCellRenderer {
904
906
return object : DefaultTableCellRenderer () {
905
- override fun getTableCellRendererComponent (
906
- table : JTable ,
907
- value : Any ,
908
- isSelected : Boolean ,
909
- hasFocus : Boolean ,
910
- row : Int ,
911
- column : Int ,
912
- ): Component {
907
+ override fun getTableCellRendererComponent (table : JTable , value : Any , isSelected : Boolean , hasFocus : Boolean , row : Int , column : Int ): Component {
913
908
super .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
914
909
if (value is String ) {
915
910
text = value
916
911
foreground = WorkspaceAndAgentStatus .from(value).statusColor()
917
912
toolTipText = WorkspaceAndAgentStatus .from(value).description
918
913
}
919
- font = this @CoderWorkspacesStepView.tableOfWorkspaces .tableHeader.font
914
+ font = table .tableHeader.font
920
915
border = JBUI .Borders .empty(0 , 8 )
921
916
return this
922
917
}
923
918
}
924
919
}
925
920
}
921
+ }
926
922
927
- private fun TableView<WorkspaceAgentModel>.selectItem (workspaceName : String? ) {
928
- if (workspaceName != null ) {
929
- this .items.forEachIndexed { index, workspaceAgentModel ->
930
- if (workspaceAgentModel.name == workspaceName) {
931
- selectionModel.addSelectionInterval(convertRowIndexToView(index), convertRowIndexToView(index))
932
- // fix cell selection case
933
- columnModel.selectionModel.addSelectionInterval(0 , columnCount - 1 )
934
- }
935
- }
923
+ class WorkspacesTable : TableView <WorkspaceAgentModel >(WorkspacesTableModel ()) {
924
+ /* *
925
+ * Given either a workspace or an agent select in order of preference:
926
+ * 1. That same agent or workspace.
927
+ * 2. The first match for the workspace (workspace itself or first agent).
928
+ */
929
+ fun selectItem (workspace : WorkspaceAgentModel ? ) {
930
+ val index = getNewSelection(workspace)
931
+ if (index > - 1 ) {
932
+ selectionModel.addSelectionInterval(convertRowIndexToView(index), convertRowIndexToView(index))
933
+ // Fix cell selection case.
934
+ columnModel.selectionModel.addSelectionInterval(0 , columnCount - 1 )
936
935
}
937
936
}
938
937
939
- companion object {
940
- val logger = Logger .getInstance(CoderWorkspacesStepView ::class .java.simpleName)
938
+ private fun getNewSelection (oldSelection : WorkspaceAgentModel ? ): Int {
939
+ if (oldSelection == null ) {
940
+ return - 1
941
+ }
942
+ val index = listTableModel.items.indexOfFirst {
943
+ it.name == oldSelection.name && it.workspaceName == oldSelection.workspaceName
944
+ }
945
+ if (index > - 1 ) {
946
+ return index
947
+ }
948
+ return listTableModel.items.indexOfFirst { it.workspaceName == oldSelection.workspaceName }
941
949
}
950
+
942
951
}
0 commit comments