An Eclipse RCP reimplementation of bgg1tool by Nand. See http://www.nand.it/nandeck/ for the original tool.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5KB

  1. package xyz.veronie.bgg.ui.handlers;
  2. import org.eclipse.e4.core.di.annotations.Execute;
  3. import org.eclipse.swt.SWT;
  4. import org.eclipse.swt.widgets.MessageBox;
  5. import org.eclipse.swt.widgets.Shell;
  6. import xyz.veronie.bgg.result.BggApi;
  7. import xyz.veronie.bgg.result.Thing;
  8. import xyz.veronie.bgg.result.ThingProvider;
  9. import xyz.veronie.bgg.ui.helpers.Resources;
  10. import java.io.BufferedWriter;
  11. import java.io.File;
  12. import java.io.FileWriter;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import java.util.HashSet;
  16. import java.util.List;
  17. import java.util.Set;
  18. import javax.inject.Inject;
  19. import org.eclipse.e4.core.di.annotations.CanExecute;
  20. public class ExportResultHandler {
  21. private static final String RESULT_TXT = "result.txt";
  22. @Inject
  23. ThingProvider thingProvider;
  24. @Execute
  25. public void execute(Shell shell, BggApi bggApi) {
  26. thingProvider.fetchDetails();
  27. String exportString = thingProvider.toResultString();
  28. String resultFilePath = Resources.INSTANCE.getTmpDir() + File.separator + RESULT_TXT;
  29. try {
  30. BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath));
  31. writer.write(exportString);
  32. writer.close();
  33. }
  34. catch (IOException e) {
  35. MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
  36. msgBox.setMessage("Could not write tmp file '" + resultFilePath + "'.");
  37. msgBox.open();
  38. e.printStackTrace();
  39. }
  40. }
  41. @CanExecute
  42. public boolean canExecute() {
  43. return thingProvider != null;
  44. }
  45. }