Skip to content

Template name as hyperlinks #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## Unreleased

### Added
- ability to open a template in the Dashboard

### Changed
- renamed the plugin from `Coder Gateway` to `Gateway`

## 2.1.3 - 2022-12-09

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ import kotlinx.coroutines.withContext
import org.zeroturnaround.exec.ProcessExecutor
import java.awt.Component
import java.awt.Dimension
import java.awt.event.MouseEvent
import java.awt.event.MouseListener
import java.awt.event.MouseMotionListener
import java.awt.font.TextAttribute
import java.awt.font.TextAttribute.UNDERLINE_ON
import javax.swing.Icon
import javax.swing.JTable
import javax.swing.JTextField
Expand All @@ -80,6 +85,8 @@ private const val CODER_URL_KEY = "coder-url"

private const val SESSION_TOKEN = "session-token"

private const val MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW = "MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW"

class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : CoderWorkspacesWizardStep, Disposable {
private val cs = CoroutineScope(Dispatchers.Main)
private var localWizardModel = CoderWorkspacesWizardModel()
Expand Down Expand Up @@ -123,6 +130,49 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
}
updateWorkspaceActions()
}

addMouseListener(object : MouseListener {
override fun mouseClicked(e: MouseEvent?) {
if (e?.source is TableView<*>) {
val tblView = e.source as TableView<WorkspaceAgentModel>
val col = tblView.selectedColumn
val workspace = tblView.selectedObject

if (col == 2 && workspace != null) {
BrowserUtil.browse(coderClient.coderURL.toURI().resolve("/templates/${workspace.templateName}"))
}
}
}

override fun mousePressed(e: MouseEvent?) {
}

override fun mouseReleased(e: MouseEvent?) {
}

override fun mouseEntered(e: MouseEvent?) {
}

override fun mouseExited(e: MouseEvent?) {
}
})
addMouseMotionListener(object : MouseMotionListener {
override fun mouseMoved(e: MouseEvent?) {
if (e?.source is TableView<*>) {
val tblView = e.source as TableView<WorkspaceAgentModel>
val row = tblView.rowAtPoint(e.point)
if (tblView.columnAtPoint(e.point) == 2 && row in 0 until tblView.listTableModel.rowCount) {
tblView.putClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW, row)
} else {
tblView.putClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW, -1)
}
}

}

override fun mouseDragged(e: MouseEvent?) {
}
})
}

private val goToDashboardAction = GoToDashboardAction()
Expand Down Expand Up @@ -569,9 +619,10 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
override fun isCenterAlignment() = true

override fun getTableCellRendererComponent(table: JTable?, value: Any?, selected: Boolean, focus: Boolean, row: Int, column: Int): Component {
return super.getTableCellRendererComponent(table, value, selected, focus, row, column).apply {
border = JBUI.Borders.empty(10, 10)
super.getTableCellRendererComponent(table, value, selected, focus, row, column).apply {
border = JBUI.Borders.empty(10)
}
return this
}
}
}
Expand All @@ -590,6 +641,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
text = value
}
font = JBFont.h3().asBold()
border = JBUI.Borders.empty()
return this
}
}
Expand All @@ -602,13 +654,27 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
}

override fun getRenderer(item: WorkspaceAgentModel?): TableCellRenderer {
val simpleH3 = JBFont.h3()

val h3AttributesWithUnderlining = simpleH3.attributes as MutableMap<TextAttribute, Any>
h3AttributesWithUnderlining[TextAttribute.UNDERLINE] = UNDERLINE_ON
val underlinedH3 = JBFont.h3().deriveFont(h3AttributesWithUnderlining)
return object : DefaultTableCellRenderer() {
override fun getTableCellRendererComponent(table: JTable, value: Any, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
if (value is String) {
text = value
}
font = JBFont.h3()
border = JBUI.Borders.empty()

if (table.getClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW) != null) {
val mouseOverRow = table.getClientProperty(MOUSE_OVER_TEMPLATE_NAME_COLUMN_ON_ROW) as Int
if (mouseOverRow >= 0 && mouseOverRow == row) {
font = underlinedH3
return this
}
}
font = simpleH3
return this
}
}
Expand All @@ -628,6 +694,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
text = value
}
font = JBFont.h3()
border = JBUI.Borders.empty()
return this
}
}
Expand All @@ -647,6 +714,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
text = value
}
font = JBFont.h3()
border = JBUI.Borders.empty()
foreground = (table.model as ListTableModel<WorkspaceAgentModel>).getRowValue(row).statusColor()
return this
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<id>com.coder.gateway</id>
<name>Coder Gateway</name>
<name>Coder</name>
<vendor>Coder</vendor>

<!-- Product and plugin compatibility requirements -->
Expand Down