deleting of rules
This commit is contained in:
@@ -22,7 +22,7 @@ class RegexMatcher extends Matcher {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
pattern.hashCode()
|
pattern.pattern().hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,6 +30,6 @@ class RegexMatcher extends Matcher {
|
|||||||
if (!(o instanceof RegexMatcher))
|
if (!(o instanceof RegexMatcher))
|
||||||
return false
|
return false
|
||||||
RegexMatcher other = (RegexMatcher) o
|
RegexMatcher other = (RegexMatcher) o
|
||||||
pattern.equals(other.pattern)
|
pattern.pattern() == other.pattern.pattern()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@ import javax.annotation.Nonnull
|
|||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
import com.muwire.core.EventBus
|
import com.muwire.core.EventBus
|
||||||
import com.muwire.core.content.ContentControlEvent
|
import com.muwire.core.content.ContentControlEvent
|
||||||
|
import com.muwire.core.content.Matcher
|
||||||
|
import com.muwire.core.content.RegexMatcher
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonController)
|
@ArtifactProviderFor(GriffonController)
|
||||||
class ContentPanelController {
|
class ContentPanelController {
|
||||||
@@ -34,7 +36,18 @@ class ContentPanelController {
|
|||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void deleteRule() {
|
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
|
@ControllerAction
|
||||||
|
@@ -26,6 +26,7 @@ class ContentPanelModel {
|
|||||||
def hits = []
|
def hits = []
|
||||||
|
|
||||||
@Observable boolean regex
|
@Observable boolean regex
|
||||||
|
@Observable boolean deleteButtonEnabled
|
||||||
|
|
||||||
void mvcGroupInit(Map<String,String> args) {
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
contentManager = application.context.get("core").contentManager
|
contentManager = application.context.get("core").contentManager
|
||||||
|
@@ -5,6 +5,7 @@ import griffon.inject.MVCMember
|
|||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
import javax.swing.JDialog
|
import javax.swing.JDialog
|
||||||
|
import javax.swing.ListSelectionModel
|
||||||
import javax.swing.SwingConstants
|
import javax.swing.SwingConstants
|
||||||
|
|
||||||
import com.muwire.core.content.RegexMatcher
|
import com.muwire.core.content.RegexMatcher
|
||||||
@@ -28,6 +29,7 @@ class ContentPanelView {
|
|||||||
|
|
||||||
def rulesTable
|
def rulesTable
|
||||||
def ruleTextField
|
def ruleTextField
|
||||||
|
def lastRulesSortEvent
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
mainFrame = application.windowManager.findWindow("main-frame")
|
mainFrame = application.windowManager.findWindow("main-frame")
|
||||||
@@ -54,7 +56,7 @@ class ContentPanelView {
|
|||||||
radioButton(text: "Keyword", selected : true, buttonGroup: ruleType, keywordAction)
|
radioButton(text: "Keyword", selected : true, buttonGroup: ruleType, keywordAction)
|
||||||
radioButton(text: "Regex", selected : false, buttonGroup: ruleType, regexAction)
|
radioButton(text: "Regex", selected : false, buttonGroup: ruleType, regexAction)
|
||||||
button(text : "Add Rule", addRuleAction)
|
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) {
|
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.getContentPane().add(mainPanel)
|
||||||
dialog.pack()
|
dialog.pack()
|
||||||
dialog.setLocationRelativeTo(mainFrame)
|
dialog.setLocationRelativeTo(mainFrame)
|
||||||
|
Reference in New Issue
Block a user