Skip to content

Commit

Permalink
fix: substitue link labels and insets with action link and jbinsets
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Apr 3, 2024
1 parent a5fd703 commit 7b012b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.snyk.plugin.ui.toolwindow.panels

import com.intellij.ui.components.labels.LinkLabel
import com.intellij.ui.components.ActionLink
import com.intellij.uiDesigner.core.GridLayoutManager
import com.intellij.util.ui.JBUI
import io.snyk.plugin.ui.addSpacer
import io.snyk.plugin.ui.baseGridConstraints
import io.snyk.plugin.ui.getReadOnlyClickableHtmlJEditorPaneFixedSize
import java.awt.Insets
import java.awt.event.ActionEvent
import javax.swing.JPanel

class StatePanel(messageHtmlText: String, actionText: String? = null, action: (() -> Unit)? = null) : JPanel() {
class StatePanel(messageHtmlText: String, actionText: String? = null, action: ((e: ActionEvent) -> Unit)? = null) : JPanel() {
init {
layout = GridLayoutManager(4, 1, Insets(20, 100, 20, 100), -1, -1)
layout = GridLayoutManager(4, 1, JBUI.insets(20, 100), -1, -1)

add(
getReadOnlyClickableHtmlJEditorPaneFixedSize(messageHtmlText),
Expand All @@ -19,7 +20,7 @@ class StatePanel(messageHtmlText: String, actionText: String? = null, action: ((

if (actionText != null && action != null) {
add(
LinkLabel.create(actionText, action),
ActionLink(actionText, action),
baseGridConstraints(row = 2, indent = 0)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.snyk.plugin.ui.toolwindow.panels

import com.intellij.ui.components.labels.LinkLabel
import com.intellij.ui.components.ActionLink
import com.intellij.uiDesigner.core.GridLayoutManager
import com.intellij.util.ui.JBUI
import io.snyk.plugin.ui.DescriptionHeaderPanel
import io.snyk.plugin.ui.addRowOfItemsToPanel
import io.snyk.plugin.ui.baseGridConstraintsAnchorWest
Expand All @@ -14,7 +15,6 @@ import io.snyk.plugin.ui.toolwindow.LabelProvider
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer
import snyk.oss.Vulnerability
import java.awt.Insets
import javax.swing.JLabel
import javax.swing.JPanel

Expand All @@ -32,7 +32,7 @@ class VulnerabilityDescriptionPanel(
override fun createMainBodyPanel(): Pair<JPanel, Int> {
val lastRowToAddSpacer = 4
val panel = JPanel(
GridLayoutManager(lastRowToAddSpacer + 1, 1, Insets(0, 10, 20, 20), -1, 10)
GridLayoutManager(lastRowToAddSpacer + 1, 1, JBUI.insets(0, 10, 20, 20), -1, 10)
).apply {
this.add(
getMainBodyPanel(),
Expand All @@ -52,7 +52,7 @@ class VulnerabilityDescriptionPanel(

private fun getMainBodyPanel(): JPanel {
val panel = JPanel()
panel.layout = GridLayoutManager(11, 2, Insets(10, 0, 20, 0), 30, -1)
panel.layout = GridLayoutManager(11, 2, JBUI.insets(10, 0, 20, 0), 30, -1)

panel.add(
boldLabel("Vulnerable module:"),
Expand Down Expand Up @@ -118,7 +118,7 @@ class VulnerabilityDescriptionPanel(
val panel = JPanel()
val packageManager = groupedVulns.first().packageManager

panel.layout = GridLayoutManager(1, intros.size * 2, Insets(0, 0, 0, 0), 0, 0)
panel.layout = GridLayoutManager(1, intros.size * 2, JBUI.emptyInsets(), 0, 0)

addRowOfItemsToPanel(
panel = panel,
Expand All @@ -133,7 +133,7 @@ class VulnerabilityDescriptionPanel(

private fun getDetailedPathsPanel(): JPanel {
val detailsPanel = JPanel()
detailsPanel.layout = GridLayoutManager(2, 2, Insets(0, 0, 0, 0), -1, -1)
detailsPanel.layout = GridLayoutManager(2, 2, JBUI.emptyInsets(), -1, -1)

detailsPanel.add(
boldLabel("Detailed paths").apply {
Expand All @@ -156,13 +156,13 @@ class VulnerabilityDescriptionPanel(

private fun getInnerDetailedPathsPanel(itemsToShow: Int? = null): JPanel {
val detailsPanel = JPanel()
detailsPanel.layout = GridLayoutManager(groupedVulns.size + 2, 2, Insets(0, 0, 0, 0), -1, -1)
detailsPanel.layout = GridLayoutManager(groupedVulns.size + 2, 2, JBUI.emptyInsets(), -1, -1)

groupedVulns
.take(itemsToShow ?: groupedVulns.size)
.forEachIndexed { index, vuln ->
val detailPanel = JPanel()
detailPanel.layout = GridLayoutManager(2, 2, Insets(0, 0, 0, 0), 30, 0)
detailPanel.layout = GridLayoutManager(2, 2, JBUI.emptyInsets(), 30, 0)

insertTitleAndResizableTextIntoPanelColumns(
panel = detailPanel,
Expand Down Expand Up @@ -191,7 +191,7 @@ class VulnerabilityDescriptionPanel(
}

if (itemsToShow != null && itemsToShow < groupedVulns.size) {
val showMoreLabel = LinkLabel.create("...and ${groupedVulns.size - itemsToShow} more") {
val showMoreLabel = ActionLink("...and ${groupedVulns.size - itemsToShow} more") {
detailsPanel.removeAll()
detailsPanel.add(
getInnerDetailedPathsPanel(),
Expand All @@ -211,7 +211,7 @@ class VulnerabilityDescriptionPanel(

private fun getOverviewPanel(): JPanel {
val overviewPanel = JPanel()
overviewPanel.layout = GridLayoutManager(2, 1, Insets(0, 5, 0, 0), -1, 0)
overviewPanel.layout = GridLayoutManager(2, 1, JBUI.insetsLeft(5), -1, 0)

val descriptionPane = getReadOnlyClickableHtmlJEditorPane(getDescriptionAsHtml())

Expand Down
18 changes: 9 additions & 9 deletions src/main/kotlin/snyk/container/ui/ContainerIssueDetailPanel.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package snyk.container.ui

import com.intellij.ui.components.labels.LinkLabel
import com.intellij.ui.components.ActionLink
import com.intellij.uiDesigner.core.GridLayoutManager
import com.intellij.util.ui.JBUI
import io.snyk.plugin.ui.DescriptionHeaderPanel
import io.snyk.plugin.ui.baseGridConstraintsAnchorWest
import io.snyk.plugin.ui.boldLabel
Expand All @@ -13,7 +14,6 @@ import io.snyk.plugin.ui.toolwindow.panels.IssueDescriptionPanelBase
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer
import snyk.container.ContainerIssue
import java.awt.Insets
import javax.swing.JPanel

class ContainerIssueDetailPanel(
Expand All @@ -29,7 +29,7 @@ class ContainerIssueDetailPanel(
override fun createMainBodyPanel(): Pair<JPanel, Int> {
val lastRowToAddSpacer = 4
val panel = JPanel(
GridLayoutManager(lastRowToAddSpacer + 1, 1, Insets(10, 10, 20, 20), -1, 10)
GridLayoutManager(lastRowToAddSpacer + 1, 1, JBUI.insets(10, 10, 20, 20), -1, 10)
)

panel.add(
Expand Down Expand Up @@ -61,7 +61,7 @@ class ContainerIssueDetailPanel(

private fun mainPanel(): JPanel {
val panel = JPanel(
GridLayoutManager(2, 2, Insets(0, 0, 0, 0), 30, -1)
GridLayoutManager(2, 2, JBUI.emptyInsets(), 30, -1)
)

val introducedThrough = groupedVulns
Expand Down Expand Up @@ -91,7 +91,7 @@ class ContainerIssueDetailPanel(

private fun getDetailedPathsPanel(): JPanel {
val detailsPanel = JPanel()
detailsPanel.layout = GridLayoutManager(2, 2, Insets(20, 0, 0, 0), -1, -1)
detailsPanel.layout = GridLayoutManager(2, 2, JBUI.insetsTop(20), -1, -1)

detailsPanel.add(
boldLabel("Detailed paths").apply {
Expand All @@ -114,13 +114,13 @@ class ContainerIssueDetailPanel(

private fun getInnerDetailedPathsPanel(itemsToShow: Int? = null): JPanel {
val detailsPanel = JPanel()
detailsPanel.layout = GridLayoutManager(groupedVulns.size + 2, 2, Insets(0, 0, 0, 0), -1, -1)
detailsPanel.layout = GridLayoutManager(groupedVulns.size + 2, 2, JBUI.emptyInsets(), -1, -1)

groupedVulns
.take(itemsToShow ?: groupedVulns.size)
.forEachIndexed { index, vuln ->
val detailPanel = JPanel()
detailPanel.layout = GridLayoutManager(2, 2, Insets(0, 0, 0, 0), 30, 5)
detailPanel.layout = GridLayoutManager(2, 2, JBUI.emptyInsets(), 30, 5)

insertTitleAndResizableTextIntoPanelColumns(
panel = detailPanel,
Expand All @@ -145,7 +145,7 @@ class ContainerIssueDetailPanel(
}

if (itemsToShow != null && itemsToShow < groupedVulns.size) {
val showMoreLabel = LinkLabel.create("...and ${groupedVulns.size - itemsToShow} more") {
val showMoreLabel = ActionLink("...and ${groupedVulns.size - itemsToShow} more") {
detailsPanel.removeAll()
detailsPanel.add(
getInnerDetailedPathsPanel(),
Expand All @@ -164,7 +164,7 @@ class ContainerIssueDetailPanel(
}

private fun overviewPanel(): JPanel {
val panel = JPanel(GridLayoutManager(2, 2, Insets(10, 5, 0, 0), -1, 0))
val panel = JPanel(GridLayoutManager(2, 2, JBUI.insets(10, 5, 0, 0), -1, 0))

val descriptionMarkdown = issue.description.replaceFirst("## NVD Description", "## Description")
val document = Parser.builder().build().parse(descriptionMarkdown)
Expand Down

0 comments on commit 7b012b9

Please sign in to comment.