Skip to content

Commit 514bd59

Browse files
Fixed Error links
1 parent bb35bc1 commit 514bd59

File tree

9 files changed

+157
-96
lines changed

9 files changed

+157
-96
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.digma.intellij.plugin.analytics;
2+
3+
import com.intellij.util.messages.Topic;
4+
5+
public interface TabsChanged {
6+
7+
@Topic.ProjectLevel
8+
Topic<TabsChanged> TABS_CHANGED_TOPIC = Topic.create("TABS_CHANGED_TOPIC", TabsChanged.class);
9+
10+
void activeTabIndexChanged(int newTabIndex);
11+
12+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class AbstractViewService(val project: Project) : Disposable {
2020

2121
private val analyticsConnectionEventsConnection: MessageBusConnection = project.messageBus.connect()
2222

23-
private val toolWindowTabsHelper = ToolWindowTabsHelper.getInstance(project)
23+
private val tabsHelper = TabsHelper.getInstance(project)
2424

2525
init {
2626
//subscribe to connection lost/gained , call doUpdateUi() on each event so that the no connection card will show or hide
@@ -43,12 +43,12 @@ abstract class AbstractViewService(val project: Project) : Disposable {
4343

4444
fun doConnectionLost() {
4545
//if a view needs to do something when connection lost can override this method and don't forget to call super
46-
if (toolWindowTabsHelper.isErrorDetailsOn()) {
47-
toolWindowTabsHelper.errorDetailsOff()
46+
if (tabsHelper.isErrorDetailsOn()) {
47+
tabsHelper.errorDetailsOff()
4848
if (this is ErrorsViewService) {
4949
this.closeErrorDetails()
5050
}
51-
toolWindowTabsHelper.errorDetailsClosed()
51+
tabsHelper.errorDetailsClosed()
5252
}
5353
}
5454

@@ -62,11 +62,11 @@ abstract class AbstractViewService(val project: Project) : Disposable {
6262
//in the view until its closed. there may be exceptions, for example the summary view can reload while error details
6363
// is on but setVisible should not run.
6464
open fun canUpdateUI(): Boolean {
65-
return !toolWindowTabsHelper.isErrorDetailsOn()
65+
return !tabsHelper.isErrorDetailsOn()
6666
}
6767

6868
open fun canSetVisible(): Boolean {
69-
return !toolWindowTabsHelper.isErrorDetailsOn()
69+
return !tabsHelper.isErrorDetailsOn()
7070
}
7171

7272

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.digma.intellij.plugin.ui.service
2+
3+
import com.intellij.openapi.diagnostic.Logger
4+
import com.intellij.openapi.project.Project
5+
import com.intellij.ui.content.Content
6+
import org.digma.intellij.plugin.analytics.TabsChanged
7+
import org.digma.intellij.plugin.log.Log
8+
9+
class TabsHelper(val project: Project) {
10+
private val logger: Logger = Logger.getInstance(TabsHelper::class.java)
11+
12+
var currentTabIndex = 0
13+
14+
private var visibleTabBeforeErrorDetails: Int? = null
15+
private var errorDetailsOn = false
16+
17+
companion object {
18+
const val INSIGHTS_TAB_NAME = "Insights"
19+
const val DEFAULT_ERRORS_TAB_NAME = "Errors"
20+
const val DETAILED_ERRORS_TAB_NAME = "Error Details"
21+
const val SUMMARY_TAB_NAME = "Summary"
22+
23+
@JvmStatic
24+
fun getInstance(project: Project): TabsHelper {
25+
return project.getService(TabsHelper::class.java)
26+
}
27+
}
28+
29+
fun isInsightsTab(content: Content?): Boolean {
30+
return content != null && content.tabName.equals(INSIGHTS_TAB_NAME, ignoreCase = true)
31+
}
32+
33+
fun isErrorsTab(content: Content?): Boolean {
34+
return content != null && content.tabName.equals(DEFAULT_ERRORS_TAB_NAME, ignoreCase = true)
35+
}
36+
37+
fun isSummaryTab(content: Content?): Boolean {
38+
return content != null && content.tabName.equals(SUMMARY_TAB_NAME, ignoreCase = true)
39+
}
40+
41+
42+
fun showingErrorDetails() {
43+
visibleTabBeforeErrorDetails = currentTabIndex
44+
}
45+
46+
fun errorDetailsClosed() {
47+
visibleTabBeforeErrorDetails?.let { notifyTabChanged(it) }
48+
visibleTabBeforeErrorDetails = null
49+
}
50+
51+
private fun notifyTabChanged(newTabIndex: Int) {
52+
Log.log(logger::info, "Firing TabChanged event for {}", newTabIndex)
53+
if (project.isDisposed) {
54+
return
55+
}
56+
val publisher = project.messageBus.syncPublisher(TabsChanged.TABS_CHANGED_TOPIC)
57+
publisher.activeTabIndexChanged(newTabIndex)
58+
}
59+
60+
fun errorDetailsOn() {
61+
errorDetailsOn = true
62+
notifyTabChanged(1)
63+
}
64+
65+
fun errorDetailsOff() {
66+
errorDetailsOn = false
67+
}
68+
69+
fun isErrorDetailsOn(): Boolean {
70+
return errorDetailsOn
71+
}
72+
73+
}

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

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/main/java/org/digma/intellij/plugin/service/ErrorsActionsService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.digma.intellij.plugin.ui.service.ErrorsViewService;
99
import org.digma.intellij.plugin.ui.service.InsightsViewService;
1010
import org.digma.intellij.plugin.ui.service.SummaryViewService;
11-
import org.digma.intellij.plugin.ui.service.ToolWindowTabsHelper;
11+
import org.digma.intellij.plugin.ui.service.TabsHelper;
1212
import org.jetbrains.annotations.NotNull;
1313
import org.jetbrains.annotations.Nullable;
1414

@@ -18,7 +18,7 @@ public class ErrorsActionsService implements ContentManagerListener {
1818
private final InsightsViewService insightsViewService;
1919
private final ErrorsViewService errorsViewService;
2020
private final SummaryViewService summaryViewService;
21-
private final ToolWindowTabsHelper toolWindowTabsHelper;
21+
private final TabsHelper tabsHelper;
2222

2323
private final EditorService editorService;
2424

@@ -27,7 +27,7 @@ public ErrorsActionsService(Project project) {
2727
insightsViewService = project.getService(InsightsViewService.class);
2828
errorsViewService = project.getService(ErrorsViewService.class);
2929
summaryViewService = project.getService(SummaryViewService.class);
30-
toolWindowTabsHelper = project.getService(ToolWindowTabsHelper.class);
30+
tabsHelper = project.getService(TabsHelper.class);
3131
editorService = project.getService(EditorService.class);
3232
}
3333

@@ -42,24 +42,24 @@ public void showErrorDetails(@NotNull CodeObjectError codeObjectError) {
4242
}
4343

4444
public void showErrorDetails(@NotNull String uid) {
45-
toolWindowTabsHelper.showingErrorDetails();
45+
tabsHelper.showingErrorDetails();
4646
errorsViewService.setVisible();
4747
errorsViewService.showErrorDetails(uid);
48-
toolWindowTabsHelper.errorDetailsOn();
48+
tabsHelper.errorDetailsOn();
4949
}
5050

5151
public void closeErrorDetailsBackButton() {
52-
toolWindowTabsHelper.errorDetailsOff();
52+
tabsHelper.errorDetailsOff();
5353
errorsViewService.closeErrorDetails();
5454
insightsViewService.updateUi();
55-
toolWindowTabsHelper.errorDetailsClosed();
55+
tabsHelper.errorDetailsClosed();
5656
}
5757

5858
@Override
5959
public void selectionChanged(@NotNull ContentManagerEvent event) {
60-
if (toolWindowTabsHelper.isErrorDetailsOn() &&
61-
(toolWindowTabsHelper.isInsightsTab(event.getContent()) || toolWindowTabsHelper.isSummaryTab(event.getContent()))) {
62-
toolWindowTabsHelper.errorDetailsOff();
60+
if (tabsHelper.isErrorDetailsOn() &&
61+
(tabsHelper.isInsightsTab(event.getContent()) || tabsHelper.isSummaryTab(event.getContent()))) {
62+
tabsHelper.errorDetailsOff();
6363
errorsViewService.closeErrorDetails();
6464
insightsViewService.updateUi();
6565
summaryViewService.updateUi();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.digma.intellij.plugin.tab;
2+
3+
import com.intellij.openapi.project.Project;
4+
import org.digma.intellij.plugin.analytics.TabsChanged;
5+
6+
/**
7+
* The central handler of TabsChanged events.
8+
* it will perform the necessary actions that are common to all languages or IDEs.
9+
*/
10+
public class TabChangeHandler implements TabsChanged {
11+
12+
@Override
13+
public void activeTabIndexChanged(int newTabIndex) {
14+
//nothing to do here
15+
}
16+
}

src/main/java/org/digma/intellij/plugin/toolwindow/sidepane/DigmaSidePaneToolWindowFactory.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.digma.intellij.plugin.ui.service.ErrorsViewService;
1616
import org.digma.intellij.plugin.ui.service.InsightsViewService;
1717
import org.digma.intellij.plugin.ui.service.SummaryViewService;
18-
import org.digma.intellij.plugin.ui.service.ToolWindowTabsHelper;
1918
import org.jetbrains.annotations.NotNull;
2019

2120
import static org.digma.intellij.plugin.ui.common.MainSidePaneWindowPanelKt.createMainSidePaneWindowPanel;
@@ -49,8 +48,6 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
4948

5049
var contentFactory = ContentFactory.getInstance();
5150

52-
ToolWindowTabsHelper.getInstance(project).setToolWindow(toolWindow);
53-
5451
//initialize AnalyticsService early so the UI can detect the connection status when created
5552
project.getService(AnalyticsService.class);
5653

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

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ import com.intellij.openapi.rd.util.launchBackground
77
import com.intellij.ui.components.JBTabbedPane
88
import com.intellij.util.ui.JBUI
99
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
10+
import org.digma.intellij.plugin.analytics.AnalyticsService
11+
import org.digma.intellij.plugin.analytics.TabsChanged
12+
import org.digma.intellij.plugin.common.EDT
1013
import org.digma.intellij.plugin.log.Log
1114
import org.digma.intellij.plugin.ui.errors.errorsPanel
1215
import org.digma.intellij.plugin.ui.insights.insightsPanel
1316
import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
1417
import org.digma.intellij.plugin.ui.panels.DigmaTabPanel
15-
import org.digma.intellij.plugin.ui.service.ErrorsViewService
16-
import org.digma.intellij.plugin.ui.service.InsightsViewService
17-
import org.digma.intellij.plugin.ui.service.SummaryViewService
18-
import org.digma.intellij.plugin.ui.service.ToolWindowTabsHelper
18+
import org.digma.intellij.plugin.ui.service.*
1919
import org.digma.intellij.plugin.ui.summary.summaryPanel
20-
import java.awt.BorderLayout
2120
import java.util.concurrent.locks.ReentrantLock
2221
import javax.swing.BorderFactory
2322
import javax.swing.BoxLayout
@@ -29,13 +28,28 @@ class TabsPanel(
2928

3029
private val project: Project
3130
private val rebuildPanelLock = ReentrantLock()
31+
private val tabsHelper = TabsHelper.getInstance(project)
32+
private val tabbedPane = JBTabbedPane()
3233

3334
init {
3435
this.project = project
3536
isOpaque = false
3637
layout = BoxLayout(this, BoxLayout.Y_AXIS)
3738
border = JBUI.Borders.empty()
39+
3840
rebuildInBackground()
41+
42+
project.messageBus.connect(project.getService(AnalyticsService::class.java))
43+
.subscribe(TabsChanged.TABS_CHANGED_TOPIC, TabsChanged { newTabIndex ->
44+
EDT.ensureEDT {
45+
if (1 == newTabIndex) {
46+
tabbedPane.setTitleAt(1, TabsHelper.DETAILED_ERRORS_TAB_NAME)
47+
} else {
48+
tabbedPane.setTitleAt(1, TabsHelper.DEFAULT_ERRORS_TAB_NAME)
49+
}
50+
tabbedPane.selectedIndex = newTabIndex
51+
}
52+
})
3953
}
4054

4155
override fun reset() {
@@ -78,21 +92,34 @@ class TabsPanel(
7892
}
7993

8094
private fun getTabsPanel(): JBTabbedPane {
81-
val tabbedPane = JBTabbedPane()
8295
tabbedPane.isOpaque = false
8396
tabbedPane.border = JBUI.Borders.empty()
8497
val insightsPanel = createInsightsPanel(project)
8598

8699
insightsPanel.border = BorderFactory.createEmptyBorder(0, 0, 0, 0) // Set the border of the panel to empty
87-
tabbedPane.addTab(ToolWindowTabsHelper.INSIGHTS_TAB_NAME, insightsPanel)
100+
tabbedPane.addTab(TabsHelper.INSIGHTS_TAB_NAME, insightsPanel)
88101

89102
val errorsPanel = createErrorsPanel(project)
90-
tabbedPane.addTab(ToolWindowTabsHelper.ERRORS_TAB_NAME, errorsPanel)
103+
if (tabsHelper.isErrorDetailsOn()) {
104+
tabbedPane.addTab(TabsHelper.DETAILED_ERRORS_TAB_NAME, errorsPanel)
105+
} else {
106+
tabbedPane.addTab(TabsHelper.DEFAULT_ERRORS_TAB_NAME, errorsPanel)
107+
}
91108
val summaryPanel = createSummaryPanel(project);
92-
tabbedPane.addTab(ToolWindowTabsHelper.SUMMARY_TAB_NAME, summaryPanel)
109+
tabbedPane.addTab(TabsHelper.SUMMARY_TAB_NAME, summaryPanel)
93110

94111
tabbedPane.border = BorderFactory.createEmptyBorder(); // Set the border of the tabbed pane to empty
95112

113+
var currentTabIndex: Int
114+
115+
// Add a listener to the JBTabbedPane to track tab changes
116+
tabbedPane.addChangeListener {
117+
// Get the index of the currently selected tab
118+
currentTabIndex = tabbedPane.selectedIndex
119+
// Do something with the tab indexes, such as update UI or perform logic
120+
tabsHelper.currentTabIndex = currentTabIndex
121+
}
122+
96123
return tabbedPane
97124
}
98125

src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
<projectService serviceImplementation="org.digma.intellij.plugin.service.ErrorsActionsService"/>
6666

67-
<projectService serviceImplementation="org.digma.intellij.plugin.ui.service.ToolWindowTabsHelper"/>
67+
<projectService serviceImplementation="org.digma.intellij.plugin.ui.service.TabsHelper"/>
6868

6969
<projectService serviceImplementation="org.digma.intellij.plugin.service.EditorService"/>
7070

@@ -129,6 +129,9 @@
129129
<listener
130130
class="org.digma.intellij.plugin.emvironment.EnvironmentChangeHandler"
131131
topic="org.digma.intellij.plugin.analytics.EnvironmentChanged"/>
132+
<listener
133+
class="org.digma.intellij.plugin.tab.TabChangeHandler"
134+
topic="org.digma.intellij.plugin.analytics.TabsChanged"/>
132135
<listener
133136
class="org.digma.intellij.plugin.debugger.DebuggerListener"
134137
topic="com.intellij.xdebugger.XDebuggerManagerListener"/>

0 commit comments

Comments
 (0)