From 8e5769651a0a012edd8daa472f5b18938cffeb77 Mon Sep 17 00:00:00 2001 From: veronie Date: Sun, 16 Feb 2020 15:45:20 +0100 Subject: [PATCH 1/3] 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); From f5a5283ee0cdcf1ca0518e6dc17aeaea15b7cd99 Mon Sep 17 00:00:00 2001 From: veronie Date: Sun, 16 Feb 2020 19:01:59 +0100 Subject: [PATCH 2/3] Added objects that keep the state of the config for bgg result retrieval. Trying to use the event broker, no luck... --- xyz.veronie.bgg.ui/META-INF/MANIFEST.MF | 5 +- .../src/xyz/veronie/bgg/data/BggResult.java | 2 +- .../xyz/veronie/bgg/data/EventConstants.java | 17 ++++ .../xyz/veronie/bgg/data/FilterFlagState.java | 15 ++++ .../contributions => data}/ResultAction.java | 2 +- .../xyz/veronie/bgg/data/ResultConfig.java | 20 +++++ .../veronie/bgg/data/ResultConfigManager.java | 59 +++++++++++++ .../contributions => data}/SourceFilter.java | 2 +- .../{ui/contributions => data}/Subtype.java | 2 +- .../src/xyz/veronie/bgg/data/UserFlag.java | 24 +++++ .../bgg/ui/contributions/BggResult.java | 6 -- .../bgg/ui/contributions/ResultConfig.java | 30 ------- .../AgeSourceFilter.java | 2 +- .../BggUserSourceFilter.java | 88 +++++++------------ .../FamilySourceFilter.java | 2 +- .../GeeklistSourceFilter.java | 2 +- .../RankSourceFilter.java | 2 +- .../SearchSourceFilter.java | 2 +- .../ThingFilterGroup.java | 13 +-- .../YearSourceFilter.java | 2 +- .../veronie/bgg/ui/parts/BggResultPart.java | 3 +- .../veronie/bgg/ui/parts/LoadFromBggPart.java | 43 +++++---- 22 files changed, 215 insertions(+), 128 deletions(-) create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/EventConstants.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/FilterFlagState.java rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/{ui/contributions => data}/ResultAction.java (80%) create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfig.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfigManager.java rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/{ui/contributions => data}/SourceFilter.java (89%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/{ui/contributions => data}/Subtype.java (91%) create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/UserFlag.java delete mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/BggResult.java delete mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultConfig.java rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/AgeSourceFilter.java (90%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/BggUserSourceFilter.java (67%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/FamilySourceFilter.java (94%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/GeeklistSourceFilter.java (95%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/RankSourceFilter.java (90%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/SearchSourceFilter.java (90%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/ThingFilterGroup.java (72%) rename xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/{contributions => filters}/YearSourceFilter.java (90%) diff --git a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF index b30ea9f..aef5ead 100644 --- a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF +++ b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF @@ -12,6 +12,9 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.17.0", org.eclipse.e4.ui.di;bundle-version="1.2.700", org.eclipse.e4.core.di.extensions;bundle-version="0.15.400", javax.annotation;bundle-version="1.2.0", - org.eclipse.jface;bundle-version="3.18.0" + org.eclipse.jface;bundle-version="3.18.0", + org.eclipse.e4.core.services;bundle-version="2.2.100", + org.eclipse.osgi.services;bundle-version="3.8.0", + javax.inject;bundle-version="1.0.0" Import-Package: org.eclipse.e4.ui.model.application.descriptor.basic, org.eclipse.e4.ui.model.application.ui.basic diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/BggResult.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/BggResult.java index 6a86859..e69c5f6 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/BggResult.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/BggResult.java @@ -1,6 +1,6 @@ package xyz.veronie.bgg.data; -/// This class contains and handles the result table for initial BGG result +/// This class contains and handles the result table for BGG things public class BggResult { } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/EventConstants.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/EventConstants.java new file mode 100644 index 0000000..031f336 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/EventConstants.java @@ -0,0 +1,17 @@ +package xyz.veronie.bgg.data; + +public interface EventConstants { + + String TOPIC_CONFIG_CHANGED = "CONFIG_CHANGED/*"; + + String TOPIC_FILTER_CHANGED = "CONFIG_CHANGED/FILTER"; + + String TOPIC_SUBTYPE_CHANGED = "CONFIG_CHANGED/SUBTYPE"; + + String TOPIC_USERFLAG_CHANGED = "CONFIG_CHANGED/USERFLAG"; + + String TOPIC_ACTION_CHANGED = "CONFIG_CHANGED/ACTION"; + + String TOPIC_USER_CHANGED = "CONFIG_CHANGED/USER"; + +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/FilterFlagState.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/FilterFlagState.java new file mode 100644 index 0000000..8844b6e --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/FilterFlagState.java @@ -0,0 +1,15 @@ +package xyz.veronie.bgg.data; + +public enum FilterFlagState { + IS(0), ISNOT(1), IGNORE(2); + + private int state; + + private FilterFlagState(int state) { + this.state = state; + } + + public int get() { + return this.state; + } +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultAction.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultAction.java similarity index 80% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultAction.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultAction.java index 46d2a52..12739e9 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultAction.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultAction.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.data; public enum ResultAction { ADD("add"), diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfig.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfig.java new file mode 100644 index 0000000..b915c45 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfig.java @@ -0,0 +1,20 @@ +package xyz.veronie.bgg.data; + +import java.util.HashMap; + +/// DTO / container for configuration of result download +public class ResultConfig { + // TODO: integrate different filters (or extend?) + + public HashMap subTypes; + public ResultAction action; + public SourceFilter source; + + public String user; + public HashMap userFlags; + + public Integer geeklistId; + public Integer familyId; + // TODO: add others + +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfigManager.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfigManager.java new file mode 100644 index 0000000..3c852b9 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfigManager.java @@ -0,0 +1,59 @@ +package xyz.veronie.bgg.data; + + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; + +public class ResultConfigManager { + + private ResultConfig resultConfig = new ResultConfig(); + + @Inject + @Optional + private void subscribeTopicSourceFilterChanged + (@UIEventTopic(EventConstants.TOPIC_FILTER_CHANGED) + SourceFilter source) { + getResultConfig().source = source; + } + + @Inject + @Optional + private void subscribeTopicSubtypesChanged + (@UIEventTopic(EventConstants.TOPIC_SUBTYPE_CHANGED) + Subtype subtype, Boolean checked) { + getResultConfig().subTypes.put(subtype, checked); + } + + @Inject + @Optional + private void subscribeTopicUserChanged + (@UIEventTopic(EventConstants.TOPIC_USER_CHANGED) + String user) { + System.out.println("set user to '" + user + "'"); + getResultConfig().user = user; + } + + @Inject + @Optional + private void subscribeTopicUserFlagChanged + (@UIEventTopic(EventConstants.TOPIC_USERFLAG_CHANGED) + UserFlag flag, FilterFlagState state) { + getResultConfig().userFlags.put(flag, state); + } + + @Inject + @Optional + private void subscribeTopicResultActionChanged + (@UIEventTopic(EventConstants.TOPIC_ACTION_CHANGED) + ResultAction action) { + getResultConfig().action = action; + } + + public ResultConfig getResultConfig() { + return resultConfig; + } + + +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/SourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/SourceFilter.java similarity index 89% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/SourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/SourceFilter.java index 463ab52..03f4573 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/SourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/SourceFilter.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.data; public enum SourceFilter { diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subtype.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/Subtype.java similarity index 91% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subtype.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/Subtype.java index 0822cff..ded73b8 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/Subtype.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/Subtype.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.data; public enum Subtype { BOARDGAME("Board games", "boardgame"), diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/UserFlag.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/UserFlag.java new file mode 100644 index 0000000..4984d62 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/UserFlag.java @@ -0,0 +1,24 @@ +package xyz.veronie.bgg.data; + +public enum UserFlag { + + OWN("owned"), + PREVIOUSLY_OWNED("previously owned"), + FOR_TRADE("for trade"), + WANTED("wanted"), + WTP("want to play"), + WTB("want to buy"), + WISHLIST("on wishlist"), + PREORDERED("preordered"); + + private String flag; + + private UserFlag(String flag) { + this.flag = flag; + } + + @Override + public String toString() { + return this.flag; + } +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/BggResult.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/BggResult.java deleted file mode 100644 index 9838433..0000000 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/BggResult.java +++ /dev/null @@ -1,6 +0,0 @@ -package xyz.veronie.bgg.ui.contributions; - -/// this represents a result of bgg "things" -public class BggResult { - -} 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 deleted file mode 100644 index a214334..0000000 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ResultConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -package xyz.veronie.bgg.ui.contributions; - -/// container for configuration of result download -public class ResultConfig { - // TODO: integrate different filters (or extend?) - - private SourceFilter source; - private Subtype subpage; - private ResultAction action; - - public SourceFilter getSource() { - return source; - } - public void setSource(SourceFilter source) { - this.source = source; - } - public Subtype getSubpage() { - return subpage; - } - public void setSubpage(Subtype subpage) { - this.subpage = subpage; - } - public ResultAction getAction() { - return action; - } - public void setAction(ResultAction action) { - this.action = action; - } - -} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/AgeSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/AgeSourceFilter.java similarity index 90% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/AgeSourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/AgeSourceFilter.java index 66ae1b9..0d470d1 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/AgeSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/AgeSourceFilter.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/BggUserSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java similarity index 67% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/BggUserSourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java index ef8162d..771406b 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/BggUserSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java @@ -1,7 +1,10 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import java.util.HashMap; +import javax.inject.Inject; + +import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; @@ -14,65 +17,36 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; +import xyz.veronie.bgg.data.EventConstants; +import xyz.veronie.bgg.data.FilterFlagState; +import xyz.veronie.bgg.data.UserFlag; + + -enum FilterState { - IS(0), ISNOT(1), IGNORE(2); - - private int state; - - private FilterState(int state) { - this.state = state; - } - - public int get() { - return this.state; - } -} -enum UserFlag { - - OWN("owned"), - PREVIOUSLY_OWNED("previously owned"), - FOR_TRADE("for trade"), - WANTED("wanted"), - WTP("want to play"), - WTB("want to buy"), - WISHLIST("on wishlist"), - PREORDERED("preordered"); - - private String flag; - - private UserFlag(String flag) { - this.flag = flag; - } - - @Override - public String toString() { - return this.flag; - } -} /// These are the controls to retrieve thing IDs for a given BGG user /// Filters can be set for the state of the thing in the user's collection /// (i.e. owned, previously owned, wishlist, etc.) public class BggUserSourceFilter { - // TODO: have to protect this static because threading? - private static String user = ""; - private static HashMap flags = new HashMap() { + @Inject + private IEventBroker eventBroker; + + private HashMap flags = new HashMap() { private static final long serialVersionUID = 1L; { - put(UserFlag.OWN, FilterState.IS); - put(UserFlag.PREVIOUSLY_OWNED, FilterState.ISNOT); - put(UserFlag.FOR_TRADE, FilterState.IGNORE); - put(UserFlag.WANTED, FilterState.IGNORE); - put(UserFlag.WTP, FilterState.IGNORE); - put(UserFlag.WTB, FilterState.IGNORE); - put(UserFlag.WISHLIST, FilterState.IGNORE); - put(UserFlag.PREORDERED, FilterState.IGNORE); + put(UserFlag.OWN, FilterFlagState.IS); + put(UserFlag.PREVIOUSLY_OWNED, FilterFlagState.ISNOT); + put(UserFlag.FOR_TRADE, FilterFlagState.IGNORE); + put(UserFlag.WANTED, FilterFlagState.IGNORE); + put(UserFlag.WTP, FilterFlagState.IGNORE); + put(UserFlag.WTB, FilterFlagState.IGNORE); + put(UserFlag.WISHLIST, FilterFlagState.IGNORE); + put(UserFlag.PREORDERED, FilterFlagState.IGNORE); }}; - public static void create(Composite parent, int style) { + public void create(Composite parent, int style) { GridLayout filterLayout = new GridLayout(4, false); parent.setLayout(filterLayout); @@ -86,7 +60,6 @@ public class BggUserSourceFilter { cbUserName.addSelectionListener(new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { setUser(cbUserName.getText()); - System.out.println("set user to '" + getUser() + "'"); } }); cbUserName.addFocusListener(new FocusListener() { @@ -134,27 +107,26 @@ public class BggUserSourceFilter { // Filters are tri-state: include iff has flag, include iff it does not have the flag, // don't care if it has that flag. // TODO: create a three-way toggle button instead. - private static void makeFilter(Composite parent, UserFlag key) { + private void makeFilter(Composite parent, UserFlag key) { Combo filterCombo = new Combo(parent, SWT.READ_ONLY); filterCombo.add("is"); filterCombo.add("is not"); filterCombo.add("ignored"); filterCombo.select(flags.get(key).get()); filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + // TODO: add listener - send a CONFIG_CHANGED event when something changes Label filterLabel = new Label(parent, SWT.LEFT); filterLabel.setText(key.toString()); filterLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); } - - public static String getUser() { - return user; - } - - - public static void setUser(String user) { - BggUserSourceFilter.user = user; + public void setUser(String user) { + if(eventBroker != null) { + eventBroker.post(EventConstants.TOPIC_USER_CHANGED, user); + } else { + System.out.println("null???"); + } } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/FamilySourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java similarity index 94% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/FamilySourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java index f21b3cc..cf46f08 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/FamilySourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/GeeklistSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilter.java similarity index 95% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/GeeklistSourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilter.java index dca0a98..47faa0c 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/GeeklistSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilter.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/RankSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/RankSourceFilter.java similarity index 90% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/RankSourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/RankSourceFilter.java index 9f4f94d..d0364f5 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/RankSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/RankSourceFilter.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/SearchSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/SearchSourceFilter.java similarity index 90% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/SearchSourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/SearchSourceFilter.java index 752bb15..7cdaaab 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/SearchSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/SearchSourceFilter.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; 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/filters/ThingFilterGroup.java similarity index 72% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ThingFilterGroup.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/ThingFilterGroup.java index 650d8cb..b61e103 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/ThingFilterGroup.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/ThingFilterGroup.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import java.util.HashMap; @@ -9,13 +9,15 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; +import xyz.veronie.bgg.data.Subtype; + 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.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); gSubtype.setLayout(new GridLayout(1, false)); buttons = new HashMap(); @@ -23,13 +25,14 @@ public class ThingFilterGroup { for (Subtype st : Subtype.values()) { Button bb = new Button(gSubtype, SWT.CHECK); bb.setText(st.toString()); + bb.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); if(st == Subtype.BOARDGAME) { // initially, only boardgame is checked - bb.setEnabled(true); + bb.setSelection(true); } else { - bb.setEnabled(false); + bb.setSelection(false); } - bb.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + // TODO: add listener to buttons. Send event with checked subtypes when something changes. buttons.put(st, bb); } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/YearSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/YearSourceFilter.java similarity index 90% rename from xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/YearSourceFilter.java rename to xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/YearSourceFilter.java index bdd84c3..c7ece46 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/contributions/YearSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/YearSourceFilter.java @@ -1,4 +1,4 @@ -package xyz.veronie.bgg.ui.contributions; +package xyz.veronie.bgg.ui.filters; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java index 16b5111..a8b5baf 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java @@ -8,11 +8,12 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; +import xyz.veronie.bgg.data.ResultConfigManager; + public class BggResultPart { @PostConstruct public void createControls(Composite parent) { - Composite main = new Composite(parent, SWT.FILL); Label lblTable = new Label(main, SWT.LEFT); 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 eab4a14..65e65a7 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 @@ -24,17 +24,17 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import xyz.veronie.bgg.ui.contributions.AgeSourceFilter; -import xyz.veronie.bgg.ui.contributions.BggUserSourceFilter; -import xyz.veronie.bgg.ui.contributions.FamilySourceFilter; -import xyz.veronie.bgg.ui.contributions.GeeklistSourceFilter; -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.Subtype; -import xyz.veronie.bgg.ui.contributions.ThingFilterGroup; -import xyz.veronie.bgg.ui.contributions.YearSourceFilter; +import xyz.veronie.bgg.data.ResultAction; +import xyz.veronie.bgg.data.ResultConfigManager; +import xyz.veronie.bgg.data.SourceFilter; +import xyz.veronie.bgg.ui.filters.AgeSourceFilter; +import xyz.veronie.bgg.ui.filters.BggUserSourceFilter; +import xyz.veronie.bgg.ui.filters.FamilySourceFilter; +import xyz.veronie.bgg.ui.filters.GeeklistSourceFilter; +import xyz.veronie.bgg.ui.filters.RankSourceFilter; +import xyz.veronie.bgg.ui.filters.SearchSourceFilter; +import xyz.veronie.bgg.ui.filters.ThingFilterGroup; +import xyz.veronie.bgg.ui.filters.YearSourceFilter; @@ -42,11 +42,16 @@ import xyz.veronie.bgg.ui.contributions.YearSourceFilter; /// There are different ways to configure which IDs to retrieve. public class LoadFromBggPart { + // TODO: figure out how to make sure this is a singleton + private ResultConfigManager resultConfigManager; + LoadFromBggPart() { + resultConfigManager = new ResultConfigManager(); + } + @PostConstruct public void createControls(Composite parent) { - Composite main = new Composite(parent, SWT.FILL); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); @@ -82,6 +87,10 @@ public class LoadFromBggPart { // choose the bgg sub-site + Label lblSubtype = new Label(dlConfigGroup, SWT.LEFT); + lblSubtype.setText("Subtypes: "); + lblSubtype.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); + ThingFilterGroup gSubtypes = new ThingFilterGroup(); gSubtypes.create(dlConfigGroup); @@ -143,11 +152,12 @@ public class LoadFromBggPart { if(selection.size() == 0) return; if(selection.getFirstElement() == SourceFilter.BGG_USER) { - if(BggUserSourceFilter.getUser().isEmpty()) { + String user = resultConfigManager.getResultConfig().user; + if(user == null || user.isEmpty()) { System.out.println("Please enter a user name."); return; } - System.out.println("...for user '" + BggUserSourceFilter.getUser() + "'"); + System.out.println("...for user '" + user + "'"); } else if(selection.getFirstElement() == SourceFilter.GEEKLIST) { System.out.println("...for geeklist id '" + GeeklistSourceFilter.getGeeklistId() + "'"); } else if(selection.getFirstElement() == SourceFilter.FAMILY) { @@ -156,8 +166,6 @@ public class LoadFromBggPart { } }); btDownload.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); - - main.pack(); @@ -177,7 +185,8 @@ public class LoadFromBggPart { switch(elem) { case BGG_USER: System.out.println("construct " + elem); - BggUserSourceFilter.create(parent, SWT.FILL); + BggUserSourceFilter f = new BggUserSourceFilter(); + f.create(parent, SWT.FILL); break; case GEEKLIST: System.out.println("construct " + elem); From f2df8db5ca291cad991c1029e5ede0af97de9fae Mon Sep 17 00:00:00 2001 From: veronie Date: Mon, 17 Feb 2020 10:05:30 +0100 Subject: [PATCH 3/3] removed minimum version from dependencies --- README.md | 4 ++-- xyz.veronie.bgg.ui/META-INF/MANIFEST.MF | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6fd95b7..4f5b4fd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# BggToolAnother - +# BggToolAnother + An Eclipse RCP reimplementation of bgg1tool by Nand. See http://www.nand.it/nandeck/ for the original tool. diff --git a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF index aef5ead..a204809 100644 --- a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF +++ b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF @@ -5,16 +5,16 @@ Bundle-SymbolicName: xyz.veronie.bgg.ui;singleton:=true Bundle-Version: 1.0.0.qualifier Automatic-Module-Name: de.wt.secondtry Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.17.0", - org.eclipse.swt;bundle-version="3.113.0", - org.eclipse.e4.core.di;bundle-version="1.7.500", - org.eclipse.e4.ui.workbench;bundle-version="1.11.0", - org.eclipse.e4.ui.di;bundle-version="1.2.700", - org.eclipse.e4.core.di.extensions;bundle-version="0.15.400", - javax.annotation;bundle-version="1.2.0", - org.eclipse.jface;bundle-version="3.18.0", - org.eclipse.e4.core.services;bundle-version="2.2.100", - org.eclipse.osgi.services;bundle-version="3.8.0", - javax.inject;bundle-version="1.0.0" +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.swt, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.workbench, + org.eclipse.e4.ui.di, + org.eclipse.e4.core.di.extensions, + javax.annotation, + org.eclipse.jface, + org.eclipse.e4.core.services, + org.eclipse.osgi.services, + javax.inject Import-Package: org.eclipse.e4.ui.model.application.descriptor.basic, org.eclipse.e4.ui.model.application.ui.basic