Skip to content

Commit

Permalink
include indexing on statusbar widget
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinVaadin committed Dec 17, 2024
1 parent 16aa303 commit 9d46315
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,23 @@ class VaadinStatusBarInfoPopupPanel(private val project: Project) : JPanel() {
wrapper.add(panel)

if (!status) {
val restart = JButton(AllIcons.Actions.Restart)
restart.addActionListener {
CopilotPluginUtil.removeDotFile(project)
CopilotPluginUtil.saveDotFile(project)
DumbService.getInstance(project).smartInvokeLater {
VaadinStatusBarWidget.update(project)
afterRestart?.invoke()
if (DumbService.isDumb(project)) {
wrapper.add(createDescription("Service will be available after indexing is completed"))
} else {
val restart = JButton(AllIcons.Actions.Restart)
restart.addActionListener {
CopilotPluginUtil.removeDotFile(project)
CopilotPluginUtil.saveDotFile(project)
DumbService.getInstance(project).smartInvokeLater {
VaadinStatusBarWidget.update(project)
afterRestart?.invoke()
}
}
panel.add(restart)
wrapper.add(
createDescription(
"<html>Service will be started automatically.<br/>In case of issues you can restart it manually.</html>"))
}
panel.add(restart)
wrapper.add(
createDescription(
"<html>Service will be available after indexing is completed.<br/>In case of issues you can restart it manually.</html>"))
}
return wrapper
}
Expand Down
50 changes: 43 additions & 7 deletions src/main/kotlin/com/vaadin/plugin/ui/VaadinStatusBarWidget.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vaadin.plugin.ui

import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.wm.StatusBarWidget
Expand All @@ -8,6 +9,7 @@ import com.intellij.ui.IconManager
import com.intellij.ui.awt.RelativePoint
import com.intellij.util.Consumer
import com.intellij.util.ui.JBUI.CurrentTheme.IconBadge
import com.intellij.util.ui.UIUtil
import com.vaadin.plugin.copilot.CopilotPluginUtil
import com.vaadin.plugin.utils.VaadinIcons
import com.vaadin.plugin.utils.hasEndpoints
Expand All @@ -24,6 +26,24 @@ class VaadinStatusBarWidget(private val project: Project) : StatusBarWidget, Sta
}
}

private var clicked: Boolean = false

init {
project.messageBus
.connect()
.subscribe(
DumbService.DUMB_MODE,
object : DumbService.DumbModeListener {
override fun enteredDumbMode() {
update(project)
}

override fun exitDumbMode() {
update(project)
}
})
}

override fun ID(): String {
return ID
}
Expand All @@ -33,7 +53,11 @@ class VaadinStatusBarWidget(private val project: Project) : StatusBarWidget, Sta
}

override fun getClickConsumer(): Consumer<MouseEvent> {
return Consumer { showPopup(RelativePoint.fromScreen(it.locationOnScreen)) }
return Consumer {
clicked = true
showPopup(RelativePoint.fromScreen(it.locationOnScreen))
update(project)
}
}

private fun showPopup(relativePoint: RelativePoint) {
Expand All @@ -47,18 +71,30 @@ class VaadinStatusBarWidget(private val project: Project) : StatusBarWidget, Sta
}

override fun getTooltipText(): String {
if (!CopilotPluginUtil.isActive(project) || !hasEndpoints()) {
return "There are issues while running Vaadin plugin, click to see details"
if (CopilotPluginUtil.isActive(project) && hasEndpoints()) {
return "Vaadin plugin is active, all features are available"
}

return "Vaadin plugin is active"
if (DumbService.isDumb(project)) {
return "Indexing is in progress, please wait"
}

return "Not all features are available, click to see details"
}

override fun getIcon(): Icon {
if (!CopilotPluginUtil.isActive(project) || !hasEndpoints()) {
return IconManager.getInstance().withIconBadge(VaadinIcons.VAADIN, IconBadge.WARNING)
if (clicked) {
return VaadinIcons.VAADIN
}

if (CopilotPluginUtil.isActive(project) && hasEndpoints()) {
return VaadinIcons.VAADIN
}

if (DumbService.isDumb(project)) {
return IconManager.getInstance().withIconBadge(VaadinIcons.VAADIN, UIUtil.getLabelForeground())
}

return VaadinIcons.VAADIN
return IconManager.getInstance().withIconBadge(VaadinIcons.VAADIN, IconBadge.WARNING)
}
}

0 comments on commit 9d46315

Please sign in to comment.