mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Java] Add toolbar and button for the scrolling until end in compilation charts
IDEA-356480 GitOrigin-RevId: 0a9f4a9e9eb44dc557286ce32faabd7f4d5b2f72
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fb1a7b145a
commit
c423c74bb9
@@ -6,4 +6,6 @@ charts.production.type=Production
|
||||
charts.test.type=Test
|
||||
charts.memory.type=Memory
|
||||
charts.cpu.type=CPU
|
||||
charts.search.results={0} results
|
||||
charts.search.results={0} results
|
||||
charts.scroll.to.end.action.title = Scroll to End
|
||||
charts.scroll.to.end.action.description = Scrolls to end in compilation charts
|
||||
+6
@@ -18,8 +18,12 @@ class CompilationChartsViewModel(val lifetime: Lifetime) {
|
||||
val statistics: Statistics = Statistics()
|
||||
val cpuMemory: RdProperty<CpuMemoryStatisticsType> = RdProperty(CpuMemoryStatisticsType.MEMORY)
|
||||
val filter: RdProperty<Filter> = RdProperty(Filter())
|
||||
val scrollToEndEvent: RdProperty<ScrollToEndEvent> = RdProperty(ScrollToEndEvent())
|
||||
|
||||
private val threadIndexes: MutableMap<Long, Int> = ConcurrentHashMap()
|
||||
|
||||
fun requestScrollToEnd() = scrollToEndEvent.set(ScrollToEndEvent())
|
||||
|
||||
fun started(values: List<StartTarget>) {
|
||||
values.forEach { value ->
|
||||
modules.add(Modules.StartEvent(value, index(value.thread)))
|
||||
@@ -118,6 +122,8 @@ class CompilationChartsViewModel(val lifetime: Lifetime) {
|
||||
}
|
||||
}
|
||||
|
||||
class ScrollToEndEvent
|
||||
|
||||
enum class CpuMemoryStatisticsType {
|
||||
CPU, MEMORY
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ package com.intellij.java.compiler.charts.ui
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.java.compiler.charts.CompilationChartsBundle
|
||||
import com.intellij.java.compiler.charts.CompilationChartsViewModel
|
||||
import com.intellij.openapi.actionSystem.ActionManager
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.actionSystem.*
|
||||
import com.intellij.openapi.actionSystem.ex.CustomComponentAction
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.popup.IconButton
|
||||
@@ -104,10 +104,42 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart
|
||||
})
|
||||
|
||||
// legend
|
||||
addToRight(JPanel().apply {
|
||||
val actionGroup = DefaultActionGroup({"Some action group"}, listOf(CompilationChartsStatsActionHolder(vm), Separator(), ScrollToEndAction(vm)))
|
||||
addToRight(ActionManager.getInstance().createActionToolbar("Some toolbar", actionGroup, true).component)
|
||||
|
||||
DumbAwareAction.create {
|
||||
val focusManager = IdeFocusManager.getInstance(project)
|
||||
if (focusManager.getFocusedDescendantFor(this@ActionPanel.component) != null) {
|
||||
focusManager.requestFocus(searchField, true)
|
||||
}
|
||||
}.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_FIND).shortcutSet, this@ActionPanel.component)
|
||||
}
|
||||
|
||||
fun updateLabel(set: Set<CompilationChartsViewModel.Modules.EventKey>?, filter: CompilationChartsViewModel.Filter?) {
|
||||
if (set == null || filter == null) {
|
||||
countLabel.text = ""
|
||||
} else {
|
||||
val count = set.count { filter.test(it) }
|
||||
if (count == set.count()) {
|
||||
countLabel.text = ""
|
||||
} else {
|
||||
countLabel.text = CompilationChartsBundle.message("charts.search.results", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ScrollToEndAction(private val vm : CompilationChartsViewModel): DumbAwareAction(
|
||||
CompilationChartsBundle.message("charts.scroll.to.end.action.title"),
|
||||
CompilationChartsBundle.message("charts.scroll.to.end.action.description"),
|
||||
AllIcons.Actions.Forward) {
|
||||
override fun actionPerformed(e: AnActionEvent) = vm.requestScrollToEnd()
|
||||
}
|
||||
|
||||
private class CompilationChartsStatsActionHolder(private val vm: CompilationChartsViewModel) : DumbAwareAction(), CustomComponentAction {
|
||||
|
||||
override fun createCustomComponent(presentation: Presentation, place: String): JComponent = JPanel().apply {
|
||||
layout = BoxLayout(this, BoxLayout.LINE_AXIS)
|
||||
border = JBUI.Borders.empty(2)
|
||||
|
||||
add(JBPanel<JBPanel<*>>(FlowLayout(FlowLayout.LEFT)).apply {
|
||||
val block = JBLabel().apply {
|
||||
preferredSize = Dimension(10, 10)
|
||||
@@ -173,7 +205,6 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart
|
||||
background = COLOR_MEMORY_BORDER
|
||||
}
|
||||
val label = JBLabel(CompilationChartsBundle.message("charts.memory.type"))
|
||||
|
||||
add(block)
|
||||
add(label)
|
||||
|
||||
@@ -194,26 +225,7 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
DumbAwareAction.create {
|
||||
val focusManager = IdeFocusManager.getInstance(project)
|
||||
if (focusManager.getFocusedDescendantFor(this@ActionPanel.component) != null) {
|
||||
focusManager.requestFocus(searchField, true)
|
||||
}
|
||||
}.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_FIND).shortcutSet, this@ActionPanel.component)
|
||||
}
|
||||
|
||||
fun updateLabel(set: Set<CompilationChartsViewModel.Modules.EventKey>?, filter: CompilationChartsViewModel.Filter?) {
|
||||
if (set == null || filter == null) {
|
||||
countLabel.text = ""
|
||||
} else {
|
||||
val count = set.count { filter.test(it) }
|
||||
if (count == set.count()) {
|
||||
countLabel.text = ""
|
||||
} else {
|
||||
countLabel.text = CompilationChartsBundle.message("charts.search.results", count)
|
||||
}
|
||||
}
|
||||
override fun actionPerformed(e: AnActionEvent) = Unit
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,10 @@ class CompilationChartsView(project: Project, private val vm: CompilationChartsV
|
||||
diagrams.cpuMemory = filter
|
||||
diagrams.forceRepaint()
|
||||
}
|
||||
|
||||
vm.scrollToEndEvent.advise(vm.lifetime) { _ ->
|
||||
rightAdhesionScrollBarListener.scrollToEnd()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+5
@@ -47,6 +47,11 @@ internal class RightAdhesionScrollBarListener(private val viewport: JViewport) :
|
||||
shouldScroll = viewport.viewPosition.x + viewport.width + additionalValue >= viewport.viewSize.width
|
||||
}
|
||||
|
||||
fun scrollToEnd() {
|
||||
shouldScroll = true
|
||||
adjustHorizontalScrollToRightIfNeeded()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val LOG = Logger.getInstance(RightAdhesionScrollBarListener::class.java)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user