Skip to content

Commit 3b34137

Browse files
authored
Adding filter action (#140)
* Adding filter action * Remove Unused import directive
1 parent 094a18f commit 3b34137

19 files changed

Lines changed: 172 additions & 5 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = no.spk.fiskeoye.plugin
44
pluginName = fiskeoye-plugin
55
pluginRepositoryUrl = https://github.com/statens-pensjonskasse/fiskeoye-plugin
66
# SemVer format -> https://semver.org
7-
pluginVersion = 0.0.7
7+
pluginVersion = 0.1.0
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 233

images/fiskeoye_4.png

448 Bytes
Loading

src/main/kotlin/no/spk/fiskeoye/plugin/actions/window/TableAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal abstract class TableAction(
1212
) : FiskeoyeAction(toolTip, icon) {
1313

1414
override fun update(e: AnActionEvent) {
15-
e.presentation.isEnabled = table.rowCount > 0
15+
e.presentation.isEnabled = !table.isEmpty
1616
}
1717

1818
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package no.spk.fiskeoye.plugin.actions.window.filter
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent
4+
import com.intellij.ui.table.JBTable
5+
import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Bitbucket
6+
7+
internal class BitbucketFilterAction(
8+
override val filterState: FilterState,
9+
override val table: JBTable,
10+
) : FilterAction(filterState, table, "Bitbucket", Bitbucket) {
11+
12+
override fun isSelected(e: AnActionEvent): Boolean = filterState.bitbucketIsSelected
13+
14+
override fun setSelected(e: AnActionEvent, state: Boolean) {
15+
filterState.bitbucketIsSelected = state
16+
filter()
17+
}
18+
19+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package no.spk.fiskeoye.plugin.actions.window.filter
2+
3+
import com.intellij.openapi.actionSystem.ToggleAction
4+
import com.intellij.ui.table.JBTable
5+
import no.spk.fiskeoye.plugin.component.LabelIcon
6+
import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Bitbucket
7+
import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Github
8+
import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Warning
9+
import no.spk.fiskeoye.plugin.util.update
10+
import javax.swing.Icon
11+
import javax.swing.RowFilter
12+
import javax.swing.table.TableRowSorter
13+
14+
abstract class FilterAction(open val filterState: FilterState, open val table: JBTable, text: String, icon: Icon) : ToggleAction(text, "", icon) {
15+
16+
fun filter() {
17+
if (table.model.rowCount == 0) return
18+
val sorter = table.rowSorter as? TableRowSorter<*> ?: TableRowSorter(table.model).also {
19+
table.rowSorter = it
20+
}
21+
applyFilter(sorter)
22+
val maxWidth = table.getClientProperty("TABLE_MAX_WIDTH_KEY") as Int
23+
table.update(maxWidth)
24+
}
25+
26+
private fun applyFilter(sorter: TableRowSorter<*>) {
27+
// Create a custom row filter based on your criteria
28+
sorter.rowFilter = object : RowFilter<Any, Int>() {
29+
30+
override fun include(entry: Entry<out Any, out Int>): Boolean {
31+
// Adjust column indices based on your table structure
32+
// Example assumes columns: 0=source, 1=type, etc.
33+
34+
val sourceValue = entry.getValue(0) as LabelIcon // Adjust column index
35+
36+
if (filterState.bitbucketIsSelected && sourceValue.icon == Bitbucket) {
37+
return false
38+
}
39+
40+
if (filterState.githubIsSelected && sourceValue.icon == Github) {
41+
return false
42+
}
43+
44+
if (filterState.warningIsSelected && sourceValue.icon == Warning) {
45+
return false
46+
}
47+
48+
return true
49+
}
50+
}
51+
}
52+
53+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package no.spk.fiskeoye.plugin.actions.window.filter
2+
3+
import com.intellij.openapi.actionSystem.DefaultActionGroup
4+
import com.intellij.ui.table.JBTable
5+
import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Filter
6+
7+
internal class FilterActionGroup(mainTable: JBTable) : DefaultActionGroup("Filter Away", true) {
8+
9+
init {
10+
templatePresentation.icon = Filter
11+
val filterState = FilterState()
12+
mainTable.putClientProperty("FILTER_STATE", filterState)
13+
14+
add(BitbucketFilterAction(filterState, mainTable))
15+
add(GithubFilterAction(filterState, mainTable))
16+
add(WarningFilterAction(filterState, mainTable))
17+
}
18+
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package no.spk.fiskeoye.plugin.actions.window.filter
2+
3+
class FilterState(
4+
var bitbucketIsSelected: Boolean = false,
5+
var githubIsSelected: Boolean = false,
6+
var warningIsSelected: Boolean = false
7+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package no.spk.fiskeoye.plugin.actions.window.filter
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent
4+
import com.intellij.ui.table.JBTable
5+
import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Github
6+
7+
internal class GithubFilterAction(
8+
override val filterState: FilterState,
9+
override val table: JBTable,
10+
) : FilterAction(filterState, table, "Github", Github) {
11+
12+
override fun isSelected(e: AnActionEvent): Boolean = filterState.githubIsSelected
13+
14+
override fun setSelected(e: AnActionEvent, state: Boolean) {
15+
filterState.githubIsSelected = state
16+
filter()
17+
}
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package no.spk.fiskeoye.plugin.actions.window.filter
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent
4+
import com.intellij.ui.table.JBTable
5+
import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Warning
6+
7+
internal class WarningFilterAction(
8+
override val filterState: FilterState,
9+
override val table: JBTable,
10+
) : FilterAction(filterState, table, "Warning", Warning) {
11+
12+
override fun isSelected(e: AnActionEvent): Boolean = filterState.warningIsSelected
13+
14+
override fun setSelected(e: AnActionEvent, state: Boolean) {
15+
filterState.warningIsSelected = state
16+
filter()
17+
}
18+
19+
}

src/main/kotlin/no/spk/fiskeoye/plugin/icons/FiskeoyeIcons.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,7 @@ internal object FiskeoyeIcons {
7474

7575
@JvmField
7676
val Add = IconLoader.getIcon("/icons/add.svg", javaClass)
77+
78+
@JvmField
79+
val Filter = IconLoader.getIcon("/icons/filter.svg", javaClass)
7780
}

0 commit comments

Comments
 (0)