| @@ -48,7 +48,7 @@ public class BggApi { | |||
| private static int RETRIES = 5; | |||
| public ArrayList<ThingMetaData> getThingsForUser(String user) throws IllegalArgumentException { | |||
| public ArrayList<Thing> getThingsForUser(String user) throws IllegalArgumentException { | |||
| ResultConfig resultConfig = configManager.getResultConfig(); | |||
| StringBuilder urlStr = new StringBuilder(); | |||
| @@ -85,7 +85,7 @@ public class BggApi { | |||
| } | |||
| public ArrayList<ThingMetaData> getThingsForGeeklist(int geeklistId) throws IllegalArgumentException { | |||
| public ArrayList<Thing> getThingsForGeeklist(int geeklistId) throws IllegalArgumentException { | |||
| ResultConfig resultConfig = configManager.getResultConfig(); | |||
| StringBuilder urlStr = new StringBuilder(); | |||
| @@ -94,7 +94,7 @@ public class BggApi { | |||
| return getThings(urlStr.toString()); | |||
| } | |||
| public ArrayList<ThingMetaData> getThingsForFamily(int familyId) throws IllegalArgumentException { | |||
| public ArrayList<Thing> getThingsForFamily(int familyId) throws IllegalArgumentException { | |||
| ResultConfig resultConfig = configManager.getResultConfig(); | |||
| StringBuilder urlStr = new StringBuilder(); | |||
| @@ -108,7 +108,7 @@ public class BggApi { | |||
| } | |||
| private ArrayList<ThingMetaData> getThings(String urlString) throws IllegalArgumentException { | |||
| private ArrayList<Thing> getThings(String urlString) throws IllegalArgumentException { | |||
| System.out.println("URL: " + urlString); | |||
| try { | |||
| @@ -141,7 +141,8 @@ public class BggApi { | |||
| // do something with the content | |||
| System.out.println(content.toString()); | |||
| ArrayList<ThingMetaData> output = parseThingMetas(content.toString()); | |||
| ArrayList<Thing> output = parseThingMetas(content.toString()); | |||
| return output; | |||
| } | |||
| @@ -165,8 +166,8 @@ public class BggApi { | |||
| private ArrayList<ThingMetaData> parseThingMetas(String content) throws IllegalArgumentException { | |||
| ArrayList<ThingMetaData> metas = new ArrayList<ThingMetaData>(); | |||
| private ArrayList<Thing> parseThingMetas(String content) throws IllegalArgumentException { | |||
| ArrayList<Thing> things = new ArrayList<Thing>(); | |||
| DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |||
| try { | |||
| @@ -201,7 +202,8 @@ public class BggApi { | |||
| getValue(eElement, "comment"), | |||
| Integer.parseInt(getValue(eElement, "numplays")) | |||
| ); | |||
| metas.add(tmd); | |||
| Thing thing = new Thing(id, tmd); | |||
| things.add(thing); | |||
| } | |||
| } | |||
| // family has "type" | |||
| @@ -233,7 +235,8 @@ public class BggApi { | |||
| id, | |||
| eLink.getAttribute("value"), | |||
| "", "", "", null); | |||
| metas.add(tmd); | |||
| Thing thing = new Thing(id, tmd); | |||
| things.add(thing); | |||
| } | |||
| } | |||
| } | |||
| @@ -268,16 +271,17 @@ public class BggApi { | |||
| Integer id = Integer.parseInt(eElement.getAttribute("objectid")); | |||
| if(id != 0) { | |||
| ThingMetaData tmd = new ThingMetaData( | |||
| Integer.parseInt(eElement.getAttribute("objectid")), | |||
| id, | |||
| eElement.getAttribute("objectname"), | |||
| "", "", "", null); | |||
| metas.add(tmd); | |||
| Thing thing = new Thing(id, tmd); | |||
| things.add(thing); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| return metas; | |||
| return things; | |||
| } catch (ParserConfigurationException e) { | |||
| e.printStackTrace(); | |||
| @@ -1,57 +1,66 @@ | |||
| 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; | |||
| } | |||
| package xyz.veronie.bgg.result; | |||
| public class Thing { | |||
| private int id; | |||
| private ThingMetaData metaData; | |||
| private ThingDetails details; | |||
| private static String[] titles = { "Id", "Name" }; | |||
| public Thing(int id, ThingMetaData metaData) { | |||
| this.id = id; | |||
| this.metaData = metaData; | |||
| } | |||
| public int getId() { | |||
| return id; | |||
| } | |||
| public void setId(int id) { | |||
| this.id = id; | |||
| } | |||
| public ThingMetaData getMetaData() { | |||
| return metaData; | |||
| } | |||
| public void setMetaData(ThingMetaData metaData) { | |||
| this.metaData = metaData; | |||
| } | |||
| public ThingDetails getDetails() { | |||
| return details; | |||
| } | |||
| public void setDetails(ThingDetails details) { | |||
| this.details = details; | |||
| } | |||
| public static String[] getTitles() { | |||
| return titles; | |||
| } | |||
| /// get field at idx, order of titles | |||
| public String getField(int idx) { | |||
| if(idx >= titles.length) { | |||
| } | |||
| String returnStr; | |||
| switch(idx) { | |||
| case 0: | |||
| returnStr = String.valueOf(this.id); | |||
| break; | |||
| case 1: | |||
| returnStr = this.getMetaData().getName(); | |||
| break; | |||
| default: | |||
| throw new ArrayIndexOutOfBoundsException( | |||
| "idx " + String.valueOf(idx) + " must be in [0,1]"); | |||
| } | |||
| return returnStr; | |||
| } | |||
| } | |||
| @@ -0,0 +1,57 @@ | |||
| package xyz.veronie.bgg.result; | |||
| public class ThingDetails { | |||
| 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; | |||
| } | |||
| @@ -14,7 +14,6 @@ public class ThingMetaData implements java.io.Serializable { | |||
| private String comment; | |||
| private Integer numPlays; | |||
| private static String[] titles = { "Id", "Name" }; | |||
| private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); | |||
| @@ -29,9 +28,7 @@ public class ThingMetaData implements java.io.Serializable { | |||
| this.setNumPlays(numPlays); | |||
| } | |||
| public static String[] getTitles() { | |||
| return titles; | |||
| } | |||
| public void addPropertyChangeListener(String propertyName, | |||
| PropertyChangeListener listener) { | |||
| @@ -42,29 +39,7 @@ public class ThingMetaData implements java.io.Serializable { | |||
| propertyChangeSupport.removePropertyChangeListener(listener); | |||
| } | |||
| /// get field at idx, order of titles | |||
| public String getField(int idx) { | |||
| if(idx >= titles.length) { | |||
| } | |||
| String returnStr; | |||
| switch(idx) { | |||
| case 0: | |||
| returnStr = String.valueOf(this.id); | |||
| break; | |||
| case 1: | |||
| returnStr = this.name; | |||
| break; | |||
| default: | |||
| throw new ArrayIndexOutOfBoundsException( | |||
| "idx " + String.valueOf(idx) + " must be in [0,1]"); | |||
| } | |||
| return returnStr; | |||
| } | |||
| public int getId() { | |||
| return id; | |||
| @@ -6,7 +6,6 @@ import java.io.IOException; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.function.Predicate; | |||
| import xyz.veronie.bgg.result.ThingMetaData; | |||
| import org.eclipse.core.runtime.Path; | |||
| @@ -16,54 +15,54 @@ public enum ThingProvider { | |||
| INSTANCE; | |||
| /// list of things. Each ID is expected to exist exactly once. | |||
| private List<ThingMetaData> thingMetas; | |||
| private List<Thing> things; | |||
| private ThingProvider() { | |||
| thingMetas = new ArrayList<ThingMetaData>(); | |||
| things = new ArrayList<Thing>(); | |||
| } | |||
| /// replace current list with new list | |||
| public void replaceThingMetas(ArrayList<ThingMetaData> metas) { | |||
| this.thingMetas = metas; | |||
| public void replaceThings(ArrayList<Thing> things) { | |||
| this.things = things; | |||
| } | |||
| /// add things from argument to current list iff their ID does not exist yet | |||
| public void addThingMetas(ArrayList<ThingMetaData> metas) { | |||
| for(ThingMetaData tmd : metas) { | |||
| public void addThings(ArrayList<Thing> things) { | |||
| for(Thing tmd : things) { | |||
| Boolean exists = false; | |||
| for(ThingMetaData thisTmd : this.thingMetas) { | |||
| for(Thing thisTmd : this.things) { | |||
| if(tmd.getId() == thisTmd.getId()) { | |||
| exists = true; | |||
| } | |||
| } | |||
| if(!exists) { | |||
| this.thingMetas.add(tmd); | |||
| this.things.add(tmd); | |||
| } | |||
| } | |||
| } | |||
| // helper function for subtractThingMetas | |||
| private static Predicate<ThingMetaData> thingEqual(final ThingMetaData other) | |||
| private static Predicate<Thing> thingEqual(final Thing 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<ThingMetaData> metas) { | |||
| for(ThingMetaData tmd : metas) { | |||
| this.thingMetas.removeIf(thingEqual(tmd)); | |||
| public void subtractThings(ArrayList<Thing> things) { | |||
| for(Thing thing : things) { | |||
| this.things.removeIf(thingEqual(thing)); | |||
| } | |||
| } | |||
| /// keep only things that exist in both argument list and current list (by ID) | |||
| public void intersectThingMetas(ArrayList<ThingMetaData> metas) { | |||
| List<ThingMetaData> cpMetas = new ArrayList<ThingMetaData>(this.thingMetas); | |||
| this.thingMetas.clear(); | |||
| for(ThingMetaData tmd : metas) { | |||
| for(ThingMetaData thisTmd : cpMetas) { | |||
| if(tmd.getId() == thisTmd.getId()) { | |||
| this.thingMetas.add(tmd); | |||
| public void intersectThings(ArrayList<Thing> things) { | |||
| List<Thing> cpThings = new ArrayList<Thing>(this.things); | |||
| this.things.clear(); | |||
| for(Thing thing : things) { | |||
| for(Thing thisThing : cpThings) { | |||
| if(thing.getId() == thisThing.getId()) { | |||
| this.things.add(thing); | |||
| } | |||
| } | |||
| } | |||
| @@ -90,8 +89,8 @@ public enum ThingProvider { | |||
| // return the current list of ids | |||
| public List<ThingMetaData> getThingMetas() { | |||
| return thingMetas; | |||
| public List<Thing> getThings() { | |||
| return things; | |||
| } | |||
| // @Inject | |||
| @@ -58,7 +58,6 @@ public class BggUserSourceFilter { | |||
| Label lblUser = new Label(mainCompo, 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[] { '.', ' ' }; | |||
| @@ -73,7 +72,9 @@ public class BggUserSourceFilter { | |||
| // } | |||
| cbUserName = new Combo(mainCompo, SWT.DROP_DOWN); | |||
| cbUserName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); | |||
| GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false); | |||
| gd.widthHint = 100; | |||
| cbUserName.setLayoutData(gd); | |||
| cbUserName.setText(configManager.getResultConfig().user); | |||
| cbUserName.addSelectionListener(new SelectionAdapter() { | |||
| public void widgetDefaultSelected(SelectionEvent e) { | |||
| @@ -23,6 +23,7 @@ import org.eclipse.swt.widgets.Label; | |||
| import org.eclipse.swt.widgets.Table; | |||
| import org.eclipse.swt.widgets.TableColumn; | |||
| import xyz.veronie.bgg.result.Thing; | |||
| import xyz.veronie.bgg.result.ThingMetaData; | |||
| import xyz.veronie.bgg.result.ThingProvider; | |||
| import xyz.veronie.bgg.types.EventConstants; | |||
| @@ -62,7 +63,7 @@ public class BggResultPart { | |||
| viewer.setContentProvider(new ArrayContentProvider()); | |||
| // Get the content for the viewer, setInput will call getElements in the | |||
| // contentProvider | |||
| viewer.setInput(ThingProvider.INSTANCE.getThingMetas()); | |||
| viewer.setInput(ThingProvider.INSTANCE.getThings()); | |||
| // make the selection available to other views | |||
| // TODO: getSite().setSelectionProvider(viewer); | |||
| // Set the sorter for the table | |||
| @@ -83,7 +84,7 @@ public class BggResultPart { | |||
| // This will create the columns for the table | |||
| private void createColumns(final Composite parent, final TableViewer viewer) { | |||
| String[] titles = ThingMetaData.getTitles(); | |||
| String[] titles = Thing.getTitles(); | |||
| int[] bounds = { 100, 500 }; // , 100, 100, 100, 100 }; | |||
| for(int i = 0; i < titles.length; ++i) { | |||
| @@ -91,7 +92,7 @@ public class BggResultPart { | |||
| col.setLabelProvider(new ColumnLabelProvider() { | |||
| @Override | |||
| public String getText(Object element) { | |||
| ThingMetaData t = (ThingMetaData) element; | |||
| Thing t = (Thing) element; | |||
| return t.getField((int)col.getColumn().getData()); | |||
| } | |||
| }); | |||
| @@ -125,11 +126,11 @@ public class BggResultPart { | |||
| (@UIEventTopic(EventConstants.TOPIC_RESULT_CHANGED) | |||
| String empty) { | |||
| System.out.println("TOPIC_RESULT_CHANGED"); | |||
| List<ThingMetaData> thingMetas = ThingProvider.INSTANCE.getThingMetas(); | |||
| viewer.setInput(thingMetas); | |||
| List<Thing> things = ThingProvider.INSTANCE.getThings(); | |||
| viewer.setInput(things); | |||
| viewer.refresh(); | |||
| statsLabel.setText(Integer.toString(thingMetas.size()) + " items"); | |||
| statsLabel.setText(Integer.toString(things.size()) + " items"); | |||
| statsLabel.redraw(); | |||
| } | |||
| @@ -30,6 +30,7 @@ import org.eclipse.swt.widgets.Label; | |||
| import xyz.veronie.bgg.result.BggApi; | |||
| import xyz.veronie.bgg.result.ResultConfig; | |||
| import xyz.veronie.bgg.result.ResultConfigManager; | |||
| import xyz.veronie.bgg.result.Thing; | |||
| import xyz.veronie.bgg.result.ThingMetaData; | |||
| import xyz.veronie.bgg.result.ThingProvider; | |||
| import xyz.veronie.bgg.types.EventConstants; | |||
| @@ -152,8 +153,8 @@ public class PreparePart { | |||
| } else { | |||
| eventBroker.send(EventConstants.TOPIC_STATUS, "Fetching " + selection.getFirstElement().toString() + " '" + user + "'..."); | |||
| try { | |||
| ArrayList<ThingMetaData> thingMetas = bggApi.getThingsForUser(user); | |||
| useThingsOnResult(thingMetas); | |||
| ArrayList<Thing> things = bggApi.getThingsForUser(user); | |||
| useThingsOnResult(things); | |||
| } | |||
| catch(IllegalArgumentException ex) { | |||
| MessageDialog.openError(mainComposite.getShell(), "", ex.getMessage()); | |||
| @@ -168,8 +169,8 @@ public class PreparePart { | |||
| } else { | |||
| eventBroker.send(EventConstants.TOPIC_STATUS, "Fetching for geeklist id '" + geeklistId + "'"); | |||
| try { | |||
| ArrayList<ThingMetaData> thingMetas = bggApi.getThingsForGeeklist(geeklistId); | |||
| useThingsOnResult(thingMetas); | |||
| ArrayList<Thing> things = bggApi.getThingsForGeeklist(geeklistId); | |||
| useThingsOnResult(things); | |||
| } | |||
| catch(IllegalArgumentException ex) { | |||
| MessageDialog.openError(mainComposite.getShell(), "", ex.getMessage()); | |||
| @@ -183,8 +184,8 @@ public class PreparePart { | |||
| } else { | |||
| eventBroker.send(EventConstants.TOPIC_STATUS, "Fetching for family id '" + familyId + "'"); | |||
| try { | |||
| ArrayList<ThingMetaData> thingMetas = bggApi.getThingsForFamily(familyId); | |||
| useThingsOnResult(thingMetas); | |||
| ArrayList<Thing> things = bggApi.getThingsForFamily(familyId); | |||
| useThingsOnResult(things); | |||
| } | |||
| catch(IllegalArgumentException ex) { | |||
| MessageDialog.openError(mainComposite.getShell(), "", ex.getMessage()); | |||
| @@ -193,23 +194,23 @@ public class PreparePart { | |||
| } | |||
| } | |||
| private void useThingsOnResult(ArrayList<ThingMetaData> thingMetas) { | |||
| private void useThingsOnResult(ArrayList<Thing> things) { | |||
| switch(configManager.getResultConfig().action) { | |||
| case REP: | |||
| ThingProvider.INSTANCE.replaceThingMetas(thingMetas); | |||
| ThingProvider.INSTANCE.replaceThings(things); | |||
| break; | |||
| case ADD: | |||
| ThingProvider.INSTANCE.addThingMetas(thingMetas); | |||
| ThingProvider.INSTANCE.addThings(things); | |||
| break; | |||
| case SUB: | |||
| ThingProvider.INSTANCE.subtractThingMetas(thingMetas); | |||
| ThingProvider.INSTANCE.subtractThings(things); | |||
| break; | |||
| case AND: | |||
| ThingProvider.INSTANCE.intersectThingMetas(thingMetas); | |||
| ThingProvider.INSTANCE.intersectThings(things); | |||
| break; | |||
| } | |||
| eventBroker.send(EventConstants.TOPIC_RESULT_CHANGED, ""); | |||
| eventBroker.send(EventConstants.TOPIC_STATUS, "Fetched " + Integer.toString(thingMetas.size()) + " things."); | |||
| eventBroker.send(EventConstants.TOPIC_STATUS, "Fetched " + Integer.toString(things.size()) + " things."); | |||
| } | |||
| }); | |||