From 8e5769651a0a012edd8daa472f5b18938cffeb77 Mon Sep 17 00:00:00 2001 From: veronie Date: Sun, 16 Feb 2020 15:45:20 +0100 Subject: [PATCH] started to nicify subtype filters --- .../bgg/ui/contributions/ResultConfig.java | 6 +-- .../veronie/bgg/ui/contributions/Subpage.java | 20 ---------- .../veronie/bgg/ui/contributions/Subtype.java | 28 ++++++++++++++ .../ui/contributions/ThingFilterGroup.java | 37 +++++++++++++++++++ .../veronie/bgg/ui/parts/LoadFromBggPart.java | 17 ++------- 5 files changed, 72 insertions(+), 36 deletions(-) delete mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subpage.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subtype.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ThingFilterGroup.java diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultConfig.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultConfig.java index 62e5c6e..a214334 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultConfig.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultConfig.java @@ -5,7 +5,7 @@ public class ResultConfig { // TODO: integrate different filters (or extend?) private SourceFilter source; - private Subpage subpage; + private Subtype subpage; private ResultAction action; public SourceFilter getSource() { @@ -14,10 +14,10 @@ public class ResultConfig { public void setSource(SourceFilter source) { this.source = source; } - public Subpage getSubpage() { + public Subtype getSubpage() { return subpage; } - public void setSubpage(Subpage subpage) { + public void setSubpage(Subtype subpage) { this.subpage = subpage; } public ResultAction getAction() { diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subpage.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subpage.java deleted file mode 100644 index e4c1930..0000000 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subpage.java +++ /dev/null @@ -1,20 +0,0 @@ -package xyz.veronie.bgg.ui.contributions; - -public enum Subpage { - BOARDGAMES("Board Games"), - RPG("RPGs"), - RPG_ITEMS("RPG Items"), - VIDEOGAMES("Video Games"), - ACCESSORIES("Accessories"); - - private String name; - - private Subpage(String name) { - this.name = name; - } - - @Override - public String toString() { - return this.name; - } -} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subtype.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subtype.java new file mode 100644 index 0000000..0822cff --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subtype.java @@ -0,0 +1,28 @@ +package xyz.veronie.bgg.ui.contributions; + +public enum Subtype { + BOARDGAME("Board games", "boardgame"), + BGEXPANSION("Board game expansions", "boardgameexpansion"), + BGACCESSORIES("Board game accessories", "boardgameaccessory"), + RPG_ISSUES("RPG issues", "rpgissue"), + RPG_ITEMS("RPG items", "rpgitem"), + VIDEOGAMES("Video Games", "videogame"); + + private String name; //< the display name + private String thingTypeString; //< the THINGTYPE string for BGG XMLAPI2 + + private Subtype(String name, String thingtypestr) { + this.name = name; + this.thingTypeString = thingtypestr; + } + + @Override + public String toString() { + return this.name; + } + + /// return the string used in BGG XMLAPI2 to identify the thingtype + public String toSubtypeString() { + return this.thingTypeString; + } +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ThingFilterGroup.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ThingFilterGroup.java new file mode 100644 index 0000000..650d8cb --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ThingFilterGroup.java @@ -0,0 +1,37 @@ +package xyz.veronie.bgg.ui.contributions; + +import java.util.HashMap; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +public class ThingFilterGroup { + private HashMap buttons; + + public void create(Composite parent) { + Group gSubtype = new Group(parent, SWT.LEFT); + gSubtype.setText("Subtypes"); + gSubtype.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); + gSubtype.setLayout(new GridLayout(1, false)); + + buttons = new HashMap(); + + for (Subtype st : Subtype.values()) { + Button bb = new Button(gSubtype, SWT.CHECK); + bb.setText(st.toString()); + if(st == Subtype.BOARDGAME) { + // initially, only boardgame is checked + bb.setEnabled(true); + } else { + bb.setEnabled(false); + } + bb.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + buttons.put(st, bb); + } + } + +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadFromBggPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadFromBggPart.java index 2e1e1b7..eab4a14 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadFromBggPart.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadFromBggPart.java @@ -32,7 +32,8 @@ import xyz.veronie.bgg.ui.contributions.RankSourceFilter; import xyz.veronie.bgg.ui.contributions.ResultAction; import xyz.veronie.bgg.ui.contributions.SearchSourceFilter; import xyz.veronie.bgg.ui.contributions.SourceFilter; -import xyz.veronie.bgg.ui.contributions.Subpage; +import xyz.veronie.bgg.ui.contributions.Subtype; +import xyz.veronie.bgg.ui.contributions.ThingFilterGroup; import xyz.veronie.bgg.ui.contributions.YearSourceFilter; @@ -81,18 +82,8 @@ public class LoadFromBggPart { // choose the bgg sub-site - Label lblTopic = new Label(dlConfigGroup, SWT.LEFT); - lblTopic.setText("Subpage: "); - lblTopic.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); - - ComboViewer cbTopic = new ComboViewer(dlConfigGroup, SWT.READ_ONLY); - cbTopic.setContentProvider(ArrayContentProvider.getInstance()); - List sites = Arrays.asList(new Subpage[] { - Subpage.BOARDGAMES, Subpage.RPG, Subpage.RPG_ITEMS, - Subpage.VIDEOGAMES, Subpage.ACCESSORIES }); - cbTopic.setInput(sites); - cbTopic.setSelection(new StructuredSelection(sites.get(0))); - + ThingFilterGroup gSubtypes = new ThingFilterGroup(); + gSubtypes.create(dlConfigGroup); // choose action on result list Label lblAct = new Label(dlConfigGroup, SWT.LEFT);