diff --git a/core/src/main/groovy/com/muwire/core/content/KeywordMatcher.groovy b/core/src/main/groovy/com/muwire/core/content/KeywordMatcher.groovy index 908818ee..55eff1eb 100644 --- a/core/src/main/groovy/com/muwire/core/content/KeywordMatcher.groovy +++ b/core/src/main/groovy/com/muwire/core/content/KeywordMatcher.groovy @@ -15,6 +15,11 @@ class KeywordMatcher extends Matcher { false } + @Override + public String getTerm() { + keyword + } + @Override public int hashCode() { keyword.hashCode() diff --git a/core/src/main/groovy/com/muwire/core/content/Matcher.groovy b/core/src/main/groovy/com/muwire/core/content/Matcher.groovy index d209c5ea..84b7e003 100644 --- a/core/src/main/groovy/com/muwire/core/content/Matcher.groovy +++ b/core/src/main/groovy/com/muwire/core/content/Matcher.groovy @@ -7,6 +7,8 @@ abstract class Matcher { protected abstract boolean match(String []searchTerms); + public abstract String getTerm(); + public void process(QueryEvent qe) { def terms = qe.searchEvent.searchTerms if (match(terms)) { diff --git a/core/src/main/groovy/com/muwire/core/content/RegexMatcher.groovy b/core/src/main/groovy/com/muwire/core/content/RegexMatcher.groovy index dbb9d38e..3849b23d 100644 --- a/core/src/main/groovy/com/muwire/core/content/RegexMatcher.groovy +++ b/core/src/main/groovy/com/muwire/core/content/RegexMatcher.groovy @@ -15,6 +15,11 @@ class RegexMatcher extends Matcher { return pattern.matcher(combined).find() } + @Override + public String getTerm() { + pattern.pattern() + } + @Override public int hashCode() { pattern.hashCode() diff --git a/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy b/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy index c64cf437..5e27aeec 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/ContentPanelController.groovy @@ -12,7 +12,21 @@ class ContentPanelController { ContentPanelModel model @ControllerAction - void click() { - model.clickCount++ + void addRule() { + } + + @ControllerAction + void deleteRule() { + + } + + @ControllerAction + void keyword() { + model.regex = false + } + + @ControllerAction + void regex() { + model.regex = true } } \ No newline at end of file diff --git a/gui/griffon-app/models/com/muwire/gui/ContentPanelModel.groovy b/gui/griffon-app/models/com/muwire/gui/ContentPanelModel.groovy index 5439df61..9246c474 100644 --- a/gui/griffon-app/models/com/muwire/gui/ContentPanelModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/ContentPanelModel.groovy @@ -1,10 +1,30 @@ package com.muwire.gui +import com.muwire.core.content.ContentManager + import griffon.core.artifact.GriffonModel import griffon.transform.Observable import griffon.metadata.ArtifactProviderFor @ArtifactProviderFor(GriffonModel) class ContentPanelModel { - @Observable int clickCount = 0 + + private ContentManager contentManager + + def rules = [] + def hits = [] + + @Observable boolean regex + + void mvcGroupInit(Map args) { + contentManager = application.context.get("core").contentManager + refresh() + } + + void refresh() { + rules.clear() + rules.addAll(contentManager.matchers) + hits.clear() + // TODO: fire table data changed event + } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy b/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy index e4f5033f..49cda555 100644 --- a/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy @@ -7,6 +7,9 @@ import griffon.metadata.ArtifactProviderFor import javax.swing.JDialog import javax.swing.SwingConstants +import com.muwire.core.content.RegexMatcher + +import java.awt.BorderLayout import java.awt.event.WindowAdapter import java.awt.event.WindowEvent @@ -23,12 +26,38 @@ class ContentPanelView { def mainFrame def mainPanel + def rulesTable + def ruleTextField + void initUI() { mainFrame = application.windowManager.findWindow("main-frame") dialog = new JDialog(mainFrame, "Content Control Panel", true) mainPanel = builder.panel { - label("Stuff goes here") + gridLayout(rows:2, cols:1) + panel { + borderLayout() + scrollPane (constraints : BorderLayout.CENTER) { + rulesTable = table(id : "rules-table", autoCreateRowSorter : true) { + tableModel(list : model.rules) { + closureColumn(header: "Term", type:String, read: {row -> row.getTerm()}) + closureColumn(header: "Regex?", type:Boolean, read: {row -> row instanceof RegexMatcher}) + closureColumn(header: "Hits", type:Integer, read : {row -> row.matches.size()}) + } + } + } + panel (constraints : BorderLayout.SOUTH) { + ruleTextField = textField(action: addRuleAction) + buttonGroup(id : "ruleType") + 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 + } + } + panel { + // TODO: hits table + } } }