|
-
- package xyz.veronie.bgg.ui.handlers;
-
- import org.eclipse.e4.core.di.annotations.Execute;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.widgets.MessageBox;
- import org.eclipse.swt.widgets.Shell;
-
- import xyz.veronie.bgg.result.BggApi;
- import xyz.veronie.bgg.result.Thing;
- import xyz.veronie.bgg.result.ThingProvider;
- import xyz.veronie.bgg.ui.helpers.Resources;
-
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
-
- import javax.inject.Inject;
-
- import org.eclipse.e4.core.di.annotations.CanExecute;
-
- public class ExportResultHandler {
-
- private static final String RESULT_TXT = "result.txt";
-
- @Inject
- ThingProvider thingProvider;
-
- @Execute
- public void execute(Shell shell, BggApi bggApi) {
- thingProvider.fetchDetails();
-
- String exportString = thingProvider.toResultString();
- String resultFilePath = Resources.INSTANCE.getTmpDir() + File.separator + RESULT_TXT;
- try {
- BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath));
- writer.write(exportString);
- writer.close();
- }
- catch (IOException e) {
- MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
- msgBox.setMessage("Could not write tmp file '" + resultFilePath + "'.");
- msgBox.open();
- e.printStackTrace();
- }
- }
-
- @CanExecute
- public boolean canExecute() {
- return thingProvider != null;
- }
-
- }
|