From ee3e04c3eb562ea9fa8abdac6830e898d16daa3f Mon Sep 17 00:00:00 2001 From: veronie Date: Sat, 20 Feb 2021 20:50:18 +0100 Subject: [PATCH] Implemented first version of output of thing to result line. Slightly rearranged metadata (some fields are now in ThingUserData). Filling ThingUserData when fetching by user with BggApi. Added ExportResultHandler. --- xyz.veronie.bgg.ui/Application.e4xmi | 2 + .../veronie/bgg/localdb/SqliteController.java | 21 ++- .../src/xyz/veronie/bgg/result/BggApi.java | 77 ++++++++- .../veronie/bgg/result/Recommendation.java | 8 + .../src/xyz/veronie/bgg/result/Thing.java | 163 +++++++++++++++++- .../xyz/veronie/bgg/result/ThingDetails.java | 12 +- .../bgg/result/ThingDetailsComposite.java | 74 -------- .../xyz/veronie/bgg/result/ThingMetaData.java | 29 +--- .../xyz/veronie/bgg/result/ThingUserData.java | 134 ++++++++++++++ .../bgg/ui/handlers/ExportResultHandler.java | 34 ++++ .../src/xyz/veronie/bgg/ui/parts/BatMain.java | 25 ++- .../veronie/bgg/ui/parts/ThingListPart.java | 6 - 12 files changed, 434 insertions(+), 151 deletions(-) create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Recommendation.java delete mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingUserData.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java diff --git a/xyz.veronie.bgg.ui/Application.e4xmi b/xyz.veronie.bgg.ui/Application.e4xmi index 002cfe8..0d5c9cb 100644 --- a/xyz.veronie.bgg.ui/Application.e4xmi +++ b/xyz.veronie.bgg.ui/Application.e4xmi @@ -24,12 +24,14 @@ + + diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java index fa2e1a7..b5d19e5 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java @@ -14,6 +14,7 @@ import java.util.List; import xyz.veronie.bgg.result.Thing; import xyz.veronie.bgg.result.ThingMetaData; +import xyz.veronie.bgg.result.ThingUserData; import xyz.veronie.bgg.ui.helpers.Resources; public class SqliteController { @@ -181,10 +182,16 @@ public class SqliteController { thingStatement.setString(2, metaData.getName()); thingStatement.setString(3, metaData.getImgURL()); 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 { + thingStatement.setString(5, ""); thingStatement.setNull(6, java.sql.Types.INTEGER); } thingStatement.execute(); @@ -254,10 +261,12 @@ public class SqliteController { ThingMetaData metaData = new ThingMetaData(id, res.getString(2), 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.setUserData(userData); thingList.add(thing); } 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 1785174..0e46668 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 @@ -78,6 +78,21 @@ public class BggApi { return getThings(urlStr.toString()); } + public ArrayList getThingDetails(Set 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 getThingsForUser(String user) throws IllegalArgumentException { ResultConfig resultConfig = configManager.getResultConfig(); @@ -230,11 +245,51 @@ public class BggApi { id, getValue(eElement, "name"), 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.setUserData(tud); things.add(thing); } } @@ -263,10 +318,7 @@ public class BggApi { id, name, getValue(eElement, "image"), - getValue(eElement, "thumbnail"), - getValue(eElement, "comment"), - null - ); + getValue(eElement, "thumbnail")); Thing thing = new Thing(id, tmd); things.add(thing); } @@ -299,7 +351,7 @@ public class BggApi { ThingMetaData tmd = new ThingMetaData( id, eLink.getAttribute("value"), - "", "", "", null); + "", ""); Thing thing = new Thing(id, tmd); things.add(thing); } @@ -338,7 +390,7 @@ public class BggApi { ThingMetaData tmd = new ThingMetaData( id, eElement.getAttribute("objectname"), - "", "", "", null); + "", ""); Thing thing = new Thing(id, tmd); 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 { NodeList nList = doc.getElementsByTagName("error"); if(nList.getLength() > 0) { diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Recommendation.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Recommendation.java new file mode 100644 index 0000000..da9a6c8 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Recommendation.java @@ -0,0 +1,8 @@ +package xyz.veronie.bgg.result; + +public enum Recommendation { + N, // not supported + P, // not recommended + R, // recommended + B // best +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java index 9308437..6131b31 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java @@ -20,10 +20,12 @@ public class Thing { private int id; private ThingMetaData metaData; + private ThingUserData userData; private ThingDetails details; // cache private Image thumbImage; + private Path imagePath; public static final String IdHeader = "ID"; public static final String ThumbHeader = "Thumbnail"; @@ -49,9 +51,19 @@ public class Thing { public void setMetaData(ThingMetaData metaData) { this.metaData = metaData; } + + public void setUserData(ThingUserData userData) { + this.userData = userData; + } + + public ThingUserData getUserData() { + return userData; + } + public ThingDetails getDetails() { return details; } + public void setDetails(ThingDetails details) { this.details = details; } @@ -63,14 +75,21 @@ public class Thing { return thumbImage; } + public String getImagePath() { + if(imagePath != null) + return imagePath.toString(); + else + return ""; + } + private void getThumbImage(int thingId) { Path tmpDir = Resources.INSTANCE.getTmpDir(); if(tmpDir != null) { - Path imageFile = Paths.get(Resources.INSTANCE.getThumbsDir().toString() + imagePath = Paths.get(Resources.INSTANCE.getThumbsDir().toString() + 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( ImageDescriptor.createFromFile(null, filename)); } else { @@ -81,7 +100,7 @@ public class Thing { ImageLoader saver = new ImageLoader(); saver.data = new ImageData[] { thumbImage.getImageData() }; - saver.save(imageFile.toString(), SWT.IMAGE_PNG); + saver.save(imagePath.toString(), SWT.IMAGE_PNG); } catch (MalformedURLException e) { 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()); + } + } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetails.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetails.java index c064164..ae3a9fd 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetails.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetails.java @@ -2,7 +2,6 @@ package xyz.veronie.bgg.result; public class ThingDetails { Integer id; - String name; String designer; String publisher; String artist; @@ -23,18 +22,13 @@ public class ThingDetails { 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 + Recommendation[] players; // 1 to 20 String description; - // exp, + Integer expansion; Integer basegameId; Integer reimplementId; String reimplement_name; @@ -48,8 +42,6 @@ public class ThingDetails { String integration_name; Integer numplays; Float price; - Float userweight; - Integer wishpriority; Integer expansions; String domain; String family; diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java deleted file mode 100644 index 8762ba7..0000000 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java +++ /dev/null @@ -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(); - } - - -} 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 7998bca..432773d 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,7 +2,6 @@ package xyz.veronie.bgg.result; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; -//import com.google.gson.Gson; public class ThingMetaData implements java.io.Serializable { private static final long serialVersionUID = -5268898737006538509L; @@ -11,21 +10,15 @@ public class ThingMetaData implements java.io.Serializable { private String name; private String imgURL; private String thumbURL; - private String comment; - private Integer numPlays; - private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); public ThingMetaData(int id, String name, - String imgURL, String thumURL, - String comment, Integer numPlays) { + String imgURL, String thumURL) { this.setId(id); this.setName(name); this.setImgURL(imgURL); this.setThumbURL(thumURL); - this.setComment(comment); - this.setNumPlays(numPlays); } @@ -78,29 +71,9 @@ public class ThingMetaData implements java.io.Serializable { 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 public String toString() { return String.valueOf(id); -// Gson gson = new Gson(); -// return gson.toJson(this); } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingUserData.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingUserData.java new file mode 100644 index 0000000..5cf4e43 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingUserData.java @@ -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; +// } + +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java new file mode 100644 index 0000000..935d843 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java @@ -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 things = thingProvider.getThings(); + for (Thing thing : things) { + System.out.println(thing.toResultTxtLine()); + } + } + + + @CanExecute + public boolean canExecute() { + return thingProvider != null; + } + +} \ No newline at end of file diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java index 97c8a03..409bb72 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BatMain.java @@ -148,6 +148,16 @@ public class BatMain { btnUndo.setEnabled(false); 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.setToolTipText("Export for nanDeck"); btnExport.setEnabled(false); @@ -222,20 +232,7 @@ public class BatMain { 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() { @Override protected void measure(Event event, Object element) { diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java index c2a2cb8..1b8bcf3 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java @@ -11,12 +11,9 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import xyz.veronie.bgg.result.Thing; -import xyz.veronie.bgg.result.ThingDetailsComposite; import xyz.veronie.bgg.types.EventConstants; public class ThingListPart { - private ThingDetailsComposite thingDetailsComposite; - @PostConstruct public void createControls(Composite parent) { Composite main = new Composite(parent, SWT.FILL); @@ -24,14 +21,11 @@ public class ThingListPart { GridLayout layout = new GridLayout(2, false); main.setLayout(layout); - - thingDetailsComposite = new ThingDetailsComposite(main, SWT.BORDER); } @Inject @Optional private void selectedThingChanged(@UIEventTopic(EventConstants.TOPIC_THING_SELECTION) Thing thing) { - thingDetailsComposite.selectedThingChanged(thing); }