Skip to content

Commit 7df21cf

Browse files
authored
Fix exception from invisible JBMenuItem (#53)
1 parent db829df commit 7df21cf

6 files changed

Lines changed: 40 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
## [Unreleased]
66

7+
## [0.0.4] - 2025.07.10
8+
9+
### What's Changed
10+
* Update changelog.md by @mohamead in [PR #51](https://github.com/statens-pensjonskasse/fiskeoye-plugin/pull/51)
11+
* Add vertical scrollbar when needed by @mohamead in [PR #52](https://github.com/statens-pensjonskasse/fiskeoye-plugin/pull/52)
12+
* Fix exception from invisible JBMenuItem in [PR #53](https://github.com/statens-pensjonskasse/fiskeoye-plugin/pull/53)
13+
14+
**Full Changelog**: https://github.com/statens-pensjonskasse/fiskeoye-plugin/compare/v0.0.3...v0.0.4
15+
716
## [0.0.3] - 2025.07.02
817

918
### What's Changed

src/main/kotlin/no/spk/fiskeoye/plugin/listeners/button/FileContentSearchListener.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ internal class FileContentSearchListener(private val fileContentPanel: FileConte
8888
) {
8989
SwingUtilities.invokeLater {
9090
val headerText = buildHeaderText(searchText, searchParams, elements.size)
91-
logger.info(headerText)
92-
9391
val model = buildTableModel(headerText, elements)
9492

9593
fileContentPanel.apply {

src/main/kotlin/no/spk/fiskeoye/plugin/ui/FileContentPanel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal class FileContentPanel : FiskeoyePanel() {
3737
this.caseSensitiveButton = buildCaseSensitiveButton()
3838
this.urlLabel = buildUrlLabel()
3939

40-
val searchButton = buildSeachButton(FileContentSearchListener(this))
40+
val searchButton = buildSearchButton(FileContentSearchListener(this))
4141
val clearButton = buildClearButton(FileContentClearListener(this))
4242

4343
val defaultActionGroup = DefaultActionGroup().apply {

src/main/kotlin/no/spk/fiskeoye/plugin/ui/FilenamePanel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal class FilenamePanel : FiskeoyePanel() {
3535
}
3636
this.urlLabel = buildUrlLabel()
3737

38-
val searchButton = buildSeachButton(FilenameSearchListener(this))
38+
val searchButton = buildSearchButton(FilenameSearchListener(this))
3939
val clearButton = buildClearButton(FilenameClearListener(this))
4040

4141
val defaultActionGroup = DefaultActionGroup().apply {

src/main/kotlin/no/spk/fiskeoye/plugin/ui/FiskeoyePanel.kt

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import java.awt.Dimension
3636
import java.awt.Font
3737
import java.awt.event.KeyListener
3838
import javax.swing.JButton
39+
import javax.swing.JTable.AUTO_RESIZE_OFF
3940
import javax.swing.JToggleButton
4041
import javax.swing.ListSelectionModel
4142
import javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
@@ -72,6 +73,7 @@ internal abstract class FiskeoyePanel : SimpleToolWindowPanel(true, true), DumbA
7273
componentPopupMenu = buildPopupMenu(this)
7374
font = buildFont()
7475
autoscrolls = false
76+
autoResizeMode = AUTO_RESIZE_OFF
7577
setDefaultRenderer(LabelIcon::class.java, LabelIconRenderer())
7678
setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION)
7779
setShowGrid(false)
@@ -97,25 +99,30 @@ internal abstract class FiskeoyePanel : SimpleToolWindowPanel(true, true), DumbA
9799

98100
private fun buildPopupMenu(table: JBTable): JBPopupMenu {
99101
return JBPopupMenu().apply popupMenu@{
100-
val copyLink = buildCopyLink(table)
101-
this.add(copyLink)
102-
val copyLinkForMarkdown = buildCopyLinkForMarkdown(table)
103-
this.add(copyLinkForMarkdown)
104-
val copyLinkForJira = buildCopyLinkForJira(table)
105-
this.add(copyLinkForJira)
106-
val nothingHere = JBMenuItem("Nothing here")
107-
this.add(nothingHere)
108-
109102
this.addPopupMenuListener(object : PopupMenuListenerAdapter() {
110103
override fun popupMenuWillBecomeVisible(e: PopupMenuEvent?) {
111-
val tableIsValid = (!table.isEmpty && table.model.getValueAt(table.selectedRow, 1) != null)
112-
copyLink.isVisible = tableIsValid
113-
copyLinkForMarkdown.isVisible = tableIsValid
114-
copyLinkForJira.isVisible = tableIsValid
115-
nothingHere.isVisible = !tableIsValid
104+
removeAll()
105+
val isValid = try {
106+
val isNotEmpty = !table.isEmpty
107+
val hasData = table.selectedRow >= 0 && table.selectedRow < table.rowCount
108+
val isNotNull = table.model.getValueAt(table.selectedRow, 1) != null
109+
isNotNull && hasData && isNotEmpty
110+
} catch (e: Exception) {
111+
false
112+
}
113+
if (!isValid) {
114+
val nothingHere = JBMenuItem("Nothing here")
115+
add(nothingHere)
116+
return
117+
}
118+
val copyLink = buildCopyLink(table)
119+
add(copyLink)
120+
val copyLinkForMarkdown = buildCopyLinkForMarkdown(table)
121+
add(copyLinkForMarkdown)
122+
val copyLinkForJira = buildCopyLinkForJira(table)
123+
add(copyLinkForJira)
116124
}
117125
})
118-
119126
}
120127
}
121128

@@ -174,7 +181,7 @@ internal abstract class FiskeoyePanel : SimpleToolWindowPanel(true, true), DumbA
174181
}
175182

176183
@Suppress("UnstableApiUsage")
177-
protected fun buildSeachButton(fiskeoyeActionListener: FiskeoyeActionListener): JButton {
184+
protected fun buildSearchButton(fiskeoyeActionListener: FiskeoyeActionListener): JButton {
178185
return JButton().apply {
179186
defaultButton()
180187
text = "Search"

src/main/kotlin/no/spk/fiskeoye/plugin/util/FiskeoyeUtil.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import java.net.URL
2929
import javax.swing.JEditorPane
3030
import javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS
3131
import javax.swing.JTable.AUTO_RESIZE_OFF
32-
import javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
3332
import javax.swing.table.DefaultTableModel
3433
import javax.swing.text.html.HTMLEditorKit
3534

@@ -105,12 +104,14 @@ internal fun openUrlWithBrowser(uri: URI) {
105104

106105
internal fun JBTable.clear() {
107106
this.model = DefaultTableModel()
107+
this.autoResizeMode = AUTO_RESIZE_OFF
108108
this.preferredSize = Dimension(0, 0)
109109
}
110110

111111
internal fun JBTable.addMessage(message: String) {
112112
this.apply {
113113
clear()
114+
autoResizeMode = AUTO_RESIZE_ALL_COLUMNS
114115
model = getDefaultModel(message)
115116
hideColumns()
116117
}
@@ -213,18 +214,18 @@ internal fun getDefaultModel(header: String): DefaultTableModel {
213214
}
214215

215216
internal fun getTruckMessage(maxSize: Int): String {
216-
return getHtmlError("NB! Antall treff overstiger $maxSize. Resultatet er trunkert")
217+
return getError("NB! Antall treff overstiger $maxSize. Resultatet er trunkert")
217218
}
218219

219220
internal fun getGeneralErrorMessage(): String {
220-
return getHtmlError("Ops! Ser ut som noe gikk galt! Se \"${LoggerFactory.getLogFilePath()}\" for mer info...")
221+
return getHtml(getError("Ops! Ser ut som noe gikk galt! Se \"${LoggerFactory.getLogFilePath()}\" for mer info..."))
221222
}
222223

223224
internal fun getInvalidString(): String {
224-
return getHtmlError("Søkestrengen må være på minst tre tegn.")
225+
return getHtml(getError("Søkestrengen må være på minst tre tegn."))
225226
}
226227

227-
internal fun getHtmlError(value: String): String {
228+
internal fun getError(value: String): String {
228229
return "<span style=\"color:red;\">$value<span>"
229230
}
230231

0 commit comments

Comments
 (0)