Skip to content

Commit 467a1dd

Browse files
authored
Revalidate envs panel (#103)
* revalidate envs panel Signed-off-by: shalom <[email protected]> * revalidate envs panel Signed-off-by: shalom <[email protected]>
1 parent 822a6f8 commit 467a1dd

File tree

8 files changed

+60
-24
lines changed

8 files changed

+60
-24
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ abstract class AbstractViewService(val project: Project) {
7171
toolWindowContent?.displayName = getViewDisplayName()
7272
toolWindowContent?.component?.revalidate()
7373
toolWindow?.component?.revalidate()
74-
toolWindow?.component?.repaint()
7574
}
7675
}
7776

src/main/java/org/digma/intellij/plugin/toolwindow/DigmaToolWindowFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.intellij.openapi.project.Project;
55
import com.intellij.openapi.wm.ToolWindow;
66
import com.intellij.openapi.wm.ToolWindowFactory;
7+
import com.intellij.ui.content.Content;
78
import com.intellij.ui.content.ContentFactory;
89
import org.digma.intellij.plugin.log.Log;
910
import org.digma.intellij.plugin.service.EditorInteractionService;
@@ -40,6 +41,8 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
4041
var toolWindowTabsHelper = project.getService(ToolWindowTabsHelper.class);
4142
toolWindowTabsHelper.setToolWindow(toolWindow);
4243

44+
Content contentToSelect;
45+
4346
{
4447
var insightsPanel = InsightsTabKt.insightsPanel(project);
4548
var insightsViewService = project.getService(InsightsViewService.class);
@@ -51,6 +54,7 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
5154
toolWindow.getContentManager().addContent(insightsContent);
5255
insightsViewService.setContent(toolWindow,insightsContent);
5356
toolWindowTabsHelper.setInsightsContent(insightsContent);
57+
contentToSelect = insightsContent;
5458
}
5559

5660
{
@@ -73,5 +77,7 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
7377

7478
project.getService(ToolWindowShower.class).setToolWindow(toolWindow);
7579
EditorInteractionService.getInstance(project).start();
80+
81+
toolWindow.getContentManager().setSelectedContent(contentToSelect, true);
7682
}
7783
}

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,17 @@ import org.digma.intellij.plugin.analytics.EnvironmentChanged
1111
import org.digma.intellij.plugin.common.CommonUtils
1212
import org.digma.intellij.plugin.ui.model.environment.EnvironmentsListChangedListener
1313
import org.digma.intellij.plugin.ui.model.environment.EnvironmentsSupplier
14-
import java.awt.BorderLayout
14+
import java.awt.Dimension
1515
import java.awt.FlowLayout
1616
import java.awt.GridLayout
1717
import java.util.*
1818
import java.util.function.Function
1919
import javax.swing.JPanel
20+
import kotlin.math.min
2021

2122
fun environmentsPanel(project: Project, environmentsSupplier: EnvironmentsSupplier): JPanel {
2223

23-
val envsPanel = EnvironmentsPanel(project, environmentsSupplier)
24-
25-
val result = JPanel()
26-
result.isOpaque = false
27-
result.border = JBUI.Borders.empty()
28-
result.layout = BorderLayout()
29-
result.add(envsPanel, BorderLayout.CENTER)
30-
return result
31-
24+
return EnvironmentsPanel(project, environmentsSupplier)
3225
}
3326

3427

@@ -56,6 +49,29 @@ class EnvironmentsPanel(project: Project, private val environmentsSupplier: Envi
5649
Disposer.register(project, messageBusConnection)
5750
}
5851

52+
53+
/*
54+
usually this panel works fine.
55+
there is one issue: sometimes when the plugin window opens on startup this panel takes too much
56+
vertical space and the insights list is almost not shown. any hover over this panel with the mouse or any
57+
other action related to the plugin will fix it and the tab will re-layout. from there on the panel functions ok.
58+
I could not find any way to cause this panel to layout correctly on startup.
59+
so the code in getPreferredSize limits the height on startup to a reasonable size and only the first few calls
60+
to getPreferredSize, from there on its ok. it proves to solve or at least hide the issue.
61+
it will be noticeable when there are many environments and only on first opening of the window and only occasionally.
62+
*/
63+
private var startup = 0
64+
override fun getPreferredSize(): Dimension {
65+
if (startup < 5) {
66+
startup++
67+
val d = super.getPreferredSize()
68+
if (d != null) {
69+
return Dimension(d.width, min(d.height, 300))
70+
}
71+
}
72+
return super.getPreferredSize()
73+
}
74+
5975
private fun select(newSelectedEnv: String?) {
6076
val currentSelected: EnvLink? = getSelected()
6177
if (currentSelected != null) {
@@ -166,6 +182,17 @@ class EnvironmentsPanel(project: Project, private val environmentsSupplier: Envi
166182
val localHostname = CommonUtils.getLocalHostname()
167183
return environment.startsWith(localHostname, true)
168184
}
185+
186+
187+
//this is the method called by the platform when requesting focus with ContentManager.setSelectedContent
188+
override fun requestFocus() {
189+
getSelected()?.requestFocusInWindow()
190+
}
191+
192+
override fun requestFocusInWindow(): Boolean {
193+
requestFocus()
194+
return true
195+
}
169196
}
170197

171198

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ fun createTopPanel(project: Project, model: PanelModel): DigmaResettablePanel {
6060
override fun reset() {
6161
scopeLine.reset()
6262
}
63+
64+
override fun requestFocus() {
65+
envsPanel.requestFocus()
66+
}
67+
68+
override fun requestFocusInWindow(): Boolean {
69+
return envsPanel.requestFocusInWindow()
70+
}
6371
}
6472

6573
result.isOpaque = false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fun getAffectedServicesTooltip(errorsModel: ErrorsModel): String {
397397
}
398398

399399

400-
private fun backButton(project: Project): JComponent {
400+
private fun backButton(project: Project): JPanel {
401401

402402
val size = Laf.scalePanels(Laf.Sizes.ERROR_DETAILS_BACK_BUTTON_SIZE)
403403
val buttonsSize = Dimension(size + 2, size + 3)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fun errorsPanel(project: Project): DigmaTabPanel {
112112
}
113113

114114
override fun getPreferredFocusedComponent(): JComponent {
115-
return errorsList
115+
return topPanelWrapper
116116
}
117117

118118
//reset must be called from EDT
@@ -139,9 +139,8 @@ fun errorsPanel(project: Project): DigmaTabPanel {
139139
errorsPanelListCardLayout.show(errorsPanelListCardPanel, LIST_CARD_NAME)
140140
}
141141

142-
errorsPanelListCardPanel.revalidate()
143-
cardsPanel.revalidate()
144142
revalidate()
143+
repaint()
145144
}
146145
}
147146

src/main/kotlin/org/digma/intellij/plugin/ui/insights/InsightsTab.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ fun insightsPanel(project: Project ): DigmaTabPanel {
8484
}
8585

8686
override fun getPreferredFocusedComponent(): JComponent {
87-
return if (insightsModel.card.name == InsightsTabCard.INSIGHTS.name){
88-
insightsList
89-
}else{
90-
previewList
91-
}
87+
return topPanelWrapper
9288
}
9389

9490
//reset must be called from EDT
@@ -109,8 +105,8 @@ fun insightsPanel(project: Project ): DigmaTabPanel {
109105
cardLayout.show(cardsPanel, insightsModel.card.name)
110106
}
111107

112-
cardsPanel.revalidate()
113108
revalidate()
109+
repaint()
114110
}
115111
}
116112

src/main/kotlin/org/digma/intellij/plugin/ui/list/PanelList.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ abstract class PanelList(val project: Project, private var model: PanelListModel
9999

100100
for (i in 0 until model.getSize()) run {
101101
cellRenderer.apply {
102-
val newComp: JPanel = getListCellRendererComponent(project,this@PanelList,
103-
model.getElementAt(i), i, this@PanelList.hasFocus(),panelsLayoutHelper)
102+
val newComp: JPanel = getListCellRendererComponent(project, this@PanelList,
103+
model.getElementAt(i), i, this@PanelList.hasFocus(), panelsLayoutHelper)
104104
add(newComp)
105105
if (gapBetweenItems) {
106106
add(Box.createVerticalStrut(scaleBorders(5)))
@@ -109,7 +109,8 @@ abstract class PanelList(val project: Project, private var model: PanelListModel
109109

110110
}
111111

112-
this.revalidate()
112+
revalidate()
113+
repaint()
113114
}
114115

115116

0 commit comments

Comments
 (0)