Browse Source

Added: result table, controls and config manager are connected

pull/2/head
veronie 5 years ago
parent
commit
3481a44b0f
23 changed files with 666 additions and 216 deletions
  1. +0
    -15
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/FilterFlagState.java
  2. +0
    -20
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfig.java
  3. +0
    -59
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfigManager.java
  4. +45
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfig.java
  5. +84
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfigManager.java
  6. +57
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java
  7. +106
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingMetaData.java
  8. +29
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java
  9. +1
    -1
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/BggResult.java
  10. +4
    -2
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java
  11. +18
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/FilterFlagState.java
  12. +1
    -1
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/ResultAction.java
  13. +1
    -1
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/SourceFilter.java
  14. +1
    -1
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/Subtype.java
  15. +6
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/SubtypeEvent.java
  16. +1
    -1
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/UserFlag.java
  17. +6
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/UserFlagEvent.java
  18. +53
    -29
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java
  19. +20
    -10
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilter.java
  20. +54
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/SubtypeGroup.java
  21. +0
    -40
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/ThingFilterGroup.java
  22. +142
    -7
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java
  23. +37
    -29
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadFromBggPart.java

+ 0
- 15
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/FilterFlagState.java View File

@@ -1,15 +0,0 @@
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;
}
}

+ 0
- 20
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfig.java View File

@@ -1,20 +0,0 @@
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<Subtype,Boolean> subTypes;
public ResultAction action;
public SourceFilter source;
public String user;
public HashMap<UserFlag, FilterFlagState> userFlags;
public Integer geeklistId;
public Integer familyId;
// TODO: add others
}

+ 0
- 59
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultConfigManager.java View File

@@ -1,59 +0,0 @@
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;
}
}

+ 45
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfig.java View File

@@ -0,0 +1,45 @@
package xyz.veronie.bgg.result;
import java.util.HashMap;
import xyz.veronie.bgg.types.FilterFlagState;
import xyz.veronie.bgg.types.ResultAction;
import xyz.veronie.bgg.types.SourceFilter;
import xyz.veronie.bgg.types.Subtype;
import xyz.veronie.bgg.types.UserFlag;
/// DTO / container for configuration of result download. Also defines startup settings for controls.
/// This container is handled by the ResultConfigManager.
public class ResultConfig {
// TODO: integrate different filters (or extend?)
public SourceFilter source = SourceFilter.BGG_USER;
public ResultAction action = ResultAction.ADD;
public HashMap<Subtype,Boolean> subTypes = new HashMap<Subtype,Boolean>() {
private static final long serialVersionUID = -8718858283141976457L;
{
for (Subtype st : Subtype.values()) {
put(st, false);
}
put(Subtype.BOARDGAME, true);
}};
// bgg user filter settings
public String user = "";
public HashMap<UserFlag, FilterFlagState> userFlags = new HashMap<UserFlag, FilterFlagState>() {
private static final long serialVersionUID = 3086538711393696853L;
{
for (UserFlag uf : UserFlag.values()) {
put(uf, FilterFlagState.IGNORE);
}
put(UserFlag.OWN, FilterFlagState.IS);
put(UserFlag.PREVIOUSLY_OWNED, FilterFlagState.ISNOT);
}};
public Integer geeklistId = null;
public Integer familyId = null;
// TODO: add others
}

+ 84
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ResultConfigManager.java View File

@@ -0,0 +1,84 @@
package xyz.veronie.bgg.result;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.e4.core.di.annotations.Creatable;
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.ResultAction;
import xyz.veronie.bgg.types.SourceFilter;
import xyz.veronie.bgg.types.SubtypeEvent;
import xyz.veronie.bgg.types.UserFlagEvent;
/// This object/instance is responsible for managing the current state of the configuration for
/// BGG result downloads. It is sent an event whenever one of the controls for the
/// configuration changes, and modifies the ResultConfig accordingly.
/// Other parts of the program can ask for the result config to either display its state
/// or execute the BGG download.
@Creatable
@Singleton
public class ResultConfigManager {
private ResultConfig resultConfig;
public ResultConfigManager() {
resultConfig = new ResultConfig();
}
@Inject
@Optional
private void subscribeTopicSourceChanged
(@UIEventTopic(EventConstants.TOPIC_SOURCE_CHANGED)
SourceFilter source) {
getResultConfig().source = source;
System.out.println("TOPIC_SOURCE_CHANGED: source = " + source);
}
@Inject
@Optional
private void subscribeTopicSubtypesChanged
(@UIEventTopic(EventConstants.TOPIC_SUBTYPE_CHANGED)
SubtypeEvent se) {
getResultConfig().subTypes.put(se.subtype, se.checked);
System.out.println("TOPIC_SUBTYPE_CHANGED: " + (se.checked?"[x] ":"[ ] ") + se.subtype);
}
@Inject
@Optional
private void subscribeTopicUserChanged
(@UIEventTopic(EventConstants.TOPIC_USER_CHANGED)
String user) {
System.out.println("set user to '" + user + "'");
getResultConfig().user = user;
System.out.println("TOPIC_USER_CHANGED: user = " + user);
}
@Inject
@Optional
private void subscribeTopicUserFlagChanged
(@UIEventTopic(EventConstants.TOPIC_USERFLAG_CHANGED)
UserFlagEvent e) {
getResultConfig().userFlags.put(e.flag, e.state);
System.out.println("TOPIC_USERFLAG_CHANGED: " + e.flag + " " + e.state);
}
@Inject
@Optional
private void subscribeTopicResultActionChanged
(@UIEventTopic(EventConstants.TOPIC_ACTION_CHANGED)
ResultAction action) {
getResultConfig().action = action;
System.out.println("TOPIC_ACTION_CHANGED: action = " + action);
}
public ResultConfig getResultConfig() {
return resultConfig;
}
}

+ 57
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java View File

@@ -0,0 +1,57 @@
package xyz.veronie.bgg.result;
public class Thing {
Integer id;
String name;
String designer;
String publisher;
String artist;
Integer yearpublished;
Integer minplayers;
Integer maxplayers;
Integer playingtime;
Integer minplaytime;
Integer maxplaytime;
Integer age;
Integer usersrated;
Integer average;
Float bayesaverage;
Integer rank;
Integer rank_wg;
Integer numcomments;
Integer numweights;
Float averageweight;
Float stddev;
Float median;
Boolean owned;
Boolean trading;
Boolean wanting;
Boolean wishing;
Float userrating;
String image;
Integer category;
Integer mechanic;
String comment;
Integer[] players; // 1 to 20
String description;
// exp,
Integer basegameId;
Integer reimplementId;
String reimplement_name;
Integer reimplementedById;
String reimplementedByName;
Integer containsId;
String containsName;
Integer iscontained;
String iscontained_name;
Integer integration;
String integration_name;
Integer numplays;
Float price;
Float userweight;
Integer wishpriority;
Integer expansions;
String domain;
String family;
Float age_poll;
}

+ 106
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingMetaData.java View File

@@ -0,0 +1,106 @@
package xyz.veronie.bgg.result;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
public class ThingMetaData {
private int id;
private Integer rating;
private String imgURL;
private String thumbURL;
private String comment;
private Integer otherId; // ???
private String username;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public ThingMetaData(int id, Integer rating, String imgURL, String thumbURL, String comment, Integer otherId, String username) {
this.setId(id);
this.setRating(rating);
this.setImgURL(imgURL);
this.setThumbURL(thumbURL);
this.setComment(comment);
this.setOtherId(otherId);
this.setUsername(username);
}
public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}
public int getId() {
return id;
}
public void setId(int id) {
propertyChangeSupport.firePropertyChange("id", this.id,
this.id = id);
}
public Integer getRating() {
return rating;
}
public void setRating(Integer rating) {
propertyChangeSupport.firePropertyChange("rating", this.rating,
this.rating = rating);
}
public String getImgURL() {
return imgURL;
}
public void setImgURL(String imgURL) {
propertyChangeSupport.firePropertyChange("img", this.imgURL,
this.imgURL = imgURL);
}
public String getThumbURL() {
return thumbURL;
}
public void setThumbURL(String thumbURL) {
propertyChangeSupport.firePropertyChange("thumb", this.thumbURL,
this.thumbURL = thumbURL);
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
propertyChangeSupport.firePropertyChange("comment", this.comment,
this.comment = comment);
}
public Integer getOtherId() {
return otherId;
}
public void setOtherId(Integer otherId) {
propertyChangeSupport.firePropertyChange("otherId", this.otherId,
this.otherId = otherId);
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
propertyChangeSupport.firePropertyChange("username", this.username,
this.username = username);
}
@Override
public String toString() {
return String.valueOf(id);
}
}

+ 29
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java View File

@@ -0,0 +1,29 @@
package xyz.veronie.bgg.result;
import java.util.ArrayList;
import java.util.List;
public enum ThingProvider {
INSTANCE;
private List<ThingMetaData> thingMetas;
private ThingProvider() {
thingMetas = new ArrayList<ThingMetaData>();
// TODO: retrieve data from BGG
// ...and iterate:
thingMetas.add(new ThingMetaData(
286053,
null,
"https://cf.geekdo-images.com/original/img/vKBCxo7d6maBDC_X9nmC5MWzIC8=/0x0/pic4880614.jpg",
"https://cf.geekdo-images.com/thumb/img/gpeB-GrXrknzAqFKEky1JOvcY4w=/fit-in/200x150/pic4880614.jpg",
"",
65212097,
"veronie"));
}
public List<ThingMetaData> getThingMetas() {
return thingMetas;
}
}

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/BggResult.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/BggResult.java View File

@@ -1,4 +1,4 @@
package xyz.veronie.bgg.data;
package xyz.veronie.bgg.types;
/// This class contains and handles the result table for BGG things
public class BggResult {

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/EventConstants.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java View File

@@ -1,10 +1,10 @@
package xyz.veronie.bgg.data;
package xyz.veronie.bgg.types;
public interface EventConstants {
String TOPIC_CONFIG_CHANGED = "CONFIG_CHANGED/*";
String TOPIC_FILTER_CHANGED = "CONFIG_CHANGED/FILTER";
String TOPIC_SOURCE_CHANGED = "CONFIG_CHANGED/FILTER";
String TOPIC_SUBTYPE_CHANGED = "CONFIG_CHANGED/SUBTYPE";
@@ -14,4 +14,6 @@ public interface EventConstants {
String TOPIC_USER_CHANGED = "CONFIG_CHANGED/USER";
String TOPIC_GEEKLIST_CHANGED = "CONFIG_CHANGED/GEEKLIST";
}

+ 18
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/FilterFlagState.java View File

@@ -0,0 +1,18 @@
package xyz.veronie.bgg.types;
public enum FilterFlagState {
IS("is"),
ISNOT("is not"),
IGNORE("ignore");
private String name;
private FilterFlagState(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/ResultAction.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/ResultAction.java View File

@@ -1,4 +1,4 @@
package xyz.veronie.bgg.data;
package xyz.veronie.bgg.types;
public enum ResultAction {
ADD("add"),

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/SourceFilter.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/SourceFilter.java View File

@@ -1,4 +1,4 @@
package xyz.veronie.bgg.data;
package xyz.veronie.bgg.types;
public enum SourceFilter {

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/Subtype.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/Subtype.java View File

@@ -1,4 +1,4 @@
package xyz.veronie.bgg.data;
package xyz.veronie.bgg.types;
public enum Subtype {
BOARDGAME("Board games", "boardgame"),

+ 6
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/SubtypeEvent.java View File

@@ -0,0 +1,6 @@
package xyz.veronie.bgg.types;
public class SubtypeEvent {
public Subtype subtype;
public Boolean checked;
}

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/data/UserFlag.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/UserFlag.java View File

@@ -1,4 +1,4 @@
package xyz.veronie.bgg.data;
package xyz.veronie.bgg.types;
public enum UserFlag {

+ 6
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/UserFlagEvent.java View File

@@ -0,0 +1,6 @@
package xyz.veronie.bgg.types;
public class UserFlagEvent {
public UserFlag flag;
public FilterFlagState state;
}

+ 53
- 29
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java View File

@@ -1,10 +1,18 @@
package xyz.veronie.bgg.ui.filters;
import java.util.HashMap;
import java.util.Arrays;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.core.services.events.IEventBroker;
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.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
@@ -17,9 +25,11 @@ 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;
import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.FilterFlagState;
import xyz.veronie.bgg.types.UserFlag;
import xyz.veronie.bgg.types.UserFlagEvent;
@@ -28,23 +38,11 @@ import xyz.veronie.bgg.data.UserFlag;
/// 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.)
@Creatable
public class BggUserSourceFilter {
@Inject
private IEventBroker eventBroker;
private HashMap<UserFlag, FilterFlagState> flags = new HashMap<UserFlag, FilterFlagState>() {
private static final long serialVersionUID = 1L;
{
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);
}};
@Inject private IEventBroker eventBroker;
@Inject private ResultConfigManager configManager;
public void create(Composite parent, int style) {
@@ -54,9 +52,23 @@ public class BggUserSourceFilter {
Label lblUser = new Label(parent, SWT.LEFT);
lblUser.setText("User name: ");
lblUser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
// // Define field assists for the text widget
// // use "." and " " activate the content proposals
// char[] autoActivationCharacters = new char[] { '.', ' ' };
// KeyStroke keyStroke;
// try {
// keyStroke = KeyStroke.getInstance("Ctrl+Space");
// new ContentProposalAdapter(text, new TextContentAdapter(),
// new SimpleContentProposalProvider(new String[] { "ProposalOne", "ProposalTwo", "ProposalThree" }),
// keyStroke, autoActivationCharacters);
// } catch (ParseException e1) {
// e1.printStackTrace();
// }
Combo cbUserName = new Combo(parent, SWT.DROP_DOWN);
cbUserName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
cbUserName.setText(configManager.getResultConfig().user);
cbUserName.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
setUser(cbUserName.getText());
@@ -78,6 +90,7 @@ 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));
// TODO: implement edit users
@@ -107,14 +120,25 @@ 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 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
private void makeFilter(Composite parent, UserFlag key) {
ComboViewer filterCombo = new ComboViewer(parent, SWT.READ_ONLY);
filterCombo.setContentProvider(ArrayContentProvider.getInstance());
List<FilterFlagState> states = Arrays.asList(new FilterFlagState[] {
FilterFlagState.IS, FilterFlagState.ISNOT, FilterFlagState.IGNORE
});
filterCombo.setInput(states);
filterCombo.setSelection(new StructuredSelection(configManager.getResultConfig().userFlags.get(key)));
filterCombo.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
UserFlagEvent ufe = new UserFlagEvent();
ufe.flag = key;
ufe.state = (FilterFlagState)selection.getFirstElement();
eventBroker.send(EventConstants.TOPIC_USERFLAG_CHANGED, ufe);
}
});
Label filterLabel = new Label(parent, SWT.LEFT);
filterLabel.setText(key.toString());
@@ -125,7 +149,7 @@ public class BggUserSourceFilter {
if(eventBroker != null) {
eventBroker.post(EventConstants.TOPIC_USER_CHANGED, user);
} else {
System.out.println("null???");
System.out.println("setGeeklistId: eventBroker is null.");
}
}


+ 20
- 10
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilter.java View File

@@ -1,5 +1,9 @@
package xyz.veronie.bgg.ui.filters;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Creatable;
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;
@@ -11,11 +15,17 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
/// These are the controls to retrieve thing IDs for a given family ID
@Creatable
public class GeeklistSourceFilter {
private static Integer geeklistId;
public static void create(Composite parent, int style) {
@Inject private IEventBroker eventBroker;
@Inject ResultConfigManager configManager;
public void create(Composite parent, int style) {
GridLayout filterLayout = new GridLayout(2, false);
parent.setLayout(filterLayout);
@@ -28,7 +38,7 @@ public class GeeklistSourceFilter {
cbGeeklistId.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
setGeeklistId(Integer.getInteger(cbGeeklistId.getText()));
System.out.println("set geeklist id to '" + getGeeklistId() + "'");
System.out.println("set geeklist id to '" + configManager.getResultConfig().geeklistId + "'");
}
});
cbGeeklistId.addFocusListener(new FocusListener() {
@@ -36,7 +46,7 @@ public class GeeklistSourceFilter {
@Override
public void focusLost(FocusEvent e) {
setGeeklistId(Integer.getInteger(cbGeeklistId.getText()));
System.out.println("set geeklist id to '" + getGeeklistId() + "'");
System.out.println("set geeklist id to '" + configManager.getResultConfig().geeklistId + "'");
}
@Override
@@ -47,11 +57,11 @@ public class GeeklistSourceFilter {
parent.layout();
}
public static Integer getGeeklistId() {
return geeklistId;
}
public static void setGeeklistId(Integer geeklistId) {
GeeklistSourceFilter.geeklistId = geeklistId;
public void setGeeklistId(Integer geeklistId) {
if(eventBroker != null) {
eventBroker.post(EventConstants.TOPIC_GEEKLIST_CHANGED, geeklistId);
} else {
System.out.println("setGeeklistId: eventBroker is null.");
}
}
}

+ 54
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/SubtypeGroup.java View File

@@ -0,0 +1,54 @@
package xyz.veronie.bgg.ui.filters;
import java.util.HashMap;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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;
import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.Subtype;
import xyz.veronie.bgg.types.SubtypeEvent;
public class SubtypeGroup {
private HashMap<Subtype, Button> buttons;
public void create(Composite parent, IEventBroker eventBroker, ResultConfigManager configManager) {
Group gSubtype = new Group(parent, SWT.LEFT);
gSubtype.setText("Subtypes");
gSubtype.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
gSubtype.setLayout(new GridLayout(1, false));
buttons = new HashMap<Subtype, Button>();
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));
// init
HashMap<Subtype, Boolean> configuredTypes = configManager.getResultConfig().subTypes;
bb.setSelection(configuredTypes.get(st));
bb.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
SubtypeEvent stEvent = new SubtypeEvent();
stEvent.subtype = st;
stEvent.checked = bb.getSelection();
eventBroker.send(EventConstants.TOPIC_SUBTYPE_CHANGED, stEvent);
}
});
buttons.put(st, bb);
}
}
}

+ 0
- 40
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/ThingFilterGroup.java View File

@@ -1,40 +0,0 @@
package xyz.veronie.bgg.ui.filters;
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;
import xyz.veronie.bgg.data.Subtype;
public class ThingFilterGroup {
private HashMap<Subtype, Button> buttons;
public void create(Composite parent) {
Group gSubtype = new Group(parent, SWT.LEFT);
gSubtype.setText("Subtypes");
gSubtype.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
gSubtype.setLayout(new GridLayout(1, false));
buttons = new HashMap<Subtype, Button>();
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.setSelection(true);
} else {
bb.setSelection(false);
}
// TODO: add listener to buttons. Send event with checked subtypes when something changes.
buttons.put(st, bb);
}
}
}

+ 142
- 7
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java View File

@@ -2,22 +2,157 @@ package xyz.veronie.bgg.ui.parts;
import javax.annotation.PostConstruct;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
//import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import xyz.veronie.bgg.data.ResultConfigManager;
import xyz.veronie.bgg.result.ThingMetaData;
import xyz.veronie.bgg.result.ThingProvider;
public class BggResultPart {
private TableViewer viewer;
@PostConstruct
public void createControls(Composite parent) {
Composite main = new Composite(parent, SWT.FILL);
GridLayout layout = new GridLayout(1, false);
main.setLayout(layout);
Label lblTable = new Label(main, SWT.LEFT);
lblTable.setText("I am a table");
lblTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
createViewer(main);
}
private void createViewer(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
createColumns(parent, viewer);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
// Get the content for the viewer, setInput will call getElements in the
// contentProvider
viewer.setInput(ThingProvider.INSTANCE.getThingMetas());
// make the selection available to other views
// TODO: getSite().setSelectionProvider(viewer);
// Set the sorter for the table
// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
}
public TableViewer getViewer() {
return viewer;
}
// This will create the columns for the table
private void createColumns(final Composite parent, final TableViewer viewer) {
String[] titles = { "Id", "Rating", "Image", "Thumb", "comment", "other Id", "User name" };
int[] bounds = { 100, 100, 100, 100, 100, 100, 100 };
// First column id
TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ThingMetaData t = (ThingMetaData) element;
return String.valueOf(t.getId());
}
});
// Second column rating
col = createTableViewerColumn(titles[1], bounds[1], 1);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ThingMetaData t = (ThingMetaData) element;
return String.valueOf(t.getRating());
}
});
// now img url
col = createTableViewerColumn(titles[2], bounds[2], 2);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ThingMetaData t = (ThingMetaData) element;
return t.getImgURL();
}
});
// thumb url
col = createTableViewerColumn(titles[3], bounds[3], 3);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ThingMetaData t = (ThingMetaData) element;
return t.getThumbURL();
}
});
// comment
col = createTableViewerColumn(titles[4], bounds[4], 4);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ThingMetaData t = (ThingMetaData) element;
return t.getComment();
}
});
// other id
col = createTableViewerColumn(titles[5], bounds[5], 5);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ThingMetaData t = (ThingMetaData) element;
return String.valueOf(t.getOtherId());
}
});
// username
col = createTableViewerColumn(titles[6], bounds[6], 6);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ThingMetaData t = (ThingMetaData) element;
return String.valueOf(t.getUsername());
}
});
}
private TableViewerColumn createTableViewerColumn(String title, int bound, final int colNumber) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
column.setText(title);
column.setWidth(bound);
column.setResizable(true);
column.setMoveable(true);
return viewerColumn;
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
viewer.getControl().setFocus();
}
}

+ 37
- 29
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/LoadFromBggPart.java View File

@@ -4,7 +4,9 @@ import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -24,16 +26,17 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import xyz.veronie.bgg.data.ResultAction;
import xyz.veronie.bgg.data.ResultConfigManager;
import xyz.veronie.bgg.data.SourceFilter;
import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.ResultAction;
import xyz.veronie.bgg.types.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.SubtypeGroup;
import xyz.veronie.bgg.ui.filters.YearSourceFilter;
@@ -42,13 +45,14 @@ import xyz.veronie.bgg.ui.filters.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();
}
@Inject
private ResultConfigManager configManager;
@Inject private IEventBroker eventBroker;
// inject all source filter composites
@Inject private BggUserSourceFilter bggUserSourceFilter;
@Inject private GeeklistSourceFilter geeklistSourceFilter;
@PostConstruct
public void createControls(Composite parent) {
@@ -82,8 +86,8 @@ public class LoadFromBggPart {
cbSource.setInput(sources);
// TODO: implement all the sources
cbSource.setSelection(new StructuredSelection(sources.get(0)));
cbSource.setSelection(new StructuredSelection(configManager.getResultConfig().source));
// listener is configured further below
// choose the bgg sub-site
@@ -91,8 +95,8 @@ public class LoadFromBggPart {
lblSubtype.setText("Subtypes: ");
lblSubtype.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
ThingFilterGroup gSubtypes = new ThingFilterGroup();
gSubtypes.create(dlConfigGroup);
SubtypeGroup gSubtypes = new SubtypeGroup();
gSubtypes.create(dlConfigGroup, eventBroker, configManager);
// choose action on result list
Label lblAct = new Label(dlConfigGroup, SWT.LEFT);
@@ -105,24 +109,29 @@ public class LoadFromBggPart {
ResultAction.ADD, ResultAction.REP, ResultAction.SUB,
ResultAction.AND, ResultAction.MIS });
cbAct.setInput(actions);
cbAct.setSelection(new StructuredSelection(actions.get(0)));
cbAct.setSelection(new StructuredSelection(configManager.getResultConfig().action));
cbAct.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
eventBroker.send(EventConstants.TOPIC_ACTION_CHANGED, selection.getFirstElement());
}
});
// area to display filter controls in
Group gFilters = new Group(main, SWT.SHADOW_ETCHED_IN);
gFilters.setText("");
gFilters.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
showFilter(gFilters, (IStructuredSelection)cbSource.getSelection()); // set content to initial selection
showFilter(gFilters, (IStructuredSelection)cbSource.getSelection()); // set content to initial selection
cbSource.addSelectionChangedListener(new ISelectionChangedListener() { // later, its content will be set via the dropdown
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event
.getSelection();
if (selection.size() > 0) {
// ASK: this is strange to me. Why is filterComposite known INSIDE a free function?
showFilter(gFilters, selection);
}
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
// ASK: this is strange to me. Why is filterComposite known INSIDE a free function?
showFilter(gFilters, selection);
eventBroker.send(EventConstants.TOPIC_SOURCE_CHANGED, selection.getFirstElement());
}
});
@@ -152,14 +161,14 @@ public class LoadFromBggPart {
if(selection.size() == 0) return;
if(selection.getFirstElement() == SourceFilter.BGG_USER) {
String user = resultConfigManager.getResultConfig().user;
String user = configManager.getResultConfig().user;
if(user == null || user.isEmpty()) {
System.out.println("Please enter a user name.");
return;
}
System.out.println("...for user '" + user + "'");
} else if(selection.getFirstElement() == SourceFilter.GEEKLIST) {
System.out.println("...for geeklist id '" + GeeklistSourceFilter.getGeeklistId() + "'");
System.out.println("...for geeklist id '" + configManager.getResultConfig().geeklistId + "'");
} else if(selection.getFirstElement() == SourceFilter.FAMILY) {
System.out.println("...for family id '" + FamilySourceFilter.getFamilyId() + "'");
}
@@ -185,12 +194,11 @@ public class LoadFromBggPart {
switch(elem) {
case BGG_USER:
System.out.println("construct " + elem);
BggUserSourceFilter f = new BggUserSourceFilter();
f.create(parent, SWT.FILL);
bggUserSourceFilter.create(parent, SWT.FILL);
break;
case GEEKLIST:
System.out.println("construct " + elem);
GeeklistSourceFilter.create(parent, SWT.FILL);
geeklistSourceFilter.create(parent, SWT.FILL);
break;
case FAMILY:
System.out.println("construct " + elem);


Loading…
Cancel
Save