From 17f9e9ad8f5ee914771fc2e0d5c3690a18f7ff71 Mon Sep 17 00:00:00 2001 From: veronie Date: Wed, 4 Mar 2020 21:32:49 +0100 Subject: [PATCH] Tagging for results (in progress) - Added maven to get gson dependency. --- xyz.veronie.bgg.ui/META-INF/MANIFEST.MF | 3 +- xyz.veronie.bgg.ui/pom.xml | 80 +++++++++++++++++++ .../src/xyz/veronie/bgg/result/BggApi.java | 5 ++ .../xyz/veronie/bgg/result/ResultConfig.java | 2 + .../bgg/result/ResultConfigManager.java | 10 +++ .../xyz/veronie/bgg/result/ThingMetaData.java | 32 +++----- .../xyz/veronie/bgg/result/ThingProvider.java | 62 +++++++++++++- .../xyz/veronie/bgg/types/EventConstants.java | 5 ++ .../src/xyz/veronie/bgg/types/FamilyType.java | 26 ++++++ .../bgg/ui/filters/BggUserSourceFilter.java | 50 ++++++++++-- .../bgg/ui/filters/FamilySourceFilter.java | 34 +++++++- .../bgg/ui/helpers/CommonControls.java | 19 +++++ .../veronie/bgg/ui/parts/BggResultPart.java | 34 +++++++- .../veronie/bgg/ui/parts/LoadFromBggPart.java | 38 ++------- .../bgg/ui/parts/LoadThingDetailsPart.java | 17 ++++ .../xyz/veronie/bgg/ui/parts/StatusBar.java | 6 +- .../target/maven-archiver/pom.properties | 4 + 17 files changed, 350 insertions(+), 77 deletions(-) create mode 100644 xyz.veronie.bgg.ui/pom.xml create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/FamilyType.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/CommonControls.java create mode 100644 xyz.veronie.bgg.ui/target/maven-archiver/pom.properties diff --git a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF index 4147832..a8c27b6 100644 --- a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF +++ b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Require-Bundle: org.eclipse.core.runtime, javax.inject Automatic-Module-Name: de.wt.secondtry Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: javax.inject;version="1.0.0", +Import-Package: com.google.gson;version="2.8.2", + javax.inject;version="1.0.0", org.eclipse.e4.ui.model.application.descriptor.basic, org.eclipse.e4.ui.model.application.ui.basic diff --git a/xyz.veronie.bgg.ui/pom.xml b/xyz.veronie.bgg.ui/pom.xml new file mode 100644 index 0000000..01bb41b --- /dev/null +++ b/xyz.veronie.bgg.ui/pom.xml @@ -0,0 +1,80 @@ + + + + 4.0.0 + + xyz.veronie.bgg + xyz.veronie.bgg.ui + 0.0.1-SNAPSHOT + + xyz.veronie.bgg.ui2 + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + com.google.code.gson + gson + 2.8.6 + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java index 075144b..bb898b5 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/BggApi.java @@ -28,6 +28,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import xyz.veronie.bgg.types.EventConstants; +import xyz.veronie.bgg.types.FamilyType; import xyz.veronie.bgg.types.FilterFlagState; import xyz.veronie.bgg.types.Subtype; import xyz.veronie.bgg.types.UserFlag; @@ -99,6 +100,10 @@ public class BggApi { StringBuilder urlStr = new StringBuilder(); urlStr.append(BASE_URL + FAMILY + "?id=" + String.valueOf(resultConfig.familyId)); + if(resultConfig.familyType != FamilyType.ALL) { + urlStr.append("?type=" + resultConfig.familyType); + } + return getThings(urlStr.toString()); } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfig.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfig.java index c255d2e..aa60f10 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfig.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfig.java @@ -2,6 +2,7 @@ package xyz.veronie.bgg.result; import java.util.HashMap; +import xyz.veronie.bgg.types.FamilyType; import xyz.veronie.bgg.types.FilterFlagState; import xyz.veronie.bgg.types.ResultAction; import xyz.veronie.bgg.types.SourceFilter; @@ -32,6 +33,7 @@ public class ResultConfig { public Integer geeklistId = null; public Integer familyId = null; + public FamilyType familyType = FamilyType.ALL; // TODO: add others diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfigManager.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfigManager.java index b096bc2..d630e09 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfigManager.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfigManager.java @@ -9,6 +9,7 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.di.UIEventTopic; import xyz.veronie.bgg.types.EventConstants; +import xyz.veronie.bgg.types.FamilyType; import xyz.veronie.bgg.types.ResultAction; import xyz.veronie.bgg.types.SourceFilter; import xyz.veronie.bgg.types.Subtype; @@ -94,6 +95,15 @@ public class ResultConfigManager { System.out.println("TOPIC_FAMILY_CHANGED: geeklistId = " + id); } + @Inject + @Optional + private void subscribeTopicResultFamilyChanged + (@UIEventTopic(EventConstants.TOPIC_FAMILYTYPE_CHANGED) + FamilyType ft) { + getResultConfig().familyType = ft; + System.out.println("TOPIC_FAMILYTYPE_CHANGED: family type = " + ft); + } + public ResultConfig getResultConfig() { return resultConfig; } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingMetaData.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingMetaData.java index 5d5a5b5..dd9fe36 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingMetaData.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingMetaData.java @@ -2,9 +2,11 @@ package xyz.veronie.bgg.result; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import com.google.gson.Gson; - -public class ThingMetaData { +public class ThingMetaData implements java.io.Serializable { + private static final long serialVersionUID = -5268898737006538509L; + private int id; private String name; private String imgURL; @@ -12,7 +14,7 @@ public class ThingMetaData { private String comment; private Integer numPlays; - private static String[] titles = { "Id", "Name" }; //, "Image", "Thumb", "comment", "# plays"}; + private static String[] titles = { "Id", "Name" }; private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); @@ -55,25 +57,9 @@ public class ThingMetaData { case 1: returnStr = this.name; break; -// case 2: -// returnStr = this.imgURL; -// break; -// case 3: -// returnStr = this.thumbURL; -// break; -// case 4: -// returnStr = this.comment; -// break; -// case 5: -// if (this.numPlays == null) { -// returnStr = ""; -// } else { -// returnStr = String.valueOf(this.numPlays); -// } -// break; default: throw new ArrayIndexOutOfBoundsException( - "idx " + String.valueOf(idx) + " must be in [0," + (titles.length-1) + "]"); + "idx " + String.valueOf(idx) + " must be in [0,1]"); } return returnStr; @@ -137,8 +123,12 @@ public class ThingMetaData { @Override public String toString() { - return String.valueOf(id); + //return String.valueOf(id); + Gson gson = new Gson(); + return gson.toJson(this); } + + } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java index f88f779..f9c1a61 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java @@ -1,40 +1,67 @@ package xyz.veronie.bgg.result; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; + +import com.google.gson.Gson; + +import xyz.veronie.bgg.types.EventConstants; +import xyz.veronie.bgg.types.SourceFilter; + public enum ThingProvider { INSTANCE; + /// list of things. Each ID is expected to exist exactly once. private List thingMetas; private ThingProvider() { thingMetas = new ArrayList(); } + /// replace current list with new list public void replaceThingMetas(ArrayList metas) { this.thingMetas = metas; } + /// add things from argument to current list iff their ID does not exist yet public void addThingMetas(ArrayList metas) { - this.thingMetas.addAll(metas); + for(ThingMetaData tmd : metas) { + Boolean exists = false; + for(ThingMetaData thisTmd : this.thingMetas) { + if(tmd.getId() == thisTmd.getId()) { + exists = true; + } + } + if(!exists) { + this.thingMetas.add(tmd); + } + } } - - public static Predicate thingEqual(ThingMetaData other) + // helper functino for subtractThingMetas + private static Predicate thingEqual(ThingMetaData other) { return p -> p.getId() == other.getId(); } + /// remove the things in the argument from the current list of things (using their ID) public void subtractThingMetas(ArrayList metas) { for(ThingMetaData tmd : metas) { this.thingMetas.removeIf(thingEqual(tmd)); } } - + /// keep only things that exist in both argument list and current list (by ID) public void intersectThingMetas(ArrayList metas) { List cpMetas = new ArrayList(this.thingMetas); this.thingMetas.clear(); @@ -47,8 +74,35 @@ public enum ThingProvider { } } + /// create a tag of the current list + public void tagResult() { + Gson gson = new Gson(); + String resultList = gson.toJson(this.thingMetas); + + try { + BufferedWriter writer = new BufferedWriter( + new FileWriter("result_" + Long.toString(System.currentTimeMillis()))); + writer.write(resultList); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + // return the current list of ids public List getThingMetas() { return thingMetas; } + + @Inject + @Optional + private void subscribeTopicSourceChanged + (@UIEventTopic(EventConstants.TOPIC_TAG_RESULT) + String str) { + System.out.println("Tag result now."); + this.tagResult(); + } + } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java index 0c47131..5a206a3 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java @@ -18,6 +18,8 @@ public interface EventConstants { String TOPIC_FAMILY_CHANGED = "CONFIG_CHANGED/FAMILY"; + String TOPIC_FAMILYTYPE_CHANGED = "CONFIG_CHANGED/FAMILYTYPE"; + String TOPIC_RESULT_CHANGED = "RESULT_CHANGED"; String TOPIC_STATUS = "STATUS"; @@ -26,4 +28,7 @@ public interface EventConstants { String TOPIC_FAMILY_INFO = "INFO/FAMILY"; + String TOPIC_TAG_RESULT = "EVENT_TAG_RESULT"; + + } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/FamilyType.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/FamilyType.java new file mode 100644 index 0000000..c904631 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/FamilyType.java @@ -0,0 +1,26 @@ +package xyz.veronie.bgg.types; + +public enum FamilyType { + ALL("any", ""), + BG_FAMILY("board game family", "boardgamefamily"), + RPG("RPG", "rpg"), + RPG_PERIODIC("RPG periodical", "rpgperiodical"); + + private String name; //< the display name + private String familyApiString; //< the THINGTYPE string for BGG XMLAPI2 + + private FamilyType(String name, String familyApiString) { + this.name = name; + this.familyApiString = familyApiString; + } + + @Override + public String toString() { + return this.name; + } + + /// return the string used in BGG XMLAPI2 to identify the thingtype + public String toApiString() { + return this.familyApiString; + } +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java index 971410a..007ea58 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java @@ -1,5 +1,6 @@ package xyz.veronie.bgg.ui.filters; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -28,8 +29,10 @@ import org.eclipse.swt.widgets.Label; import xyz.veronie.bgg.result.ResultConfigManager; import xyz.veronie.bgg.types.EventConstants; import xyz.veronie.bgg.types.FilterFlagState; +import xyz.veronie.bgg.types.Subtype; import xyz.veronie.bgg.types.UserFlag; import xyz.veronie.bgg.types.UserFlagEvent; +import xyz.veronie.bgg.ui.helpers.CommonControls; @@ -46,7 +49,7 @@ public class BggUserSourceFilter { public void create(Composite parent, int style) { - GridLayout filterLayout = new GridLayout(4, false); + GridLayout filterLayout = new GridLayout(5, false); parent.setLayout(filterLayout); Label lblUser = new Label(parent, SWT.LEFT); @@ -87,36 +90,67 @@ public class BggUserSourceFilter { } }); - Button btEditUsers = new Button(parent, SWT.PUSH); - btEditUsers.setText("edit users"); - btEditUsers.setEnabled(false); - btEditUsers.setVisible(false); - btEditUsers.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); +// Button btEditUsers = new Button(parent, SWT.PUSH); +// btEditUsers.setText("edit users"); +// btEditUsers.setEnabled(false); +// btEditUsers.setVisible(false); +// btEditUsers.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); // TODO: implement edit users + CommonControls.makeEmptySpace(parent, 1); + + // choose the thing sub-type + Label lblSubtype = new Label(parent, SWT.LEFT); + lblSubtype.setText("Subtypes: "); + lblSubtype.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); + + ComboViewer cbSubtypes = new ComboViewer(parent, SWT.READ_ONLY); + cbSubtypes.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + cbSubtypes.setContentProvider(ArrayContentProvider.getInstance()); + List subtypes = new ArrayList(); + for (Subtype st : Subtype.values()) { + subtypes.add(st); + } + cbSubtypes.setInput(subtypes); + cbSubtypes.setSelection(new StructuredSelection(configManager.getResultConfig().subtype)); + cbSubtypes.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + eventBroker.send(EventConstants.TOPIC_SUBTYPE_CHANGED, selection.getFirstElement()); + } + }); + + + Label infoLabel = new Label(parent, SWT.LEFT); infoLabel.setText("Select which flags are used as filter. Filters follow 'AND' rule."); GridData gdInfo = new GridData(SWT.FILL, SWT.FILL, true, false); - gdInfo.horizontalSpan = 4; + gdInfo.horizontalSpan = 5; infoLabel.setLayoutData(gdInfo); makeFilter(parent, UserFlag.OWN); makeFilter(parent, UserFlag.WTP); + CommonControls.makeEmptySpace(parent, 1); makeFilter(parent, UserFlag.PREVIOUSLY_OWNED); makeFilter(parent, UserFlag.WTB); + CommonControls.makeEmptySpace(parent, 1); makeFilter(parent, UserFlag.TRADE); makeFilter(parent, UserFlag.WISHLIST); + CommonControls.makeEmptySpace(parent, 1); makeFilter(parent, UserFlag.WANT); makeFilter(parent, UserFlag.PREORDERED); + CommonControls.makeEmptySpace(parent, 1); makeFilter(parent, UserFlag.RATED); makeFilter(parent, UserFlag.COMMENT); + CommonControls.makeEmptySpace(parent, 1); makeFilter(parent, UserFlag.PLAYED); - + parent.pack(); parent.getParent().pack(); parent.layout(); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java index ed64bbf..ac8134a 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java @@ -1,5 +1,8 @@ package xyz.veronie.bgg.ui.filters; +import java.util.ArrayList; +import java.util.List; + import javax.inject.Inject; import org.eclipse.e4.core.di.annotations.Creatable; @@ -7,6 +10,12 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.FocusEvent; @@ -21,6 +30,7 @@ import org.eclipse.swt.widgets.Label; import xyz.veronie.bgg.result.ResultConfigManager; import xyz.veronie.bgg.types.EventConstants; +import xyz.veronie.bgg.types.FamilyType; /// These are the controls to retrieve thing IDs for a given family ID @Creatable @@ -45,7 +55,7 @@ public class FamilySourceFilter { if(fid != null) { cbFamilyId.setText(Integer.toString(fid)); } - + cbFamilyId.addSelectionListener(new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { try { @@ -78,6 +88,28 @@ public class FamilySourceFilter { } }); + + Label lblFamilyType = new Label(parent, SWT.LEFT); + lblFamilyType.setText("Family Type: "); + lblFamilyType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + + ComboViewer cbSubtypes = new ComboViewer(parent, SWT.READ_ONLY); + cbSubtypes.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + cbSubtypes.setContentProvider(ArrayContentProvider.getInstance()); + List subtypes = new ArrayList(); + for (FamilyType ft : FamilyType.values()) { + subtypes.add(ft); + } + cbSubtypes.setInput(subtypes); + cbSubtypes.setSelection(new StructuredSelection(configManager.getResultConfig().familyType)); + cbSubtypes.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + eventBroker.send(EventConstants.TOPIC_FAMILYTYPE_CHANGED, selection.getFirstElement()); + } + }); + confLabel = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY); confLabel.setText(""); confLabel.setWordWrap(true); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/CommonControls.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/CommonControls.java new file mode 100644 index 0000000..f9386b9 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/CommonControls.java @@ -0,0 +1,19 @@ +package xyz.veronie.bgg.ui.helpers; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class CommonControls { + public static void makeEmptySpace(Composite parent, int span) { + Label empty = new Label(parent, SWT.LEFT); + empty.setText(""); + GridData gde = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + if(span > 1) { + gde.horizontalSpan = span; + } + empty.setLayoutData(gde); + } + +} 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 056d9c0..898e8b9 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 @@ -1,9 +1,12 @@ package xyz.veronie.bgg.ui.parts; +import java.util.List; + import javax.annotation.PostConstruct; import javax.inject.Inject; import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ColumnLabelProvider; @@ -12,7 +15,9 @@ import org.eclipse.jface.viewers.TableViewerColumn; 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.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; @@ -22,20 +27,35 @@ import xyz.veronie.bgg.types.EventConstants; public class BggResultPart { private TableViewer viewer; + private Label statsLabel; + + @Inject private IEventBroker eventBroker; @PostConstruct public void createControls(Composite parent) { Composite main = new Composite(parent, SWT.FILL); - GridLayout layout = new GridLayout(1, false); + main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + + GridLayout layout = new GridLayout(2, false); main.setLayout(layout); createViewer(main); + + statsLabel = new Label(main, SWT.FILL); + statsLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + statsLabel.setText("0 items"); + + Button tagResultButton = new Button(main, SWT.PUSH); + tagResultButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + tagResultButton.addListener(SWT.SELECTED, event -> { + eventBroker.post(EventConstants.TOPIC_TAG_RESULT, ""); + }); } private void createViewer(Composite parent) { viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER ); createColumns(parent, viewer); final Table table = viewer.getTable(); table.setHeaderVisible(true); @@ -52,10 +72,10 @@ public class BggResultPart { // Layout the viewer GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; - gridData.horizontalSpan = 2; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; + gridData.horizontalSpan = 2; viewer.getControl().setLayoutData(gridData); } @@ -107,8 +127,14 @@ public class BggResultPart { (@UIEventTopic(EventConstants.TOPIC_RESULT_CHANGED) String empty) { System.out.println("TOPIC_RESULT_CHANGED"); - viewer.setInput(ThingProvider.INSTANCE.getThingMetas()); + List thingMetas = ThingProvider.INSTANCE.getThingMetas(); + viewer.setInput(thingMetas); viewer.refresh(); + + statsLabel.setText(Integer.toString(thingMetas.size()) + " items"); + statsLabel.redraw(); } + + } 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 7a450b6..7e9c760 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 @@ -42,6 +42,7 @@ 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.YearSourceFilter; +import xyz.veronie.bgg.ui.helpers.CommonControls; @@ -98,29 +99,9 @@ public class LoadFromBggPart { cbSource.setSelection(new StructuredSelection(configManager.getResultConfig().source)); // listener is configured further below - makeEmptySpace(main, 1); + CommonControls.makeEmptySpace(main, 3); - // choose the thing sub-type - Label lblSubtype = new Label(main, SWT.LEFT); - lblSubtype.setText("Subtypes: "); - lblSubtype.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); - - ComboViewer cbSubtypes = new ComboViewer(main, SWT.READ_ONLY); - cbSubtypes.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - cbSubtypes.setContentProvider(ArrayContentProvider.getInstance()); - List subtypes = new ArrayList(); - for (Subtype st : Subtype.values()) { - subtypes.add(st); - } - cbSubtypes.setInput(subtypes); - cbSubtypes.setSelection(new StructuredSelection(configManager.getResultConfig().subtype)); - cbSubtypes.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event.getSelection(); - eventBroker.send(EventConstants.TOPIC_SUBTYPE_CHANGED, selection.getFirstElement()); - } - }); + @@ -147,7 +128,7 @@ public class LoadFromBggPart { // next row: - makeEmptySpace(main, 5); + CommonControls.makeEmptySpace(main, 5); // next row @@ -242,7 +223,7 @@ public class LoadFromBggPart { ComboViewer cbAct = new ComboViewer(main, SWT.READ_ONLY); GridData gdact = new GridData(SWT.FILL, SWT.FILL, false, false); - cbSubtypes.getCombo().setLayoutData(gdact); + cbAct.getCombo().setLayoutData(gdact); cbAct.setContentProvider(ArrayContentProvider.getInstance()); List actions = new ArrayList(); for(ResultAction act : ResultAction.values()) { @@ -331,14 +312,5 @@ public class LoadFromBggPart { } - public void makeEmptySpace(Composite parent, int span) { - Label empty = new Label(parent, SWT.LEFT); - empty.setText(""); - GridData gde = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); - if(span > 1) { - gde.horizontalSpan = span; - } - empty.setLayoutData(gde); - } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadThingDetailsPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadThingDetailsPart.java index 0a11266..29d1a7b 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadThingDetailsPart.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadThingDetailsPart.java @@ -1,5 +1,22 @@ package xyz.veronie.bgg.ui.parts; +import javax.annotation.PostConstruct; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + public class LoadThingDetailsPart { + @PostConstruct + public void createControls(Composite parent) { + Composite main = new Composite(parent, SWT.FILL); + main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + + GridLayout layout = new GridLayout(5, false); + main.setLayout(layout); + + } + } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/StatusBar.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/StatusBar.java index 8c61291..8c4ffa7 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/StatusBar.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/StatusBar.java @@ -7,16 +7,11 @@ import javax.inject.Inject; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.di.UIEventTopic; -import org.eclipse.jface.resource.ColorDescriptor; -import org.eclipse.jface.resource.DeviceResourceException; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.resource.ResourceManager; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Device; import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -38,6 +33,7 @@ public class StatusBar { statusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // create the manager and bind to a widget + // TODO: do I have to free the color? how? ResourceManager resManager = new LocalResourceManager(JFaceResources.getResources(), statusLabel); statusLabel.setBackground(resManager.createColor(new RGB(255,255,0))); diff --git a/xyz.veronie.bgg.ui/target/maven-archiver/pom.properties b/xyz.veronie.bgg.ui/target/maven-archiver/pom.properties new file mode 100644 index 0000000..19b73cc --- /dev/null +++ b/xyz.veronie.bgg.ui/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.6.3 +version=0.0.1-SNAPSHOT +groupId=xyz.veronie.bgg +artifactId=xyz.veronie.bgg.ui