-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved plugin status bar widget to show current state. Added dialog…
… with information for user.
- Loading branch information
1 parent
b028e18
commit 1f906f9
Showing
7 changed files
with
145 additions
and
36 deletions.
There are no files selected for viewing
30 changes: 0 additions & 30 deletions
30
src/main/kotlin/com/vaadin/plugin/copilot/CopilotStatusBarPanel.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/kotlin/com/vaadin/plugin/ui/VaadinStatusBarInfoPopupPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.vaadin.plugin.ui | ||
|
||
import com.intellij.icons.AllIcons | ||
import com.intellij.openapi.ui.DialogPanel | ||
import com.intellij.ui.components.JBLabel | ||
import com.intellij.util.ui.JBEmptyBorder | ||
import com.intellij.util.ui.JBFont | ||
import com.intellij.util.ui.UIUtil | ||
import java.awt.Component | ||
import javax.swing.JLabel | ||
import javax.swing.JPanel | ||
import org.jdesktop.swingx.HorizontalLayout | ||
import org.jdesktop.swingx.VerticalLayout | ||
|
||
class VaadinStatusBarInfoPopupPanel(copilotInitialized: Boolean, endpointsAvailable: Boolean) : JPanel() { | ||
|
||
init { | ||
val p = DialogPanel(VerticalLayout(UIUtil.LARGE_VGAP)) | ||
p.border = JBEmptyBorder(UIUtil.getRegularPanelInsets()) | ||
add(p) | ||
|
||
val header = JBLabel("Vaadin plugin information") | ||
header.font = JBFont.h4() | ||
|
||
p.add(header) | ||
p.add( | ||
statusRow( | ||
"Copilot service is running", | ||
copilotInitialized, | ||
"Service will be available after indexing is completed")) | ||
p.add( | ||
statusRow( | ||
"Endpoints are available", | ||
endpointsAvailable, | ||
"Feature is available for IntelliJ Ultimate with installed Endpoints plugin")) | ||
} | ||
|
||
private fun statusRow(label: String, checked: Boolean, description: String): Component { | ||
val wrapper = JPanel(VerticalLayout()) | ||
|
||
val panel = JPanel(HorizontalLayout(UIUtil.DEFAULT_HGAP)) | ||
panel.add(JBLabel(label)) | ||
panel.add(JLabel(if (checked) AllIcons.Actions.Checked else AllIcons.Actions.Cancel)) | ||
wrapper.add(panel) | ||
|
||
if (!checked) { | ||
val desc = JLabel(description) | ||
desc.font = JBFont.smallOrNewUiMedium().asItalic() | ||
wrapper.add(desc) | ||
} | ||
return wrapper | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/com/vaadin/plugin/ui/VaadinStatusBarWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.vaadin.plugin.ui | ||
|
||
import com.intellij.openapi.actionSystem.DataContext | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.popup.JBPopupFactory | ||
import com.intellij.openapi.ui.popup.ListPopup | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.openapi.wm.StatusBarWidget | ||
import com.intellij.openapi.wm.impl.status.EditorBasedStatusBarPopup | ||
import com.intellij.ui.BadgeIconSupplier | ||
import com.vaadin.plugin.copilot.CopilotPluginUtil | ||
import com.vaadin.plugin.utils.VaadinIcons | ||
import com.vaadin.plugin.utils.hasEndpoints | ||
import javax.swing.Icon | ||
|
||
class VaadinStatusBarWidget(project: Project) : EditorBasedStatusBarPopup(project, false) { | ||
|
||
companion object { | ||
const val ID = "VaadinStatusBarPanel" | ||
} | ||
|
||
private val iconSupplier: BadgeIconSupplier = BadgeIconSupplier(VaadinIcons.VAADIN) | ||
|
||
private var clicked: Boolean = false | ||
|
||
override fun ID(): String { | ||
return ID | ||
} | ||
|
||
override fun createInstance(project: Project): StatusBarWidget { | ||
return VaadinStatusBarWidget(project) | ||
} | ||
|
||
override fun createPopup(context: DataContext): ListPopup? { | ||
clicked = true | ||
val popup = VaadinStatusBarInfoPopupPanel(isCopilotActive(), hasEndpoints()) | ||
JBPopupFactory.getInstance() | ||
.createComponentPopupBuilder(popup, null) | ||
.createPopup() | ||
.showInBestPositionFor(context) | ||
return null | ||
} | ||
|
||
override fun getWidgetState(file: VirtualFile?): WidgetState { | ||
val state = WidgetState(getTooltip(), null, true) | ||
state.icon = getIcon() | ||
return state | ||
} | ||
|
||
private fun getTooltip(): String { | ||
if (!isCopilotActive() || !hasEndpoints()) { | ||
return "There are issues while running Vaadin plugin, click to see details" | ||
} | ||
|
||
return "Vaadin plugin is active" | ||
} | ||
|
||
private fun getIcon(): Icon { | ||
if (clicked) { | ||
return iconSupplier.originalIcon | ||
} | ||
|
||
if (!isCopilotActive() || !hasEndpoints()) { | ||
return iconSupplier.warningIcon | ||
} | ||
|
||
return iconSupplier.originalIcon | ||
} | ||
|
||
private fun isCopilotActive(): Boolean { | ||
return CopilotPluginUtil.getDotFile(project) !== null | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
.../copilot/CopilotStatusBarWidgetFactory.kt → ...plugin/ui/VaadinStatusBarWidgetFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package com.vaadin.plugin.copilot | ||
package com.vaadin.plugin.ui | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.wm.StatusBarWidget | ||
import com.intellij.openapi.wm.StatusBarWidgetFactory | ||
|
||
class CopilotStatusBarWidgetFactory : StatusBarWidgetFactory { | ||
class VaadinStatusBarWidgetFactory : StatusBarWidgetFactory { | ||
|
||
override fun getId(): String { | ||
return "CopilotStatusBarWidgetFactory" | ||
return "VaadinStatusBarWidgetFactory" | ||
} | ||
|
||
override fun getDisplayName(): String { | ||
return "Vaadin" | ||
} | ||
|
||
override fun createWidget(project: Project): StatusBarWidget { | ||
return CopilotStatusBarPanel(project) | ||
return VaadinStatusBarWidget(project) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters