From 3f95d2bf1d6b0cc8f105e60eed19652712ba7d01 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 9 Jul 2019 21:15:08 +0100 Subject: [PATCH] trust and distrust buttons --- .../muwire/gui/ContentPanelController.groovy | 15 +++++++++++++-- .../com/muwire/gui/ContentPanelView.groovy | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy b/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy index aa022abf..e5ef9f76 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy @@ -9,8 +9,11 @@ import javax.annotation.Nonnull import com.muwire.core.Core import com.muwire.core.EventBus import com.muwire.core.content.ContentControlEvent +import com.muwire.core.content.Match import com.muwire.core.content.Matcher import com.muwire.core.content.RegexMatcher +import com.muwire.core.trust.TrustEvent +import com.muwire.core.trust.TrustLevel @ArtifactProviderFor(GriffonController) class ContentPanelController { @@ -67,12 +70,20 @@ class ContentPanelController { @ControllerAction void trust() { - + int selectedHit = view.getSelectedHit() + if (selectedHit < 0) + return + Match m = model.hits[selectedHit] + core.eventBus.publish(new TrustEvent(persona : m.persona, level : TrustLevel.TRUSTED)) } @ControllerAction void distrust() { - + int selectedHit = view.getSelectedHit() + if (selectedHit < 0) + return + Match m = model.hits[selectedHit] + core.eventBus.publish(new TrustEvent(persona : m.persona, level : TrustLevel.DISTRUSTED)) } void saveMuWireSettings() { diff --git a/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy b/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy index ff95bef3..d2217f8c 100644 --- a/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy @@ -32,6 +32,7 @@ class ContentPanelView { def ruleTextField def lastRulesSortEvent def hitsTable + def lastHitsSortEvent void initUI() { mainFrame = application.windowManager.findWindow("main-frame") @@ -91,6 +92,15 @@ class ContentPanelView { selectedRow } + int getSelectedHit() { + int selectedRow = hitsTable.getSelectedRow() + if (selectedRow < 0) + return -1 + if (lastHitsSortEvent != null) + selectedRow = hitsTable.rowSorter.convertRowIndexToModel(selectedRow) + selectedRow + } + void mvcGroupInit(Map args) { rulesTable.rowSorter.addRowSorterListener({evt -> lastRulesSortEvent = evt}) @@ -111,6 +121,14 @@ class ContentPanelView { } }) + hitsTable.rowSorter.addRowSorterListener({evt -> lastHitsSortEvent = evt}) + hitsTable.rowSorter.setSortsOnUpdates(true) + selectionModel = hitsTable.getSelectionModel() + selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) + selectionModel.addListSelectionListener({ + int selectedRow = getSelectedHit() + model.trustButtonsEnabled = selectedRow >= 0 + }) dialog.getContentPane().add(mainPanel) dialog.pack()