Skip to content

Commit 7c34368

Browse files
Refresh all insights and errors button
1 parent 868b4ac commit 7c34368

File tree

8 files changed

+94
-26
lines changed

8 files changed

+94
-26
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/ui/service/ErrorsViewService.kt

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.digma.intellij.plugin.ui.service
22

33
import com.intellij.openapi.diagnostic.Logger
44
import com.intellij.openapi.project.Project
5+
import org.digma.intellij.plugin.common.Backgroundable
56
import org.digma.intellij.plugin.document.DocumentInfoContainer
67
import org.digma.intellij.plugin.errors.ErrorsProvider
78
import org.digma.intellij.plugin.log.Log
@@ -15,10 +16,13 @@ import org.digma.intellij.plugin.ui.model.errors.ErrorDetailsModel
1516
import org.digma.intellij.plugin.ui.model.errors.ErrorsModel
1617
import org.digma.intellij.plugin.ui.model.errors.ErrorsTabCard
1718
import java.util.Collections
19+
import java.util.concurrent.locks.Lock
20+
import java.util.concurrent.locks.ReentrantLock
1821

1922
class ErrorsViewService(project: Project) : AbstractViewService(project) {
2023

2124
private val logger: Logger = Logger.getInstance(ErrorsViewService::class.java)
25+
private val lock: Lock = ReentrantLock()
2226

2327
//the model is single per the life of an open project in intellij. it shouldn't be created
2428
//elsewhere in the program. it can not be singleton.
@@ -40,17 +44,24 @@ class ErrorsViewService(project: Project) : AbstractViewService(project) {
4044
fun contextChanged(
4145
methodInfo: MethodInfo
4246
) {
43-
44-
Log.log(logger::debug, "contextChanged to {}. ", methodInfo)
45-
46-
val errorsListContainer = errorsProvider.getErrors(methodInfo)
47-
model.listViewItems = errorsListContainer.listViewItems
48-
model.usageStatusResult = errorsListContainer.usageStatus
49-
model.scope = MethodScope(methodInfo)
50-
model.card = ErrorsTabCard.ERRORS_LIST
51-
model.errorsCount = errorsListContainer.count
52-
53-
updateUi()
47+
try {
48+
Log.log(logger::debug, "contextChanged to {}. ", methodInfo)
49+
50+
lock.tryLock()
51+
Log.log(logger::debug, "TryLock acquired for contextChanged to {}. ", methodInfo)
52+
53+
val errorsListContainer = errorsProvider.getErrors(methodInfo)
54+
model.listViewItems = errorsListContainer.listViewItems
55+
model.usageStatusResult = errorsListContainer.usageStatus
56+
model.scope = MethodScope(methodInfo)
57+
model.card = ErrorsTabCard.ERRORS_LIST
58+
model.errorsCount = errorsListContainer.count
59+
60+
updateUi()
61+
} finally {
62+
lock.unlock()
63+
Log.log(logger::debug, "TryLock released for contextChanged to {}. ", methodInfo)
64+
}
5465
}
5566

5667

@@ -158,5 +169,13 @@ class ErrorsViewService(project: Project) : AbstractViewService(project) {
158169
return emptyErrorDetails
159170
}
160171

172+
fun refreshErrors() {
173+
val scope = model.scope
174+
if (scope is MethodScope) {
175+
Backgroundable.ensureBackground(project, "Refresh errors list") {
176+
contextChanged(scope.getMethodInfo())
177+
}
178+
}
179+
}
161180

162181
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/ui/service/InsightsViewService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InsightsViewService(project: Project) : AbstractViewService(project) {
5151
Log.log(logger::debug, "contextChanged to {}. ", methodInfo)
5252

5353
lock.tryLock()
54-
Log.log(logger::debug, "Try lock acquired for contextChanged to {}. ", methodInfo)
54+
Log.log(logger::debug, "TryLock acquired for contextChanged to {}. ", methodInfo)
5555

5656
val insightsListContainer: InsightsListContainer = insightsProvider.getInsights(methodInfo)
5757

@@ -65,7 +65,7 @@ class InsightsViewService(project: Project) : AbstractViewService(project) {
6565
updateUi()
6666
} finally {
6767
lock.unlock()
68-
Log.log(logger::debug, "Try lock released for contextChanged to {}. ", methodInfo)
68+
Log.log(logger::debug, "TryLock released for contextChanged to {}. ", methodInfo)
6969
}
7070
}
7171

src/main/kotlin/org/digma/intellij/plugin/ui/common/ErrorsCommon.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import javax.swing.border.LineBorder
1111

1212
fun createScorePanelNoArrows(model: CodeObjectError): JPanel {
1313

14-
val scorePanelSize = Laf.scalePanels(Laf.Sizes.ERROR_SCORE_PANEL_SIZE)
14+
val scorePanelSize = Laf.scalePanels(Laf.Sizes.PANEL_SIZE_32)
1515
val scoreLabel = JLabel("${model.scoreInfo.score}", JLabel.CENTER)
1616
scoreLabel.toolTipText = genToolTipAsHtml(model.scoreInfo)
1717
scoreLabel.preferredSize = Dimension(scorePanelSize,scorePanelSize)

src/main/kotlin/org/digma/intellij/plugin/ui/common/Laf.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.intellij.icons.AllIcons
44
import com.intellij.ui.JBColor
55
import com.intellij.util.ui.JBUI
66
import org.digma.intellij.plugin.icons.IconsUtil
7-
import org.digma.intellij.plugin.ui.common.Laf.Sizes.Companion.INSIGHT_ICON_SIZE
7+
import org.digma.intellij.plugin.ui.common.Laf.Sizes.Companion.INSIGHT_ICON_SIZE_32
88
import org.digma.intellij.plugin.ui.list.insights.ThreeDotsIcon
99
import java.awt.Color
1010
import java.awt.Font
@@ -98,6 +98,7 @@ object Laf {
9898
@JvmStatic val WAITING_DATA = SvgIcon.asIs("/icons/sand-watch.svg")
9999
@JvmStatic val SLOW = SvgIcon.asIs("/icons/snail.svg")
100100
@JvmStatic val THREE_DOTS = ThreeDotsIcon.asIs("/icons/three-dots.svg")
101+
@JvmStatic val REFRESH = ThreeDotsIcon.asIs("/icons/repeat.svg")
101102

102103
@JvmStatic val QUESTION_MARK = AllIcons.General.QuestionDialog
103104
@JvmStatic val SPAN_DURATION_DROPPED = loadAndScaleIconByWidth("/icons/dropped.png", 8)
@@ -110,7 +111,7 @@ object Laf {
110111
}
111112

112113
private fun loadAndScaleInsightIconByWidth(path: String): Icon {
113-
val size = scaleIcons(INSIGHT_ICON_SIZE)
114+
val size = scaleIcons(INSIGHT_ICON_SIZE_32)
114115
return IconsUtil.loadAndScaleIconObjectByWidth(path, size)
115116
}
116117

@@ -123,10 +124,11 @@ object Laf {
123124
class Sizes{
124125
companion object {
125126
@JvmStatic
126-
val INSIGHT_ICON_SIZE: Int = 32
127-
const val ERROR_SCORE_PANEL_SIZE = 32
128-
const val ERROR_DETAILS_BACK_BUTTON_SIZE = 32
129-
const val ERROR_DETAILS_NAVIGATION_BUTTON_SIZE = 24
127+
val INSIGHT_ICON_SIZE_32: Int = 32
128+
const val PANEL_SIZE_32 = 32
129+
const val BUTTON_SIZE_32 = 32
130+
const val BUTTON_SIZE_24 = 24
131+
const val BUTTON_SIZE_26 = 26
130132
}
131133
}
132134

src/main/kotlin/org/digma/intellij/plugin/ui/common/Panels.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ import com.intellij.ui.dsl.builder.panel
1010
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
1111
import com.intellij.util.ui.JBUI
1212
import org.digma.intellij.plugin.analytics.AnalyticsService
13+
import org.digma.intellij.plugin.ui.errors.IconButton
1314
import org.digma.intellij.plugin.ui.model.NOT_SUPPORTED_OBJECT_MSG
1415
import org.digma.intellij.plugin.ui.model.PanelModel
1516
import org.digma.intellij.plugin.ui.model.insights.InsightsModel
1617
import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
1718
import org.digma.intellij.plugin.ui.panels.DigmaTabPanel
19+
import org.digma.intellij.plugin.ui.service.ErrorsViewService
20+
import org.digma.intellij.plugin.ui.service.InsightsViewService
1821
import java.awt.BorderLayout
19-
import javax.swing.JLabel
22+
import java.awt.Dimension
23+
import java.awt.event.MouseAdapter
24+
import java.awt.event.MouseEvent
25+
import javax.swing.*
2026

2127

28+
private const val REFRESH_ALL_INSIGHTS_AND_ERRORS = "Refresh"
29+
2230
fun noCodeObjectWarningPanel(model: PanelModel): DialogPanel {
2331

2432
return panel {
@@ -77,9 +85,9 @@ fun createTopPanel(project: Project, model: PanelModel): DigmaResettablePanel {
7785
}
7886

7987
result.isOpaque = false
80-
result.border = JBUI.Borders.empty(0, 10, 0, 10)
88+
result.border = JBUI.Borders.empty(0, 10)
8189
result.layout = BorderLayout()
82-
result.add(scopeLine, BorderLayout.NORTH)
90+
result.add(getScopeLineResultPanel(scopeLine, project), BorderLayout.NORTH)
8391
result.add(envsPanel, BorderLayout.CENTER)
8492
return result
8593
}
@@ -88,3 +96,32 @@ fun createTopPanel(project: Project, model: PanelModel): DigmaResettablePanel {
8896
fun wrapWithNoConnectionWrapper(project: Project, panel: DigmaTabPanel): DigmaTabPanel {
8997
return NoConnectionWrapper(project, panel)
9098
}
99+
100+
private fun getGeneralRefreshButton(project: Project): JButton {
101+
val insightsActionListener: InsightsViewService = project.getService(InsightsViewService::class.java)
102+
val errorsActionListener: ErrorsViewService = project.getService(ErrorsViewService::class.java)
103+
104+
val size = Laf.scalePanels(Laf.Sizes.BUTTON_SIZE_26)
105+
val buttonsSize = Dimension(size, size)
106+
val generalRefreshIconButton = IconButton(Laf.Icons.Insight.REFRESH)
107+
generalRefreshIconButton.preferredSize = buttonsSize
108+
generalRefreshIconButton.maximumSize = buttonsSize
109+
generalRefreshIconButton.toolTipText = asHtml(REFRESH_ALL_INSIGHTS_AND_ERRORS)
110+
111+
generalRefreshIconButton.addMouseListener(object : MouseAdapter() {
112+
override fun mouseClicked(e: MouseEvent?) {
113+
insightsActionListener.refreshInsights()
114+
errorsActionListener.refreshErrors()
115+
}
116+
})
117+
return generalRefreshIconButton
118+
}
119+
120+
private fun getScopeLineResultPanel(scopeLine: DialogPanel, project: Project): JPanel {
121+
val scopeLineResultPanel = JPanel()
122+
scopeLineResultPanel.layout = BoxLayout(scopeLineResultPanel, BoxLayout.LINE_AXIS)
123+
scopeLineResultPanel.add(scopeLine)
124+
scopeLineResultPanel.add(Box.createHorizontalGlue())
125+
scopeLineResultPanel.add(getGeneralRefreshButton(project))
126+
return scopeLineResultPanel
127+
}

src/main/kotlin/org/digma/intellij/plugin/ui/common/ScopeLine.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun scopeLine(scopeNameProducer: Producer<String>,
1717
scopeIconProducer: Producer<Icon>): DialogPanel {
1818

1919
return panel {
20-
row(asHtml(spanGrayed("Scope: "))) {
20+
row {
2121
icon(scopeIconProducer.produce()).bind(
2222
JLabel::getIcon, JLabel::setIcon, MutableProperty(
2323
getter = { scopeIconProducer.produce() },

src/main/kotlin/org/digma/intellij/plugin/ui/errors/ErrorDetailsPanel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fun flowStackNavigation(errorsModel: ErrorsModel, framesList: ScrollablePanelLis
258258

259259
val currentLabel = JLabel("0/00 Flow Stacks")
260260

261-
val size = Laf.scalePanels(Laf.Sizes.ERROR_DETAILS_NAVIGATION_BUTTON_SIZE)
261+
val size = Laf.scalePanels(Laf.Sizes.BUTTON_SIZE_24)
262262
val buttonsSize = Dimension(size + 2, size + 2)
263263

264264
val backButton = IconButton(Laf.Icons.ErrorDetails.BACK)
@@ -394,7 +394,7 @@ fun getAffectedServicesTooltip(errorsModel: ErrorsModel): String {
394394

395395
private fun backButton(project: Project): JPanel {
396396

397-
val size = Laf.scalePanels(Laf.Sizes.ERROR_DETAILS_BACK_BUTTON_SIZE)
397+
val size = Laf.scalePanels(Laf.Sizes.BUTTON_SIZE_32)
398398
val buttonsSize = Dimension(size + 2, size + 3)
399399

400400
val backButton = IconButton(Laf.Icons.ErrorDetails.BACK)
Lines changed: 10 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)