diff --git a/xyz.veronie.bgg.ui/Application.e4xmi b/xyz.veronie.bgg.ui/Application.e4xmi
index 32eaa62..be08761 100644
--- a/xyz.veronie.bgg.ui/Application.e4xmi
+++ b/xyz.veronie.bgg.ui/Application.e4xmi
@@ -17,8 +17,10 @@
+
+
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 7600914..3353aeb 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
@@ -11,6 +11,7 @@ import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import java.util.Map.Entry;
import javax.inject.Inject;
@@ -61,6 +62,10 @@ public class BggApi {
}
}
+ public ArrayList getThings(List ids) {
+ // TODO: retrieve a list of things from BGG with the given ids
+ return new ArrayList();
+ }
public ArrayList getThingsForUser(String user) throws IllegalArgumentException {
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java
index d93b044..9994d12 100644
--- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/dialogs/LoadGameListDialog.java
@@ -2,6 +2,9 @@ package xyz.veronie.bgg.ui.dialogs;
import java.util.List;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -26,6 +29,7 @@ import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.wb.swt.SWTResourceManager;
import xyz.veronie.bgg.ui.helpers.BatColors;
+import org.eclipse.swt.widgets.Button;
public class LoadGameListDialog extends Dialog {
private String selectedName;
@@ -112,6 +116,21 @@ public class LoadGameListDialog extends Dialog {
});
column.pack();
+
+ Composite otherActionsComposite = new Composite(container, SWT.NONE);
+ otherActionsComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ otherActionsComposite.setLayout(new GridLayout(1, false));
+
+ Button btnImport = new Button(otherActionsComposite, SWT.NONE);
+ btnImport.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseUp(MouseEvent e) {
+ importFromBggTool1Result();
+ }
+ });
+ btnImport.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ btnImport.setBounds(0, 0, 75, 25);
+ btnImport.setText("Import from BggTool1 result.txt...");
return container;
}
@@ -122,7 +141,15 @@ public class LoadGameListDialog extends Dialog {
this.close();
}
-
+ private void importFromBggTool1Result() {
+// ECommandService commandService, EHandlerService handlerService
+// ParameterizedCommand cmd =
+// commandService.createCommand("xyz.veronie.bgg.ui.command.importResultTxt", null);
+// if (handlerService.canExecute(cmd)){
+// handlerService.executeHandler(cmd);
+// }
+ }
+
/**
* Create contents of the button bar.
* @param parent
@@ -146,5 +173,4 @@ public class LoadGameListDialog extends Dialog {
public String getSelectedName() {
return selectedName;
}
-
}
diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ImportResultTxtHandler.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ImportResultTxtHandler.java
new file mode 100644
index 0000000..2c9025f
--- /dev/null
+++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ImportResultTxtHandler.java
@@ -0,0 +1,96 @@
+
+package xyz.veronie.bgg.ui.handlers;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+
+public class ImportResultTxtHandler {
+
+ private Shell shell;
+
+
+ @Execute
+ public void execute(Shell shell) {
+ this.shell = shell;
+
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setText("Select a result.txt from bgg1tool");
+ String[] exfilters = { "*.txt" };
+ dialog.setFilterExtensions(exfilters);
+ String resultPath = dialog.open();
+
+ if(resultPath != null && !resultPath.isEmpty()) {
+ List thingIds = parseResultTxtIds(resultPath);
+
+ }
+ }
+
+
+ private List parseResultTxtIds(String resultPath) {
+ FileReader input = null;
+ String myLine = null;
+ try {
+ input = new FileReader(resultPath);
+
+ BufferedReader bufferedReader = new BufferedReader(input);
+
+ List ids = new ArrayList();
+ while ( (myLine = bufferedReader.readLine()) != null)
+ {
+ String[] tokens = myLine.split(",");
+ if(tokens.length > 1) {
+ ids.add(Integer.parseInt(tokens[0]));
+ }
+ }
+
+ bufferedReader.close();
+ System.out.println("TRACE: " + ids);
+ return ids;
+
+ } catch (FileNotFoundException e) {
+ MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
+ msgBox.setMessage("Could not open file '" + resultPath + "'.");
+ msgBox.open();
+ e.printStackTrace();
+ } catch (IOException e) {
+ MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
+ String msg = "Error while parsing '" + resultPath + "'.\r\n" +
+ "It must have comma separated lines starting with an integer number.\r\n";
+ msgBox.setMessage(msg);
+ msgBox.open();
+ e.printStackTrace();
+ }
+ catch (NumberFormatException e) {
+ MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
+ String msg = "Error while parsing '" + resultPath + "'.\r\n" +
+ "It must have comma separated lines starting with an integer number.\r\n";
+ if(myLine != null) {
+ msg.concat("The offending line reads\r\n" + myLine);
+ }
+ msgBox.setMessage(msg);
+ msgBox.open();
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+
+ @CanExecute
+ public boolean canExecute() {
+
+ return true;
+ }
+
+}
\ No newline at end of file