Skip to content

Commit

Permalink
Fixed Error links
Browse files Browse the repository at this point in the history
  • Loading branch information
MykolaYaremchuk committed Mar 22, 2023
1 parent bb35bc1 commit 514bd59
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.digma.intellij.plugin.analytics;

import com.intellij.util.messages.Topic;

public interface TabsChanged {

@Topic.ProjectLevel
Topic<TabsChanged> TABS_CHANGED_TOPIC = Topic.create("TABS_CHANGED_TOPIC", TabsChanged.class);

void activeTabIndexChanged(int newTabIndex);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class AbstractViewService(val project: Project) : Disposable {

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

private val toolWindowTabsHelper = ToolWindowTabsHelper.getInstance(project)
private val tabsHelper = TabsHelper.getInstance(project)

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

fun doConnectionLost() {
//if a view needs to do something when connection lost can override this method and don't forget to call super
if (toolWindowTabsHelper.isErrorDetailsOn()) {
toolWindowTabsHelper.errorDetailsOff()
if (tabsHelper.isErrorDetailsOn()) {
tabsHelper.errorDetailsOff()
if (this is ErrorsViewService) {
this.closeErrorDetails()
}
toolWindowTabsHelper.errorDetailsClosed()
tabsHelper.errorDetailsClosed()
}
}

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

open fun canSetVisible(): Boolean {
return !toolWindowTabsHelper.isErrorDetailsOn()
return !tabsHelper.isErrorDetailsOn()
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.digma.intellij.plugin.ui.service

import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.ui.content.Content
import org.digma.intellij.plugin.analytics.TabsChanged
import org.digma.intellij.plugin.log.Log

class TabsHelper(val project: Project) {
private val logger: Logger = Logger.getInstance(TabsHelper::class.java)

var currentTabIndex = 0

private var visibleTabBeforeErrorDetails: Int? = null
private var errorDetailsOn = false

companion object {
const val INSIGHTS_TAB_NAME = "Insights"
const val DEFAULT_ERRORS_TAB_NAME = "Errors"
const val DETAILED_ERRORS_TAB_NAME = "Error Details"
const val SUMMARY_TAB_NAME = "Summary"

@JvmStatic
fun getInstance(project: Project): TabsHelper {
return project.getService(TabsHelper::class.java)
}
}

fun isInsightsTab(content: Content?): Boolean {
return content != null && content.tabName.equals(INSIGHTS_TAB_NAME, ignoreCase = true)
}

fun isErrorsTab(content: Content?): Boolean {
return content != null && content.tabName.equals(DEFAULT_ERRORS_TAB_NAME, ignoreCase = true)
}

fun isSummaryTab(content: Content?): Boolean {
return content != null && content.tabName.equals(SUMMARY_TAB_NAME, ignoreCase = true)
}


fun showingErrorDetails() {
visibleTabBeforeErrorDetails = currentTabIndex
}

fun errorDetailsClosed() {
visibleTabBeforeErrorDetails?.let { notifyTabChanged(it) }
visibleTabBeforeErrorDetails = null
}

private fun notifyTabChanged(newTabIndex: Int) {
Log.log(logger::info, "Firing TabChanged event for {}", newTabIndex)
if (project.isDisposed) {
return
}
val publisher = project.messageBus.syncPublisher(TabsChanged.TABS_CHANGED_TOPIC)
publisher.activeTabIndexChanged(newTabIndex)
}

fun errorDetailsOn() {
errorDetailsOn = true
notifyTabChanged(1)
}

fun errorDetailsOff() {
errorDetailsOn = false
}

fun isErrorDetailsOn(): Boolean {
return errorDetailsOn
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.digma.intellij.plugin.ui.service.ErrorsViewService;
import org.digma.intellij.plugin.ui.service.InsightsViewService;
import org.digma.intellij.plugin.ui.service.SummaryViewService;
import org.digma.intellij.plugin.ui.service.ToolWindowTabsHelper;
import org.digma.intellij.plugin.ui.service.TabsHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -18,7 +18,7 @@ public class ErrorsActionsService implements ContentManagerListener {
private final InsightsViewService insightsViewService;
private final ErrorsViewService errorsViewService;
private final SummaryViewService summaryViewService;
private final ToolWindowTabsHelper toolWindowTabsHelper;
private final TabsHelper tabsHelper;

private final EditorService editorService;

Expand All @@ -27,7 +27,7 @@ public ErrorsActionsService(Project project) {
insightsViewService = project.getService(InsightsViewService.class);
errorsViewService = project.getService(ErrorsViewService.class);
summaryViewService = project.getService(SummaryViewService.class);
toolWindowTabsHelper = project.getService(ToolWindowTabsHelper.class);
tabsHelper = project.getService(TabsHelper.class);
editorService = project.getService(EditorService.class);
}

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

public void showErrorDetails(@NotNull String uid) {
toolWindowTabsHelper.showingErrorDetails();
tabsHelper.showingErrorDetails();
errorsViewService.setVisible();
errorsViewService.showErrorDetails(uid);
toolWindowTabsHelper.errorDetailsOn();
tabsHelper.errorDetailsOn();
}

public void closeErrorDetailsBackButton() {
toolWindowTabsHelper.errorDetailsOff();
tabsHelper.errorDetailsOff();
errorsViewService.closeErrorDetails();
insightsViewService.updateUi();
toolWindowTabsHelper.errorDetailsClosed();
tabsHelper.errorDetailsClosed();
}

@Override
public void selectionChanged(@NotNull ContentManagerEvent event) {
if (toolWindowTabsHelper.isErrorDetailsOn() &&
(toolWindowTabsHelper.isInsightsTab(event.getContent()) || toolWindowTabsHelper.isSummaryTab(event.getContent()))) {
toolWindowTabsHelper.errorDetailsOff();
if (tabsHelper.isErrorDetailsOn() &&
(tabsHelper.isInsightsTab(event.getContent()) || tabsHelper.isSummaryTab(event.getContent()))) {
tabsHelper.errorDetailsOff();
errorsViewService.closeErrorDetails();
insightsViewService.updateUi();
summaryViewService.updateUi();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/digma/intellij/plugin/tab/TabChangeHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.digma.intellij.plugin.tab;

import com.intellij.openapi.project.Project;
import org.digma.intellij.plugin.analytics.TabsChanged;

/**
* The central handler of TabsChanged events.
* it will perform the necessary actions that are common to all languages or IDEs.
*/
public class TabChangeHandler implements TabsChanged {

@Override
public void activeTabIndexChanged(int newTabIndex) {
//nothing to do here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.digma.intellij.plugin.ui.service.ErrorsViewService;
import org.digma.intellij.plugin.ui.service.InsightsViewService;
import org.digma.intellij.plugin.ui.service.SummaryViewService;
import org.digma.intellij.plugin.ui.service.ToolWindowTabsHelper;
import org.jetbrains.annotations.NotNull;

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

var contentFactory = ContentFactory.getInstance();

ToolWindowTabsHelper.getInstance(project).setToolWindow(toolWindow);

//initialize AnalyticsService early so the UI can detect the connection status when created
project.getService(AnalyticsService.class);

Expand Down
45 changes: 36 additions & 9 deletions src/main/kotlin/org/digma/intellij/plugin/ui/common/TabsPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import com.intellij.openapi.rd.util.launchBackground
import com.intellij.ui.components.JBTabbedPane
import com.intellij.util.ui.JBUI
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
import org.digma.intellij.plugin.analytics.AnalyticsService
import org.digma.intellij.plugin.analytics.TabsChanged
import org.digma.intellij.plugin.common.EDT
import org.digma.intellij.plugin.log.Log
import org.digma.intellij.plugin.ui.errors.errorsPanel
import org.digma.intellij.plugin.ui.insights.insightsPanel
import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
import org.digma.intellij.plugin.ui.panels.DigmaTabPanel
import org.digma.intellij.plugin.ui.service.ErrorsViewService
import org.digma.intellij.plugin.ui.service.InsightsViewService
import org.digma.intellij.plugin.ui.service.SummaryViewService
import org.digma.intellij.plugin.ui.service.ToolWindowTabsHelper
import org.digma.intellij.plugin.ui.service.*
import org.digma.intellij.plugin.ui.summary.summaryPanel
import java.awt.BorderLayout
import java.util.concurrent.locks.ReentrantLock
import javax.swing.BorderFactory
import javax.swing.BoxLayout
Expand All @@ -29,13 +28,28 @@ class TabsPanel(

private val project: Project
private val rebuildPanelLock = ReentrantLock()
private val tabsHelper = TabsHelper.getInstance(project)
private val tabbedPane = JBTabbedPane()

init {
this.project = project
isOpaque = false
layout = BoxLayout(this, BoxLayout.Y_AXIS)
border = JBUI.Borders.empty()

rebuildInBackground()

project.messageBus.connect(project.getService(AnalyticsService::class.java))
.subscribe(TabsChanged.TABS_CHANGED_TOPIC, TabsChanged { newTabIndex ->
EDT.ensureEDT {
if (1 == newTabIndex) {
tabbedPane.setTitleAt(1, TabsHelper.DETAILED_ERRORS_TAB_NAME)
} else {
tabbedPane.setTitleAt(1, TabsHelper.DEFAULT_ERRORS_TAB_NAME)
}
tabbedPane.selectedIndex = newTabIndex
}
})
}

override fun reset() {
Expand Down Expand Up @@ -78,21 +92,34 @@ class TabsPanel(
}

private fun getTabsPanel(): JBTabbedPane {
val tabbedPane = JBTabbedPane()
tabbedPane.isOpaque = false
tabbedPane.border = JBUI.Borders.empty()
val insightsPanel = createInsightsPanel(project)

insightsPanel.border = BorderFactory.createEmptyBorder(0, 0, 0, 0) // Set the border of the panel to empty
tabbedPane.addTab(ToolWindowTabsHelper.INSIGHTS_TAB_NAME, insightsPanel)
tabbedPane.addTab(TabsHelper.INSIGHTS_TAB_NAME, insightsPanel)

val errorsPanel = createErrorsPanel(project)
tabbedPane.addTab(ToolWindowTabsHelper.ERRORS_TAB_NAME, errorsPanel)
if (tabsHelper.isErrorDetailsOn()) {
tabbedPane.addTab(TabsHelper.DETAILED_ERRORS_TAB_NAME, errorsPanel)
} else {
tabbedPane.addTab(TabsHelper.DEFAULT_ERRORS_TAB_NAME, errorsPanel)
}
val summaryPanel = createSummaryPanel(project);
tabbedPane.addTab(ToolWindowTabsHelper.SUMMARY_TAB_NAME, summaryPanel)
tabbedPane.addTab(TabsHelper.SUMMARY_TAB_NAME, summaryPanel)

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

var currentTabIndex: Int

// Add a listener to the JBTabbedPane to track tab changes
tabbedPane.addChangeListener {
// Get the index of the currently selected tab
currentTabIndex = tabbedPane.selectedIndex
// Do something with the tab indexes, such as update UI or perform logic
tabsHelper.currentTabIndex = currentTabIndex
}

return tabbedPane
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

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

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

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

Expand Down Expand Up @@ -129,6 +129,9 @@
<listener
class="org.digma.intellij.plugin.emvironment.EnvironmentChangeHandler"
topic="org.digma.intellij.plugin.analytics.EnvironmentChanged"/>
<listener
class="org.digma.intellij.plugin.tab.TabChangeHandler"
topic="org.digma.intellij.plugin.analytics.TabsChanged"/>
<listener
class="org.digma.intellij.plugin.debugger.DebuggerListener"
topic="com.intellij.xdebugger.XDebuggerManagerListener"/>
Expand Down

0 comments on commit 514bd59

Please sign in to comment.