deleting of rules

pull/11/head
Zlatin Balevsky 2019-07-09 20:50:07 +01:00
parent 72b81eb886
commit ce660cefe9
4 changed files with 45 additions and 3 deletions

View File

@ -22,7 +22,7 @@ class RegexMatcher extends Matcher {
@Override
public int hashCode() {
pattern.hashCode()
pattern.pattern().hashCode()
}
@Override
@ -30,6 +30,6 @@ class RegexMatcher extends Matcher {
if (!(o instanceof RegexMatcher))
return false
RegexMatcher other = (RegexMatcher) o
pattern.equals(other.pattern)
pattern.pattern() == other.pattern.pattern()
}
}

View File

@ -9,6 +9,8 @@ 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.Matcher
import com.muwire.core.content.RegexMatcher
@ArtifactProviderFor(GriffonController)
class ContentPanelController {
@ -34,7 +36,18 @@ class ContentPanelController {
@ControllerAction
void deleteRule() {
int rule = view.getSelectedRule()
if (rule < 0)
return
Matcher matcher = model.rules[rule]
String term = matcher.getTerm()
if (matcher instanceof RegexMatcher)
core.muOptions.watchedRegexes.remove(term)
else
core.muOptions.watchedKeywords.remove(term)
saveMuWireSettings()
core.eventBus.publish(new ContentControlEvent(term : term, regex : (matcher instanceof RegexMatcher), add: false))
}
@ControllerAction

View File

@ -26,6 +26,7 @@ class ContentPanelModel {
def hits = []
@Observable boolean regex
@Observable boolean deleteButtonEnabled
void mvcGroupInit(Map<String,String> args) {
contentManager = application.context.get("core").contentManager

View File

@ -5,6 +5,7 @@ import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.swing.JDialog
import javax.swing.ListSelectionModel
import javax.swing.SwingConstants
import com.muwire.core.content.RegexMatcher
@ -28,6 +29,7 @@ class ContentPanelView {
def rulesTable
def ruleTextField
def lastRulesSortEvent
void initUI() {
mainFrame = application.windowManager.findWindow("main-frame")
@ -54,7 +56,7 @@ class ContentPanelView {
radioButton(text: "Keyword", selected : true, buttonGroup: ruleType, keywordAction)
radioButton(text: "Regex", selected : false, buttonGroup: ruleType, regexAction)
button(text : "Add Rule", addRuleAction)
button(text : "Delete Rule", deleteRuleAction) // TODO: enable/disable
button(text : "Delete Rule", enabled : bind {model.deleteButtonEnabled}, deleteRuleAction)
}
}
}
@ -64,7 +66,33 @@ class ContentPanelView {
}
}
int getSelectedRule() {
int selectedRow = rulesTable.getSelectedRow()
if (selectedRow < 0)
return -1
if (lastRulesSortEvent != null)
selectedRow = rulesTable.rowSorter.convertRowIndexToModel(selectedRow)
selectedRow
}
void mvcGroupInit(Map<String,String> args) {
rulesTable.rowSorter.addRowSorterListener({evt -> lastRulesSortEvent = evt})
rulesTable.rowSorter.setSortsOnUpdates(true)
def selectionModel = rulesTable.getSelectionModel()
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
selectionModel.addListSelectionListener({
int selectedRow = getSelectedRule()
if (selectedRow < 0) {
model.deleteButtonEnabled = false
return
} else {
model.deleteButtonEnabled = true
// TODO: populate hits table
}
})
dialog.getContentPane().add(mainPanel)
dialog.pack()
dialog.setLocationRelativeTo(mainFrame)