diff --git a/xyz.veronie.bgg.ui/Application.e4xmi b/xyz.veronie.bgg.ui/Application.e4xmi
index d296003..4ee48d0 100644
--- a/xyz.veronie.bgg.ui/Application.e4xmi
+++ b/xyz.veronie.bgg.ui/Application.e4xmi
@@ -11,6 +11,7 @@
+
diff --git a/xyz.veronie.bgg.ui/icons/folder-symbol.png b/xyz.veronie.bgg.ui/icons/folder-symbol.png
new file mode 100644
index 0000000..7863b0a
Binary files /dev/null and b/xyz.veronie.bgg.ui/icons/folder-symbol.png differ
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/LocalDbAdapterService.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/LocalDbAdapterService.java
new file mode 100644
index 0000000..4dec875
--- /dev/null
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/LocalDbAdapterService.java
@@ -0,0 +1,38 @@
+package xyz.veronie.bgg.localdb;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import xyz.veronie.bgg.result.ThingMetaData;
+
+public class LocalDbAdapterService {
+ private SqliteController sqliteController;
+
+ public LocalDbAdapterService() {
+ initDb();
+ }
+
+ private void initDb() {
+ File dbFile = new File(SqliteController.DB_PATH);
+ if(!dbFile.exists()) {
+ SqliteController.getInstance().createSchema();
+ }
+ sqliteController = SqliteController.getInstance();
+ }
+
+
+ /// add a list of things with the given name
+ public void storeThingList(List things, String name) {
+ sqliteController.openThingList(name);
+ sqliteController.addToThingList(name, things);
+ }
+
+ /// retrieve a list of things with the given name
+ public List retrieveThingList(String name) {
+ // TODO: implement retrieve thing list
+ return new ArrayList();
+ }
+
+
+}
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
new file mode 100644
index 0000000..ffc309e
--- /dev/null
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java
@@ -0,0 +1,134 @@
+package xyz.veronie.bgg.localdb;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+
+import xyz.veronie.bgg.result.ThingMetaData;
+
+public class SqliteController {
+
+ private static final SqliteController dbcontroller = new SqliteController();
+ private static Connection connection;
+ public static final String DB_PATH = System.getProperty("user.home") + "/" + "bggtool.db";
+
+ static {
+ try {
+ Class.forName("org.sqlite.JDBC");
+ } catch (ClassNotFoundException e) {
+ System.err.println("Error while loading JDBC driver");
+ e.printStackTrace();
+ }
+ }
+
+ private SqliteController() {
+ initDBConnection();
+ }
+
+ public static SqliteController getInstance() {
+ return dbcontroller;
+ }
+
+ private void initDBConnection() {
+ try {
+ if (connection != null)
+ return;
+ System.out.println("Creating Connection to Database...");
+ String filename = System.getProperty("user.home") + "/bggtool.db";
+ connection = DriverManager.getConnection("jdbc:sqlite:" + filename);
+ if (!connection.isClosed())
+ System.out.println("...Connection established");
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ try {
+ if (!connection.isClosed() && connection != null) {
+ connection.close();
+ if (connection.isClosed())
+ System.out.println("Connection to Database closed");
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ public void createSchema() {
+ try {
+ Statement stmt = connection.createStatement();
+ stmt.executeUpdate("DROP TABLE IF EXISTS Thing;");
+ stmt.executeUpdate("DROP TABLE IF EXISTS ThingList");
+ stmt.executeUpdate("DROP TABLE IF EXISTS ThingListToThing");
+
+ stmt.executeUpdate("CREATE TABLE Thing (ThingId INTEGER PRIMARY KEY, Name, ImgUrl, ThumbUrl, Comment, NumPlays);");
+ stmt.executeUpdate("CREATE TABLE ThingList (ListId INTEGER PRIMARY KEY, Name) ON DELETE CASCADE;");
+ stmt.executeUpdate("CREATE UNIQUE INDEX idx1 ON ThingList(Name)");
+ stmt.executeUpdate("CREATE TABLE ThingListToThing (ListId, ThingId, FOREIGN KEY (ListId) REFERENCES ThingList(ListId), FOREIGN KEY (ThingId) REFERENCES Thing(ThingId));");
+ stmt.executeUpdate("CREATE UNIQUE INDEX idx2 ON ThingListToThing(ListId, ThingId)");
+
+ } catch (SQLException e) {
+ System.err.println("Couldn't create Schema");
+ e.printStackTrace();
+ }
+ }
+
+ public void openThingList(String name) {
+ try {
+ Statement stmt = connection.createStatement();
+ // insert new thing list if one with that name does not exist already
+ stmt.executeQuery("INSERT INTO ThingList (name) VALUES ('" + name + "');");
+ } catch (SQLException e) {
+ System.err.println("Couldn't add to thing list with handle " + name);
+ e.printStackTrace();
+ }
+ }
+
+ public void addToThingList(String name, List things) {
+ try {
+
+ Statement stmt = connection.createStatement();
+ ResultSet res = stmt.executeQuery("SELECT ListId from ThingList where name = '" + name + "'");
+ int listId = res.getInt(0);
+
+ PreparedStatement thingStatement = connection
+ .prepareStatement("INSERT INTO Thing VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT REPLACE;");
+ PreparedStatement listToThingStatement = connection
+ .prepareStatement("INSERT INTO ThingListToThing VALUES (?, ?)");
+
+ for (ThingMetaData thing : things) {
+ thingStatement.setInt(1, thing.getId());
+ thingStatement.setString(2, thing.getName());
+ thingStatement.setString(3, thing.getImgURL());
+ thingStatement.setString(4, thing.getThumbURL());
+ thingStatement.setString(5, thing.getComment());
+ thingStatement.setInt(6, thing.getNumPlays());
+ thingStatement.addBatch();
+ // get generated id
+ ResultSet keys = thingStatement.getGeneratedKeys();
+ int thingId = keys.getInt(0);
+
+ listToThingStatement.setInt(0, listId);
+ listToThingStatement.setInt(1, thingId);
+ listToThingStatement.addBatch();
+ }
+
+ connection.setAutoCommit(false);
+ thingStatement.executeBatch();
+ connection.setAutoCommit(true);
+
+ } catch (SQLException e) {
+ System.err.println("Couldn't add to thing list with handle " + name);
+ e.printStackTrace();
+ }
+ }
+
+
+}
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java
index 436d79a..5f0ba0c 100644
--- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java
@@ -1,24 +1,29 @@
package xyz.veronie.bgg.result;
-import java.io.BufferedWriter;
-import java.io.FileWriter;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
-import xyz.veronie.bgg.result.ThingMetaData;
-import org.eclipse.core.runtime.Path;
+import javax.annotation.PostConstruct;
+import javax.inject.Singleton;
-//import com.google.gson.Gson;
+import org.eclipse.e4.core.di.annotations.Creatable;
-public enum ThingProvider {
- INSTANCE;
+import xyz.veronie.bgg.localdb.LocalDbAdapterService;
+
+@Creatable
+@Singleton
+public class ThingProvider {
+ private LocalDbAdapterService localDbAdapterService;
/// list of things. Each ID is expected to exist exactly once.
private List thingMetas;
+
+ public ThingProvider() {}
- private ThingProvider() {
+ @PostConstruct
+ public void init() {
+ localDbAdapterService = new LocalDbAdapterService();
thingMetas = new ArrayList();
}
@@ -69,23 +74,9 @@ public enum ThingProvider {
}
}
- /// create a tag of the current list
- public void tagResult() {
-// Gson gson = new Gson();
-// String resultList = gson.toJson(this.thingMetas);
-
- try {
- Path filesPath = new Path("result_" + Long.toString(System.currentTimeMillis()));
- System.out.println("File output path: " + filesPath);
- BufferedWriter writer = new BufferedWriter(
- new FileWriter(filesPath.toString()));
-// writer.write(resultList);
-
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
+ /// store current list in DB
+ public void storeList() {
+ localDbAdapterService.storeThingList(this.thingMetas, "TestList");
}
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleSaveGamelist.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleSaveGamelist.java
index 2113108..bfa9318 100644
--- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleSaveGamelist.java
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/HandleSaveGamelist.java
@@ -1,6 +1,8 @@
package xyz.veronie.bgg.ui.handlers;
+import javax.inject.Inject;
+
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
@@ -8,15 +10,17 @@ import xyz.veronie.bgg.result.ThingProvider;
public class HandleSaveGamelist {
+ @Inject
+ ThingProvider thingProvider;
+
@Execute
public void execute() {
- ThingProvider.INSTANCE.tagResult();
+ thingProvider.storeList();
}
@CanExecute
public boolean canExecute() {
- // TODO
return true;
}
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java
index 4bae887..c951f9e 100644
--- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java
@@ -6,18 +6,14 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Optional;
-import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
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.Label;
import org.eclipse.swt.widgets.Table;
@@ -31,6 +27,9 @@ public class BggResultPart {
private TableViewer viewer;
private Label statsLabel;
+ @Inject
+ private ThingProvider thingProvider;
+
@PostConstruct
public void createControls(Composite parent) {
Composite main = new Composite(parent, SWT.FILL);
@@ -62,7 +61,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.getThingMetas());
// make the selection available to other views
// TODO: getSite().setSelectionProvider(viewer);
// Set the sorter for the table
@@ -125,7 +124,7 @@ public class BggResultPart {
(@UIEventTopic(EventConstants.TOPIC_RESULT_CHANGED)
String empty) {
System.out.println("TOPIC_RESULT_CHANGED");
- List thingMetas = ThingProvider.INSTANCE.getThingMetas();
+ List thingMetas = thingProvider.getThingMetas();
viewer.setInput(thingMetas);
viewer.refresh();
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java
index d33363f..2786107 100644
--- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java
@@ -92,103 +92,103 @@ public class DownloadThingDetailsPart {
- Button onlyNewCheck = new Button(optionsGroup, SWT.CHECK);
- onlyNewCheck.setText("Only new");
-
- Button usePersNamesCheck = new Button(optionsGroup, SWT.CHECK);
- usePersNamesCheck.setText("Use pers. names");
- usePersNamesCheck.setEnabled(false);
-
- Button only1DesignerCheck = new Button(optionsGroup, SWT.CHECK);
- only1DesignerCheck.setText("Only one designer");
- only1DesignerCheck.setEnabled(false);
-
-
- Button withDescCheck = new Button(optionsGroup, SWT.CHECK);
- withDescCheck.setText("With description");
-
- Button usePersImagesCheck = new Button(optionsGroup, SWT.CHECK);
- usePersImagesCheck.setText("Use pers. images");
- usePersImagesCheck.setEnabled(false);
-
- Button only1PublisherCheck = new Button(optionsGroup, SWT.CHECK);
- only1PublisherCheck.setText("Only one publisher");
- only1PublisherCheck.setEnabled(false);
-
-
- Button limitDescCheck = new Button(optionsGroup, SWT.CHECK);
- limitDescCheck.setText("Limit description");
-
- Button useRecBestInfoCheck = new Button(optionsGroup, SWT.CHECK);
- useRecBestInfoCheck.setText("Use rec./best info");
- useRecBestInfoCheck.setEnabled(false);
-
- Button only1ArtistCheck = new Button(optionsGroup, SWT.CHECK);
- only1ArtistCheck.setText("Only one artist");
- only1ArtistCheck.setEnabled(false);
-
-
-
- Button downloadVotesCheck = new Button(optionsGroup, SWT.CHECK);
- downloadVotesCheck.setText("Download votes");
- downloadVotesCheck.setEnabled(false);
- downloadVotesCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- extendedInfoCheck.setEnabled(true);
- }
- });
-
- Button brnDetailCheck = new Button(optionsGroup, SWT.CHECK);
- brnDetailCheck.setText("B/R/N detail");
- brnDetailCheck.setEnabled(false);
-
- Button reloadDataCheck = new Button(optionsGroup, SWT.CHECK);
- reloadDataCheck.setText("Reload data");
- reloadDataCheck.setEnabled(false);
-
-
-
- extendedInfoCheck = new Button(optionsGroup, SWT.CHECK);
- extendedInfoCheck.setText(" Extended info");
- extendedInfoCheck.setEnabled(false); // enabled when download votes is checked
-
- Button downloadPlaysCheck = new Button(optionsGroup, SWT.CHECK);
- downloadPlaysCheck.setText("Download plays");
- downloadPlaysCheck.setEnabled(false);
- downloadPlaysCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- downloadAllPlaysCheck.setEnabled(true);
- }
- });
-
- Button reloadImagesCheck = new Button(optionsGroup, SWT.CHECK);
- reloadImagesCheck.setText("Reload images");
- reloadImagesCheck.setEnabled(false);
-
-
-
- Button downloadLangCheck = new Button(optionsGroup, SWT.CHECK);
- downloadLangCheck.setText("Download lang.");
- downloadLangCheck.setEnabled(false);
-
- downloadAllPlaysCheck = new Button(optionsGroup, SWT.CHECK);
- downloadAllPlaysCheck.setText(" Download plays (all)");
- downloadAllPlaysCheck.setEnabled(false); // enabled when download plays checked
-
- Button ReloadQRCodesCheck = new Button(optionsGroup, SWT.CHECK);
- ReloadQRCodesCheck.setText("Reload QR codes");
- ReloadQRCodesCheck.setEnabled(false);
-
-
- Button namesImgCheck = new Button(optionsGroup, SWT.CHECK);
- namesImgCheck.setText("Names in images");
- namesImgCheck.setEnabled(false);
-
- Button useQrCodesCheck = new Button(optionsGroup, SWT.CHECK);
- useQrCodesCheck.setText("Use QR codes");
- useQrCodesCheck.setEnabled(false);
+// Button onlyNewCheck = new Button(optionsGroup, SWT.CHECK);
+// onlyNewCheck.setText("Only new");
+//
+// Button usePersNamesCheck = new Button(optionsGroup, SWT.CHECK);
+// usePersNamesCheck.setText("Use pers. names");
+// usePersNamesCheck.setEnabled(false);
+//
+// Button only1DesignerCheck = new Button(optionsGroup, SWT.CHECK);
+// only1DesignerCheck.setText("Only one designer");
+// only1DesignerCheck.setEnabled(false);
+//
+//
+// Button withDescCheck = new Button(optionsGroup, SWT.CHECK);
+// withDescCheck.setText("With description");
+//
+// Button usePersImagesCheck = new Button(optionsGroup, SWT.CHECK);
+// usePersImagesCheck.setText("Use pers. images");
+// usePersImagesCheck.setEnabled(false);
+//
+// Button only1PublisherCheck = new Button(optionsGroup, SWT.CHECK);
+// only1PublisherCheck.setText("Only one publisher");
+// only1PublisherCheck.setEnabled(false);
+//
+//
+// Button limitDescCheck = new Button(optionsGroup, SWT.CHECK);
+// limitDescCheck.setText("Limit description");
+//
+// Button useRecBestInfoCheck = new Button(optionsGroup, SWT.CHECK);
+// useRecBestInfoCheck.setText("Use rec./best info");
+// useRecBestInfoCheck.setEnabled(false);
+//
+// Button only1ArtistCheck = new Button(optionsGroup, SWT.CHECK);
+// only1ArtistCheck.setText("Only one artist");
+// only1ArtistCheck.setEnabled(false);
+//
+//
+//
+// Button downloadVotesCheck = new Button(optionsGroup, SWT.CHECK);
+// downloadVotesCheck.setText("Download votes");
+// downloadVotesCheck.setEnabled(false);
+// downloadVotesCheck.addSelectionListener(new SelectionAdapter() {
+// @Override
+// public void widgetSelected(SelectionEvent e) {
+// extendedInfoCheck.setEnabled(true);
+// }
+// });
+//
+// Button brnDetailCheck = new Button(optionsGroup, SWT.CHECK);
+// brnDetailCheck.setText("B/R/N detail");
+// brnDetailCheck.setEnabled(false);
+//
+// Button reloadDataCheck = new Button(optionsGroup, SWT.CHECK);
+// reloadDataCheck.setText("Reload data");
+// reloadDataCheck.setEnabled(false);
+//
+//
+//
+// extendedInfoCheck = new Button(optionsGroup, SWT.CHECK);
+// extendedInfoCheck.setText(" Extended info");
+// extendedInfoCheck.setEnabled(false); // enabled when download votes is checked
+//
+// Button downloadPlaysCheck = new Button(optionsGroup, SWT.CHECK);
+// downloadPlaysCheck.setText("Download plays");
+// downloadPlaysCheck.setEnabled(false);
+// downloadPlaysCheck.addSelectionListener(new SelectionAdapter() {
+// @Override
+// public void widgetSelected(SelectionEvent e) {
+// downloadAllPlaysCheck.setEnabled(true);
+// }
+// });
+//
+// Button reloadImagesCheck = new Button(optionsGroup, SWT.CHECK);
+// reloadImagesCheck.setText("Reload images");
+// reloadImagesCheck.setEnabled(false);
+//
+//
+//
+// Button downloadLangCheck = new Button(optionsGroup, SWT.CHECK);
+// downloadLangCheck.setText("Download lang.");
+// downloadLangCheck.setEnabled(false);
+//
+// downloadAllPlaysCheck = new Button(optionsGroup, SWT.CHECK);
+// downloadAllPlaysCheck.setText(" Download plays (all)");
+// downloadAllPlaysCheck.setEnabled(false); // enabled when download plays checked
+//
+// Button ReloadQRCodesCheck = new Button(optionsGroup, SWT.CHECK);
+// ReloadQRCodesCheck.setText("Reload QR codes");
+// ReloadQRCodesCheck.setEnabled(false);
+//
+//
+// Button namesImgCheck = new Button(optionsGroup, SWT.CHECK);
+// namesImgCheck.setText("Names in images");
+// namesImgCheck.setEnabled(false);
+//
+// Button useQrCodesCheck = new Button(optionsGroup, SWT.CHECK);
+// useQrCodesCheck.setText("Use QR codes");
+// useQrCodesCheck.setEnabled(false);
}
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/PreparePart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/PreparePart.java
index 84bebe4..12d6d21 100644
--- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/PreparePart.java
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/PreparePart.java
@@ -56,7 +56,11 @@ public class PreparePart {
@Inject
private ResultConfigManager configManager;
- @Inject private IEventBroker eventBroker;
+ @Inject
+ private IEventBroker eventBroker;
+
+ @Inject
+ private ThingProvider thingProvider;
// inject all source filter composites
@Inject private BggUserSourceFilter bggUserSourceFilter;
@@ -196,16 +200,16 @@ public class PreparePart {
private void useThingsOnResult(ArrayList thingMetas) {
switch(configManager.getResultConfig().action) {
case REP:
- ThingProvider.INSTANCE.replaceThingMetas(thingMetas);
+ thingProvider.replaceThingMetas(thingMetas);
break;
case ADD:
- ThingProvider.INSTANCE.addThingMetas(thingMetas);
+ thingProvider.addThingMetas(thingMetas);
break;
case SUB:
- ThingProvider.INSTANCE.subtractThingMetas(thingMetas);
+ thingProvider.subtractThingMetas(thingMetas);
break;
case AND:
- ThingProvider.INSTANCE.intersectThingMetas(thingMetas);
+ thingProvider.intersectThingMetas(thingMetas);
break;
}
eventBroker.send(EventConstants.TOPIC_RESULT_CHANGED, "");