@@ -17,8 +17,10 @@ | |||
</children> | |||
<handlers xmi:id="_a0tuEGAUEeuNUoCJDLJTzQ" elementId="xyz.veronie.bgg.ui.handler.save" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.HandleSaveGamelist" command="_lA5t8F9TEeuvNqpgCDWpdQ"/> | |||
<handlers xmi:id="_xJXjUG3zEeuCP7xCflu8WA" elementId="xyz.veronie.bgg.ui.handler.load" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.HandleLoadGamelist" 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"/> | |||
<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="_rkauIG7REeutwMlAyj2x8w" elementId="xyz.veronie.bgg.ui.command.importResultTxt" commandName="ImportResultTxt" description="Import result.txt from bgg1tool"/> | |||
<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_Zs0qSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/> | |||
@@ -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<Thing> getThings(List<Integer> ids) { | |||
// TODO: retrieve a list of things from BGG with the given ids | |||
return new ArrayList<Thing>(); | |||
} | |||
public ArrayList<Thing> getThingsForUser(String user) throws IllegalArgumentException { | |||
@@ -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; | |||
} | |||
} |
@@ -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<Integer> thingIds = parseResultTxtIds(resultPath); | |||
} | |||
} | |||
private List<Integer> parseResultTxtIds(String resultPath) { | |||
FileReader input = null; | |||
String myLine = null; | |||
try { | |||
input = new FileReader(resultPath); | |||
BufferedReader bufferedReader = new BufferedReader(input); | |||
List<Integer> ids = new ArrayList<Integer>(); | |||
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; | |||
} | |||
} |