Repository for the HealthTool which enables Apple users to analyse their health data from the Apple health app and prepares the data for contributing it for future studies on wearable data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.7 KiB

3 years ago
  1. package application.helpers;
  2. import application.helpers.wrappers.WrappedException;
  3. import javafx.application.Platform;
  4. /**
  5. * This thread is used to enable working in the background while the progress
  6. * view is displayed
  7. *
  8. * @author Bianca
  9. *
  10. */
  11. public class WorkWhileProgressThread extends Thread
  12. {
  13. /**
  14. * The callback used to change the view after the work is done
  15. */
  16. private ChangeViewCallback cb;
  17. /**
  18. * There are 2 possible workloads: reading the file for the overview
  19. * ({@code True}) or creating the files for being inspected ({@code False})
  20. */
  21. private boolean overview;
  22. /**
  23. *
  24. * @param cb The callback
  25. * @param overView {@code True} if the initial file needs to be read or
  26. * {@code False} if the files for being inspected need to be
  27. * created
  28. */
  29. public WorkWhileProgressThread(ChangeViewCallback cb, boolean overView)
  30. {
  31. this.cb = cb;
  32. this.overview = overView;
  33. }
  34. @Override
  35. public void run()
  36. {
  37. //read the file
  38. if (overview)
  39. {
  40. try
  41. {
  42. this.cb.callFillDataList();
  43. }
  44. catch (WrappedException e)
  45. {
  46. cb.callErrorReadingFile(e.getReason());
  47. }
  48. Platform.runLater(new Runnable()
  49. {
  50. @Override
  51. public void run()
  52. {
  53. cb.callOverview();
  54. }
  55. });
  56. }
  57. else
  58. { //create the selected files
  59. try
  60. {
  61. this.cb.callCreateTempFiles();
  62. Platform.runLater(new Runnable()
  63. {
  64. @Override
  65. public void run()
  66. {
  67. cb.callInspect();
  68. }
  69. });
  70. }
  71. catch (WrappedException e)
  72. {
  73. this.cb.callErrorWritingTemFiles(e.getReason());
  74. Platform.runLater(new Runnable()
  75. {
  76. @Override
  77. public void run()
  78. {
  79. cb.callInspectWithError();
  80. }
  81. });
  82. }
  83. }
  84. }
  85. }