Slightly rearranged metadata (some fields are now in ThingUserData). Filling ThingUserData when fetching by user with BggApi. Added ExportResultHandler.pull/16/head
@@ -24,12 +24,14 @@ | |||||
<handlers xmi:id="_a0tuEGAUEeuNUoCJDLJTzQ" elementId="xyz.veronie.bgg.ui.handler.save" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.SaveGamelistHandler" command="_lA5t8F9TEeuvNqpgCDWpdQ"/> | <handlers xmi:id="_a0tuEGAUEeuNUoCJDLJTzQ" elementId="xyz.veronie.bgg.ui.handler.save" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.SaveGamelistHandler" command="_lA5t8F9TEeuvNqpgCDWpdQ"/> | ||||
<handlers xmi:id="_xJXjUG3zEeuCP7xCflu8WA" elementId="xyz.veronie.bgg.ui.handler.load" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.LoadGamelistHandler" command="_qyrHAG3zEeuCP7xCflu8WA"/> | <handlers xmi:id="_xJXjUG3zEeuCP7xCflu8WA" elementId="xyz.veronie.bgg.ui.handler.load" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.LoadGamelistHandler" command="_qyrHAG3zEeuCP7xCflu8WA"/> | ||||
<handlers xmi:id="_y97SUG7REeutwMlAyj2x8w" elementId="xyz.veronie.bgg.ui.handler.importResultTxt" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.ImportResultTxtHandler" command="_rkauIG7REeutwMlAyj2x8w"/> | <handlers xmi:id="_y97SUG7REeutwMlAyj2x8w" elementId="xyz.veronie.bgg.ui.handler.importResultTxt" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.ImportResultTxtHandler" command="_rkauIG7REeutwMlAyj2x8w"/> | ||||
<handlers xmi:id="_I0EUoHOzEeuMU7Jt9moleA" elementId="xyz.veronie.bgg.ui.handler.export" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.ExportResultHandler" command="_OUnzIHOzEeuMU7Jt9moleA"/> | |||||
<menuContributions xmi:id="_AitwEHBeEeuk7d_98DxC5A" elementId="xyz.veronie.bgg.ui.menucontribution.gamelists" accessibilityPhrase="Game Lists" positionInParent="0"> | <menuContributions xmi:id="_AitwEHBeEeuk7d_98DxC5A" elementId="xyz.veronie.bgg.ui.menucontribution.gamelists" accessibilityPhrase="Game Lists" positionInParent="0"> | ||||
<children xsi:type="menu:HandledMenuItem" xmi:id="_JvwHYHBeEeuk7d_98DxC5A" elementId="importResult" label="Import..." tooltip="Import thing list from bgg1tool result.txt file" command="_rkauIG7REeutwMlAyj2x8w"/> | <children xsi:type="menu:HandledMenuItem" xmi:id="_JvwHYHBeEeuk7d_98DxC5A" elementId="importResult" label="Import..." tooltip="Import thing list from bgg1tool result.txt file" command="_rkauIG7REeutwMlAyj2x8w"/> | ||||
</menuContributions> | </menuContributions> | ||||
<commands xmi:id="_lA5t8F9TEeuvNqpgCDWpdQ" elementId="xyz.veronie.bgg.ui.command.save" commandName="Save" description="save game list"/> | <commands xmi:id="_lA5t8F9TEeuvNqpgCDWpdQ" elementId="xyz.veronie.bgg.ui.command.save" commandName="Save" description="save game list"/> | ||||
<commands xmi:id="_qyrHAG3zEeuCP7xCflu8WA" elementId="xyz.veronie.bgg.ui.command.load" commandName="Load" description="load game list"/> | <commands xmi:id="_qyrHAG3zEeuCP7xCflu8WA" elementId="xyz.veronie.bgg.ui.command.load" commandName="Load" description="load game list"/> | ||||
<commands xmi:id="_rkauIG7REeutwMlAyj2x8w" elementId="xyz.veronie.bgg.ui.command.importResultTxt" commandName="ImportResultTxt" description="Import result.txt from bgg1tool"/> | <commands xmi:id="_rkauIG7REeutwMlAyj2x8w" elementId="xyz.veronie.bgg.ui.command.importResultTxt" commandName="ImportResultTxt" description="Import result.txt from bgg1tool"/> | ||||
<commands xmi:id="_OUnzIHOzEeuMU7Jt9moleA" elementId="xyz.veronie.bgg.ui.command.export" commandName="Export" description="export result.txt file"/> | |||||
<addons xmi:id="_Lw_ZsUqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/> | <addons xmi:id="_Lw_ZsUqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/> | ||||
<addons xmi:id="_Lw_ZskqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/> | <addons xmi:id="_Lw_ZskqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/> | ||||
<addons xmi:id="_Lw_Zs0qSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/> | <addons xmi:id="_Lw_Zs0qSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/> | ||||
@@ -14,6 +14,7 @@ import java.util.List; | |||||
import xyz.veronie.bgg.result.Thing; | import xyz.veronie.bgg.result.Thing; | ||||
import xyz.veronie.bgg.result.ThingMetaData; | import xyz.veronie.bgg.result.ThingMetaData; | ||||
import xyz.veronie.bgg.result.ThingUserData; | |||||
import xyz.veronie.bgg.ui.helpers.Resources; | import xyz.veronie.bgg.ui.helpers.Resources; | ||||
public class SqliteController { | public class SqliteController { | ||||
@@ -181,10 +182,16 @@ public class SqliteController { | |||||
thingStatement.setString(2, metaData.getName()); | thingStatement.setString(2, metaData.getName()); | ||||
thingStatement.setString(3, metaData.getImgURL()); | thingStatement.setString(3, metaData.getImgURL()); | ||||
thingStatement.setString(4, metaData.getThumbURL()); | thingStatement.setString(4, metaData.getThumbURL()); | ||||
thingStatement.setString(5, metaData.getComment()); | |||||
if(metaData.getNumPlays() != null) { | |||||
thingStatement.setInt(6, metaData.getNumPlays()); | |||||
ThingUserData userData = thing.getUserData(); | |||||
if(userData != null) { | |||||
thingStatement.setString(5, userData.getComment()); | |||||
if(userData.getNumPlays() != null) { | |||||
thingStatement.setInt(6, userData.getNumPlays()); | |||||
} else { | |||||
thingStatement.setNull(6, java.sql.Types.INTEGER); | |||||
} | |||||
} else { | } else { | ||||
thingStatement.setString(5, ""); | |||||
thingStatement.setNull(6, java.sql.Types.INTEGER); | thingStatement.setNull(6, java.sql.Types.INTEGER); | ||||
} | } | ||||
thingStatement.execute(); | thingStatement.execute(); | ||||
@@ -254,10 +261,12 @@ public class SqliteController { | |||||
ThingMetaData metaData = new ThingMetaData(id, | ThingMetaData metaData = new ThingMetaData(id, | ||||
res.getString(2), | res.getString(2), | ||||
res.getString(3), | res.getString(3), | ||||
res.getString(4), | |||||
res.getString(5), | |||||
res.getInt(6)); | |||||
res.getString(4)); | |||||
ThingUserData userData = new ThingUserData(); | |||||
userData.setComment(res.getString(5)); | |||||
userData.setNumPlays(res.getInt(6)); | |||||
Thing thing = new Thing(id, metaData); | Thing thing = new Thing(id, metaData); | ||||
thing.setUserData(userData); | |||||
thingList.add(thing); | thingList.add(thing); | ||||
} | } | ||||
@@ -78,6 +78,21 @@ public class BggApi { | |||||
return getThings(urlStr.toString()); | return getThings(urlStr.toString()); | ||||
} | } | ||||
public ArrayList<Thing> getThingDetails(Set<Integer> ids) { | |||||
StringBuilder urlStr = new StringBuilder(); | |||||
urlStr.append(BASE_URL + "thing?id="); | |||||
String sep = ""; | |||||
for (Integer integer : ids) { | |||||
urlStr.append(sep + integer.toString()); | |||||
if(sep.isEmpty()) { | |||||
sep = ","; | |||||
} | |||||
} | |||||
return getThings(urlStr.toString()); | |||||
} | |||||
public ArrayList<Thing> getThingsForUser(String user) throws IllegalArgumentException { | public ArrayList<Thing> getThingsForUser(String user) throws IllegalArgumentException { | ||||
ResultConfig resultConfig = configManager.getResultConfig(); | ResultConfig resultConfig = configManager.getResultConfig(); | ||||
@@ -230,11 +245,51 @@ public class BggApi { | |||||
id, | id, | ||||
getValue(eElement, "name"), | getValue(eElement, "name"), | ||||
getValue(eElement, "image"), | getValue(eElement, "image"), | ||||
getValue(eElement, "thumbnail"), | |||||
getValue(eElement, "comment"), | |||||
Integer.parseInt(getValue(eElement, "numplays")) | |||||
getValue(eElement, "thumbnail") | |||||
); | ); | ||||
ThingUserData tud = new ThingUserData(); | |||||
tud.setNumPlays(Integer.valueOf(getValue(eElement, "numplays"))); | |||||
tud.setComment(getValue(eElement, "comment")); | |||||
// rating | |||||
NodeList statsNodes = eElement.getElementsByTagName("stats"); | |||||
if(statsNodes.getLength() > 0) { | |||||
Node statsNode = statsNodes.item(0); | |||||
NodeList statsChildren = statsNode.getChildNodes(); | |||||
if(statsChildren.getLength() > 0) { | |||||
Element ratingNode = (Element)statsChildren.item(0); | |||||
String ratingValue = ratingNode.getAttribute("value"); | |||||
if(!ratingValue.equals("N/A")) { | |||||
try { | |||||
Float rating = Float.valueOf(ratingValue); | |||||
tud.setRating(rating); | |||||
} | |||||
catch(NumberFormatException e) { | |||||
System.out.println("WARN: rating value is not a float."); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
NodeList statusNodes = eElement.getElementsByTagName("status"); | |||||
if(statusNodes.getLength() > 0) { | |||||
Element statusNode = (Element)statusNodes.item(0); | |||||
tud.setOwn(attributeToBoolean(statusNode, "own")); | |||||
tud.setPrevowned(attributeToBoolean(statusNode, "prevowned")); | |||||
tud.setFortrade(attributeToBoolean(statusNode, "fortrade")); | |||||
tud.setWant(attributeToBoolean(statusNode, "want")); | |||||
tud.setWanttoplay(attributeToBoolean(statusNode, "wanttoplay")); | |||||
tud.setWanttobuy(attributeToBoolean(statusNode, "wanttobuy")); | |||||
tud.setWishlist(attributeToBoolean(statusNode, "wishlist")); | |||||
if(statusNode.hasAttribute("wishlistpriority")) { | |||||
tud.setWishlistpriority(Integer.valueOf(statusNode.getAttribute("wishlistpriority"))); | |||||
} | |||||
tud.setPreordered(attributeToBoolean(statusNode, "preordered")); | |||||
tud.setLastmodified(statusNode.getAttribute("lastmodified")); | |||||
} | |||||
Thing thing = new Thing(id, tmd); | Thing thing = new Thing(id, tmd); | ||||
thing.setUserData(tud); | |||||
things.add(thing); | things.add(thing); | ||||
} | } | ||||
} | } | ||||
@@ -263,10 +318,7 @@ public class BggApi { | |||||
id, | id, | ||||
name, | name, | ||||
getValue(eElement, "image"), | getValue(eElement, "image"), | ||||
getValue(eElement, "thumbnail"), | |||||
getValue(eElement, "comment"), | |||||
null | |||||
); | |||||
getValue(eElement, "thumbnail")); | |||||
Thing thing = new Thing(id, tmd); | Thing thing = new Thing(id, tmd); | ||||
things.add(thing); | things.add(thing); | ||||
} | } | ||||
@@ -299,7 +351,7 @@ public class BggApi { | |||||
ThingMetaData tmd = new ThingMetaData( | ThingMetaData tmd = new ThingMetaData( | ||||
id, | id, | ||||
eLink.getAttribute("value"), | eLink.getAttribute("value"), | ||||
"", "", "", null); | |||||
"", ""); | |||||
Thing thing = new Thing(id, tmd); | Thing thing = new Thing(id, tmd); | ||||
things.add(thing); | things.add(thing); | ||||
} | } | ||||
@@ -338,7 +390,7 @@ public class BggApi { | |||||
ThingMetaData tmd = new ThingMetaData( | ThingMetaData tmd = new ThingMetaData( | ||||
id, | id, | ||||
eElement.getAttribute("objectname"), | eElement.getAttribute("objectname"), | ||||
"", "", "", null); | |||||
"", ""); | |||||
Thing thing = new Thing(id, tmd); | Thing thing = new Thing(id, tmd); | ||||
things.add(thing); | things.add(thing); | ||||
} | } | ||||
@@ -362,6 +414,13 @@ public class BggApi { | |||||
} | } | ||||
private Boolean attributeToBoolean(Element statusNode, String attribute) { | |||||
if(statusNode.hasAttribute(attribute)) { | |||||
return statusNode.getAttribute(attribute).equals("0") ? false : true; | |||||
} | |||||
return null; | |||||
} | |||||
private void checkForErrors(Document doc) throws IllegalArgumentException { | private void checkForErrors(Document doc) throws IllegalArgumentException { | ||||
NodeList nList = doc.getElementsByTagName("error"); | NodeList nList = doc.getElementsByTagName("error"); | ||||
if(nList.getLength() > 0) { | if(nList.getLength() > 0) { | ||||
@@ -0,0 +1,8 @@ | |||||
package xyz.veronie.bgg.result; | |||||
public enum Recommendation { | |||||
N, // not supported | |||||
P, // not recommended | |||||
R, // recommended | |||||
B // best | |||||
} |
@@ -20,10 +20,12 @@ public class Thing { | |||||
private int id; | private int id; | ||||
private ThingMetaData metaData; | private ThingMetaData metaData; | ||||
private ThingUserData userData; | |||||
private ThingDetails details; | private ThingDetails details; | ||||
// cache | // cache | ||||
private Image thumbImage; | private Image thumbImage; | ||||
private Path imagePath; | |||||
public static final String IdHeader = "ID"; | public static final String IdHeader = "ID"; | ||||
public static final String ThumbHeader = "Thumbnail"; | public static final String ThumbHeader = "Thumbnail"; | ||||
@@ -49,9 +51,19 @@ public class Thing { | |||||
public void setMetaData(ThingMetaData metaData) { | public void setMetaData(ThingMetaData metaData) { | ||||
this.metaData = metaData; | this.metaData = metaData; | ||||
} | } | ||||
public void setUserData(ThingUserData userData) { | |||||
this.userData = userData; | |||||
} | |||||
public ThingUserData getUserData() { | |||||
return userData; | |||||
} | |||||
public ThingDetails getDetails() { | public ThingDetails getDetails() { | ||||
return details; | return details; | ||||
} | } | ||||
public void setDetails(ThingDetails details) { | public void setDetails(ThingDetails details) { | ||||
this.details = details; | this.details = details; | ||||
} | } | ||||
@@ -63,14 +75,21 @@ public class Thing { | |||||
return thumbImage; | return thumbImage; | ||||
} | } | ||||
public String getImagePath() { | |||||
if(imagePath != null) | |||||
return imagePath.toString(); | |||||
else | |||||
return ""; | |||||
} | |||||
private void getThumbImage(int thingId) { | private void getThumbImage(int thingId) { | ||||
Path tmpDir = Resources.INSTANCE.getTmpDir(); | Path tmpDir = Resources.INSTANCE.getTmpDir(); | ||||
if(tmpDir != null) { | if(tmpDir != null) { | ||||
Path imageFile = Paths.get(Resources.INSTANCE.getThumbsDir().toString() | |||||
imagePath = Paths.get(Resources.INSTANCE.getThumbsDir().toString() | |||||
+ File.separator + String.valueOf(thingId) + ".png"); | + File.separator + String.valueOf(thingId) + ".png"); | ||||
if(Files.exists(imageFile, LinkOption.NOFOLLOW_LINKS)) { | |||||
String filename = imageFile.toString().replace("\\","/"); | |||||
if(Files.exists(imagePath, LinkOption.NOFOLLOW_LINKS)) { | |||||
String filename = imagePath.toString().replace("\\","/"); | |||||
thumbImage = Resources.INSTANCE.getResourceManager().createImage( | thumbImage = Resources.INSTANCE.getResourceManager().createImage( | ||||
ImageDescriptor.createFromFile(null, filename)); | ImageDescriptor.createFromFile(null, filename)); | ||||
} else { | } else { | ||||
@@ -81,7 +100,7 @@ public class Thing { | |||||
ImageLoader saver = new ImageLoader(); | ImageLoader saver = new ImageLoader(); | ||||
saver.data = new ImageData[] { thumbImage.getImageData() }; | saver.data = new ImageData[] { thumbImage.getImageData() }; | ||||
saver.save(imageFile.toString(), SWT.IMAGE_PNG); | |||||
saver.save(imagePath.toString(), SWT.IMAGE_PNG); | |||||
} catch (MalformedURLException e) { | } catch (MalformedURLException e) { | ||||
System.out.println("INFO: Malformed URL for ThingId " + thingId); | System.out.println("INFO: Malformed URL for ThingId " + thingId); | ||||
} | } | ||||
@@ -130,4 +149,140 @@ public class Thing { | |||||
} | } | ||||
} | } | ||||
/// convert the thing into a comma-separated line for a result.txt file | |||||
/** | |||||
* The format is (without line breaks): | |||||
* id,name,designer,publisher,artist,yearpublished,minplayers,maxplayers,playingtime,minplaytime,maxplaytime, | |||||
* age,usersrated,average,bayesaverage,rank,rank_wg,numcomments,numweights,averageweight,stddev,median, | |||||
* owned,trading,wanting,wishing,userrating,image,category,mechanic,comment, | |||||
* 1player,2player,3player,4player,5player,6player,7player,8player,9player,10player, | |||||
* 11player,12player,13player,14player,15player,16player,17player,18player,19player,20player, | |||||
* description,exp,basegame,reimplement,reimplement_name,reimplemented,reimplemented_name, | |||||
* contains,contains_name,iscontained,iscontained_name,integration,integration_name, | |||||
* numplays,price,userweight,wishpriority,expansions,domain,family,age_poll | |||||
* | |||||
* @return | |||||
*/ | |||||
public String toResultTxtLine() { | |||||
StringBuilder str = new StringBuilder(); | |||||
final String emptyItem = "\"\","; | |||||
// id,name,designer,publisher,artist,yearpublished,minplayers,maxplayers,playingtime,minplaytime,maxplaytime, | |||||
// age,usersrated,average,bayesaverage,rank,rank_wg,numcomments,numweights,averageweight,stddev,median, | |||||
str.append(Integer.toString(id)).append(","); | |||||
str.append(metaData.getName()).append(","); | |||||
if(details != null) { | |||||
str.append(details.designer).append(","); | |||||
str.append(details.publisher).append(","); | |||||
str.append(details.artist).append(","); | |||||
str.append(details.yearpublished).append(","); | |||||
str.append(details.minplayers).append(","); | |||||
str.append(details.maxplayers).append(","); | |||||
str.append(details.playingtime).append(","); | |||||
str.append(details.minplaytime).append(","); | |||||
str.append(details.maxplaytime).append(","); | |||||
str.append(details.age).append(","); | |||||
str.append(details.usersrated).append(","); | |||||
str.append(details.average).append(","); | |||||
str.append(floatToResult(details.bayesaverage)).append(","); | |||||
str.append(details.rank).append(","); | |||||
str.append(details.rank_wg).append(","); | |||||
str.append(details.numcomments).append(","); | |||||
str.append(details.numweights).append(","); | |||||
str.append(floatToResult(details.averageweight)).append(","); | |||||
str.append(floatToResult(details.stddev)).append(","); | |||||
str.append(floatToResult(details.median)).append(","); | |||||
} else { | |||||
for(int i = 0; i < 20; ++i) { | |||||
str.append(emptyItem); | |||||
} | |||||
} | |||||
// owned,trading,wanting,wishing,userrating, | |||||
if(userData != null) { | |||||
str.append(userData.getOwn()?"1":"0").append(","); | |||||
str.append(userData.getFortrade()?"1":"0").append(","); | |||||
str.append(userData.getWant()?"1":"0").append(","); | |||||
str.append(userData.getWishlist()?"1":"0").append(","); | |||||
str.append(floatToResult(userData.getRating())).append(","); | |||||
} | |||||
// image,category,mechanic,comment, | |||||
str.append(getImagePath()).append(","); | |||||
if(details != null) { | |||||
str.append(details.category).append(","); | |||||
str.append(details.mechanic).append(","); | |||||
} else str.append(emptyItem).append(emptyItem); | |||||
if(userData != null) { | |||||
str.append(userData.getComment()).append(","); | |||||
} else str.append(emptyItem); | |||||
// 1player,2player,3player,4player,5player,6player,7player,8player,9player,10player, | |||||
// 11player,12player,13player,14player,15player,16player,17player,18player,19player,20player, | |||||
if(details != null) { | |||||
for(Recommendation r : details.players) { | |||||
str.append(r.name()).append(","); | |||||
} | |||||
} else { | |||||
for(int i = 0; i < 20; ++i) { | |||||
str.append("N,"); | |||||
} | |||||
} | |||||
// description,exp,basegame,reimplement,reimplement_name,reimplemented,reimplemented_name, | |||||
// contains,contains_name,iscontained,iscontained_name,integration,integration_name, | |||||
if(details != null) { | |||||
str.append(details.description).append(","); | |||||
str.append(details.expansion).append(","); | |||||
str.append(details.basegameId).append(","); | |||||
str.append(details.reimplementId).append(","); | |||||
str.append(details.reimplement_name).append(","); | |||||
str.append(details.reimplementedById).append(","); | |||||
str.append(details.reimplementedByName).append(","); | |||||
str.append(details.containsId).append(","); | |||||
str.append(details.containsName).append(","); | |||||
str.append(details.iscontained).append(","); | |||||
str.append(details.iscontained_name).append(","); | |||||
str.append(details.integration).append(","); | |||||
str.append(details.integration_name).append(","); | |||||
} else { | |||||
for(int i = 0; i < 13; ++i) { | |||||
str.append(emptyItem); | |||||
} | |||||
} | |||||
// numplays,price,userweight,wishpriority,expansions,domain,family,age_poll | |||||
if(userData != null) { | |||||
str.append(userData.getNumPlays()).append(","); | |||||
} else str.append(emptyItem); | |||||
if(details != null) { | |||||
str.append(details.price).append(","); | |||||
} else str.append(emptyItem); | |||||
// TODO: find out how to get userweight... | |||||
str.append(emptyItem); | |||||
if(userData != null) { | |||||
str.append(userData.getWishlistpriority()).append(","); | |||||
} else str.append(emptyItem); | |||||
if(details != null) { | |||||
str.append(details.expansions).append(","); | |||||
str.append(details.domain).append(","); | |||||
str.append(details.family).append(","); | |||||
str.append(details.age_poll).append(","); | |||||
} else { | |||||
str.append(emptyItem); | |||||
str.append(emptyItem); | |||||
str.append(emptyItem); | |||||
str.append(emptyItem); | |||||
} | |||||
return str.toString(); | |||||
} | |||||
private String floatToResult(Float rating) { | |||||
if(rating == null) { | |||||
return ""; | |||||
} else { | |||||
return Float.toString(rating.floatValue()); | |||||
} | |||||
} | |||||
} | } |
@@ -2,7 +2,6 @@ package xyz.veronie.bgg.result; | |||||
public class ThingDetails { | public class ThingDetails { | ||||
Integer id; | Integer id; | ||||
String name; | |||||
String designer; | String designer; | ||||
String publisher; | String publisher; | ||||
String artist; | String artist; | ||||
@@ -23,18 +22,13 @@ public class ThingDetails { | |||||
Float averageweight; | Float averageweight; | ||||
Float stddev; | Float stddev; | ||||
Float median; | Float median; | ||||
Boolean owned; | |||||
Boolean trading; | |||||
Boolean wanting; | |||||
Boolean wishing; | |||||
Float userrating; | |||||
String image; | String image; | ||||
Integer category; | Integer category; | ||||
Integer mechanic; | Integer mechanic; | ||||
String comment; | String comment; | ||||
Integer[] players; // 1 to 20 | |||||
Recommendation[] players; // 1 to 20 | |||||
String description; | String description; | ||||
// exp, | |||||
Integer expansion; | |||||
Integer basegameId; | Integer basegameId; | ||||
Integer reimplementId; | Integer reimplementId; | ||||
String reimplement_name; | String reimplement_name; | ||||
@@ -48,8 +42,6 @@ public class ThingDetails { | |||||
String integration_name; | String integration_name; | ||||
Integer numplays; | Integer numplays; | ||||
Float price; | Float price; | ||||
Float userweight; | |||||
Integer wishpriority; | |||||
Integer expansions; | Integer expansions; | ||||
String domain; | String domain; | ||||
String family; | String family; | ||||
@@ -1,74 +0,0 @@ | |||||
package xyz.veronie.bgg.result; | |||||
import java.awt.Label; | |||||
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 ThingDetailsComposite extends Composite { | |||||
ThingDetails thingDetails; | |||||
private Label nameField; | |||||
private Label designerField; | |||||
private Label publisherField; | |||||
private Label yearField; | |||||
public ThingDetailsComposite(Composite parent, int style) { | |||||
super(parent, style); | |||||
} | |||||
@PostConstruct | |||||
public void create() { | |||||
setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); | |||||
GridLayout layout = new GridLayout(2, false); | |||||
setLayout(layout); | |||||
Label nameLbl = new Label("Name"); | |||||
applyLayout(nameLbl); | |||||
nameField = new Label(""); | |||||
Label designerLbl = new Label("Designer"); | |||||
applyLayout(designerLbl); | |||||
designerField = new Label(""); | |||||
Label publisherLbl = new Label("Publisher"); | |||||
applyLayout(publisherLbl); | |||||
publisherField = new Label(""); | |||||
Label yearLbl = new Label("Publisher"); | |||||
applyLayout(yearLbl); | |||||
yearField = new Label(""); | |||||
this.getParent().layout(); | |||||
} | |||||
private void applyLayout(Label label) { | |||||
label.setAlignment(SWT.RIGHT); | |||||
} | |||||
public void selectedThingChanged(Thing thing) { | |||||
System.out.println("TOPIC_THING_SELECTION: " + thing); | |||||
thingDetails = thing.getDetails(); | |||||
if(thingDetails != null) { | |||||
nameField.setText(thingDetails.name); | |||||
designerField.setText(thingDetails.designer); | |||||
publisherField.setText(thingDetails.publisher); | |||||
yearField.setText(Integer.toString(thingDetails.yearpublished)); | |||||
} else { | |||||
nameField.setText(""); | |||||
designerField.setText(""); | |||||
publisherField.setText(""); | |||||
yearField.setText(""); | |||||
} | |||||
this.getParent().layout(); | |||||
} | |||||
} |
@@ -2,7 +2,6 @@ package xyz.veronie.bgg.result; | |||||
import java.beans.PropertyChangeListener; | import java.beans.PropertyChangeListener; | ||||
import java.beans.PropertyChangeSupport; | import java.beans.PropertyChangeSupport; | ||||
//import com.google.gson.Gson; | |||||
public class ThingMetaData implements java.io.Serializable { | public class ThingMetaData implements java.io.Serializable { | ||||
private static final long serialVersionUID = -5268898737006538509L; | private static final long serialVersionUID = -5268898737006538509L; | ||||
@@ -11,21 +10,15 @@ public class ThingMetaData implements java.io.Serializable { | |||||
private String name; | private String name; | ||||
private String imgURL; | private String imgURL; | ||||
private String thumbURL; | private String thumbURL; | ||||
private String comment; | |||||
private Integer numPlays; | |||||
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); | private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); | ||||
public ThingMetaData(int id, String name, | public ThingMetaData(int id, String name, | ||||
String imgURL, String thumURL, | |||||
String comment, Integer numPlays) { | |||||
String imgURL, String thumURL) { | |||||
this.setId(id); | this.setId(id); | ||||
this.setName(name); | this.setName(name); | ||||
this.setImgURL(imgURL); | this.setImgURL(imgURL); | ||||
this.setThumbURL(thumURL); | this.setThumbURL(thumURL); | ||||
this.setComment(comment); | |||||
this.setNumPlays(numPlays); | |||||
} | } | ||||
@@ -78,29 +71,9 @@ public class ThingMetaData implements java.io.Serializable { | |||||
this.thumbURL = thumbURL); | this.thumbURL = thumbURL); | ||||
} | } | ||||
public Integer getNumPlays() { | |||||
return numPlays; | |||||
} | |||||
public void setNumPlays(Integer numPlays) { | |||||
this.numPlays = numPlays; | |||||
} | |||||
public String getComment() { | |||||
return comment; | |||||
} | |||||
public void setComment(String comment) { | |||||
propertyChangeSupport.firePropertyChange("comment", this.comment, | |||||
this.comment = comment); | |||||
} | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
return String.valueOf(id); | return String.valueOf(id); | ||||
// Gson gson = new Gson(); | |||||
// return gson.toJson(this); | |||||
} | } | ||||
@@ -0,0 +1,134 @@ | |||||
package xyz.veronie.bgg.result; | |||||
public class ThingUserData { | |||||
private Integer numplays; | |||||
private String comment; | |||||
private Float rating; | |||||
private Boolean own; | |||||
private Boolean prevowned; | |||||
private Boolean fortrade; | |||||
private Boolean want; | |||||
private Boolean wanttoplay; | |||||
private Boolean wanttobuy; | |||||
private Boolean wishlist; | |||||
private Integer wishlistpriority; | |||||
private Boolean preordered; | |||||
private String lastmodified; | |||||
//private Float weight; | |||||
public Integer getNumPlays() { | |||||
return numplays; | |||||
} | |||||
public void setNumPlays(Integer numPlays) { | |||||
this.numplays = numPlays; | |||||
} | |||||
public String getComment() { | |||||
return comment; | |||||
} | |||||
public void setComment(String comment) { | |||||
this.comment = comment; | |||||
} | |||||
public Float getRating() { | |||||
return rating; | |||||
} | |||||
public void setRating(Float rating) { | |||||
this.rating = rating; | |||||
} | |||||
public Boolean getOwn() { | |||||
return own; | |||||
} | |||||
public void setOwn(Boolean own) { | |||||
this.own = own; | |||||
} | |||||
public Boolean getPrevowned() { | |||||
return prevowned; | |||||
} | |||||
public void setPrevowned(Boolean prevowned) { | |||||
this.prevowned = prevowned; | |||||
} | |||||
public Boolean getFortrade() { | |||||
return fortrade; | |||||
} | |||||
public void setFortrade(Boolean fortrade) { | |||||
this.fortrade = fortrade; | |||||
} | |||||
public Boolean getWant() { | |||||
return want; | |||||
} | |||||
public void setWant(Boolean want) { | |||||
this.want = want; | |||||
} | |||||
public Boolean getWanttoplay() { | |||||
return wanttoplay; | |||||
} | |||||
public void setWanttoplay(Boolean wanttoplay) { | |||||
this.wanttoplay = wanttoplay; | |||||
} | |||||
public Boolean getWanttobuy() { | |||||
return wanttobuy; | |||||
} | |||||
public void setWanttobuy(Boolean wanttobuy) { | |||||
this.wanttobuy = wanttobuy; | |||||
} | |||||
public Boolean getWishlist() { | |||||
return wishlist; | |||||
} | |||||
public void setWishlist(Boolean wishlist) { | |||||
this.wishlist = wishlist; | |||||
} | |||||
public Integer getWishlistpriority() { | |||||
return wishlistpriority; | |||||
} | |||||
public void setWishlistpriority(Integer wishlistpriority) { | |||||
this.wishlistpriority = wishlistpriority; | |||||
} | |||||
public Boolean getPreordered() { | |||||
return preordered; | |||||
} | |||||
public void setPreordered(Boolean preordered) { | |||||
this.preordered = preordered; | |||||
} | |||||
public String getLastmodified() { | |||||
return lastmodified; | |||||
} | |||||
public void setLastmodified(String lastmodified) { | |||||
this.lastmodified = lastmodified; | |||||
} | |||||
// public Float getWeight() { | |||||
// return weight; | |||||
// } | |||||
// | |||||
// public void setWeight(Float weight) { | |||||
// this.weight = weight; | |||||
// } | |||||
} |
@@ -0,0 +1,34 @@ | |||||
package xyz.veronie.bgg.ui.handlers; | |||||
import org.eclipse.e4.core.di.annotations.Execute; | |||||
import xyz.veronie.bgg.result.Thing; | |||||
import xyz.veronie.bgg.result.ThingProvider; | |||||
import java.util.List; | |||||
import javax.inject.Inject; | |||||
import org.eclipse.e4.core.di.annotations.CanExecute; | |||||
public class ExportResultHandler { | |||||
@Inject | |||||
ThingProvider thingProvider; | |||||
@Execute | |||||
public void execute() { | |||||
List<Thing> things = thingProvider.getThings(); | |||||
for (Thing thing : things) { | |||||
System.out.println(thing.toResultTxtLine()); | |||||
} | |||||
} | |||||
@CanExecute | |||||
public boolean canExecute() { | |||||
return thingProvider != null; | |||||
} | |||||
} |
@@ -148,6 +148,16 @@ public class BatMain { | |||||
btnUndo.setEnabled(false); | btnUndo.setEnabled(false); | ||||
btnExport = new Button(buttonRow, SWT.NONE); | btnExport = new Button(buttonRow, SWT.NONE); | ||||
btnExport.addMouseListener(new MouseAdapter() { | |||||
@Override | |||||
public void mouseUp(MouseEvent e) { | |||||
ParameterizedCommand cmd = | |||||
commandService.createCommand("xyz.veronie.bgg.ui.command.export", null); | |||||
if (handlerService.canExecute(cmd)){ | |||||
handlerService.executeHandler(cmd); | |||||
} | |||||
} | |||||
}); | |||||
btnExport.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/export_nandeck_60x60.png")); | btnExport.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/export_nandeck_60x60.png")); | ||||
btnExport.setToolTipText("Export for nanDeck"); | btnExport.setToolTipText("Export for nanDeck"); | ||||
btnExport.setEnabled(false); | btnExport.setEnabled(false); | ||||
@@ -222,20 +232,7 @@ public class BatMain { | |||||
TableViewerColumn colThumbnail = createTableViewerColumn(Thing.ThumbHeader, 120, 0); | TableViewerColumn colThumbnail = createTableViewerColumn(Thing.ThumbHeader, 120, 0); | ||||
// colThumbnail.setLabelProvider(new ColumnLabelProvider() { | |||||
// @Override | |||||
// public Image getImage(Object element) { | |||||
// Thing t = (Thing) element; | |||||
// Image img = t.getThumbnail(); | |||||
// return img; | |||||
// } | |||||
// | |||||
// @Override | |||||
// public String getText(Object element) { | |||||
// return ""; | |||||
// } | |||||
// | |||||
// }); | |||||
colThumbnail.setLabelProvider(new OwnerDrawLabelProvider() { | colThumbnail.setLabelProvider(new OwnerDrawLabelProvider() { | ||||
@Override | @Override | ||||
protected void measure(Event event, Object element) { | protected void measure(Event event, Object element) { | ||||
@@ -11,12 +11,9 @@ import org.eclipse.swt.layout.GridLayout; | |||||
import org.eclipse.swt.widgets.Composite; | import org.eclipse.swt.widgets.Composite; | ||||
import xyz.veronie.bgg.result.Thing; | import xyz.veronie.bgg.result.Thing; | ||||
import xyz.veronie.bgg.result.ThingDetailsComposite; | |||||
import xyz.veronie.bgg.types.EventConstants; | import xyz.veronie.bgg.types.EventConstants; | ||||
public class ThingListPart { | public class ThingListPart { | ||||
private ThingDetailsComposite thingDetailsComposite; | |||||
@PostConstruct | @PostConstruct | ||||
public void createControls(Composite parent) { | public void createControls(Composite parent) { | ||||
Composite main = new Composite(parent, SWT.FILL); | Composite main = new Composite(parent, SWT.FILL); | ||||
@@ -24,14 +21,11 @@ public class ThingListPart { | |||||
GridLayout layout = new GridLayout(2, false); | GridLayout layout = new GridLayout(2, false); | ||||
main.setLayout(layout); | main.setLayout(layout); | ||||
thingDetailsComposite = new ThingDetailsComposite(main, SWT.BORDER); | |||||
} | } | ||||
@Inject | @Inject | ||||
@Optional | @Optional | ||||
private void selectedThingChanged(@UIEventTopic(EventConstants.TOPIC_THING_SELECTION) Thing thing) { | private void selectedThingChanged(@UIEventTopic(EventConstants.TOPIC_THING_SELECTION) Thing thing) { | ||||
thingDetailsComposite.selectedThingChanged(thing); | |||||
} | } | ||||