Changeset 9905 in josm for trunk/src/org
- Timestamp:
- 2016-03-01T20:36:36+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java
r9067 r9905 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GraphicsEnvironment; 6 7 import java.util.ArrayList; 7 8 import java.util.Collection; 8 9 import java.util.LinkedHashSet; 9 import java.util.List;10 10 import java.util.Set; 11 11 import java.util.concurrent.Future; … … 22 22 public class PostDownloadHandler implements Runnable { 23 23 private final DownloadTask task; 24 private final List<Future<?>> futures;24 private final Future<?> future; 25 25 26 26 /** … … 31 31 public PostDownloadHandler(DownloadTask task, Future<?> future) { 32 32 this.task = task; 33 this.futures = new ArrayList<>(); 34 if (future != null) { 35 this.futures.add(future); 36 } 37 } 38 39 /** 40 * constructor 41 * @param task the asynchronous download task 42 * @param futures the futures on which the completion of the download task can be synchronized 43 */ 44 public PostDownloadHandler(DownloadTask task, Future<?> ... futures) { 45 this.task = task; 46 this.futures = new ArrayList<>(); 47 if (futures == null) return; 48 for (Future<?> future: futures) { 49 this.futures.add(future); 50 } 51 } 52 53 /** 54 * constructor 55 * @param task the asynchronous download task 56 * @param futures the futures on which the completion of the download task can be synchronized 57 */ 58 public PostDownloadHandler(DownloadTask task, List<Future<?>> futures) { 59 this.task = task; 60 this.futures = new ArrayList<>(); 61 if (futures == null) return; 62 this.futures.addAll(futures); 33 this.future = future; 63 34 } 64 35 65 36 @Override 66 37 public void run() { 67 // wait for all downloads task to finish (by waiting for the futuresto return a value)38 // wait for downloads task to finish (by waiting for the future to return a value) 68 39 // 69 for (Future<?> future: futures) { 70 try { 71 future.get(); 72 } catch (Exception e) { 73 Main.error(e); 74 return; 75 } 40 try { 41 future.get(); 42 } catch (Exception e) { 43 Main.error(e); 44 return; 76 45 } 77 46 78 47 // make sure errors are reported only once 79 48 // 80 Set<Object> errors = new LinkedHashSet<>(); 81 errors.addAll(task.getErrorObjects()); 49 Set<Object> errors = new LinkedHashSet<>(task.getErrorObjects()); 82 50 if (errors.isEmpty()) 83 51 return; … … 87 55 if (errors.size() == 1) { 88 56 final Object error = errors.iterator().next(); 89 SwingUtilities.invokeLater(new Runnable() { 90 @Override 91 public void run() { 92 if (error instanceof Exception) { 93 ExceptionDialogUtil.explainException((Exception) error); 94 } else if (tr("No data found in this area.").equals(error)) { 95 new Notification(error.toString()).setIcon(JOptionPane.WARNING_MESSAGE).show(); 96 } else { 97 JOptionPane.showMessageDialog( 98 Main.parent, 99 error.toString(), 100 tr("Error during download"), 101 JOptionPane.ERROR_MESSAGE); 57 if (!GraphicsEnvironment.isHeadless()) { 58 SwingUtilities.invokeLater(new Runnable() { 59 @Override 60 public void run() { 61 if (error instanceof Exception) { 62 ExceptionDialogUtil.explainException((Exception) error); 63 } else if (tr("No data found in this area.").equals(error)) { 64 new Notification(error.toString()).setIcon(JOptionPane.WARNING_MESSAGE).show(); 65 } else { 66 JOptionPane.showMessageDialog( 67 Main.parent, 68 error.toString(), 69 tr("Error during download"), 70 JOptionPane.ERROR_MESSAGE); 71 } 102 72 } 103 } 104 } );73 }); 74 } 105 75 return; 106 76 } … … 110 80 if (!errors.isEmpty()) { 111 81 final Collection<String> items = new ArrayList<>(); 112 for (Object error :errors) {82 for (Object error : errors) { 113 83 if (error instanceof String) { 114 84 items.add((String) error); … … 118 88 } 119 89 120 SwingUtilities.invokeLater(new Runnable() { 121 @Override 122 public void run() { 123 JOptionPane.showMessageDialog( 124 Main.parent, 125 "<html>"+Utils.joinAsHtmlUnorderedList(items)+"</html>", 126 tr("Errors during download"), 127 JOptionPane.ERROR_MESSAGE); 128 } 129 }); 90 if (!GraphicsEnvironment.isHeadless()) { 91 SwingUtilities.invokeLater(new Runnable() { 92 @Override 93 public void run() { 94 JOptionPane.showMessageDialog( 95 Main.parent, 96 "<html>"+Utils.joinAsHtmlUnorderedList(items)+"</html>", 97 tr("Errors during download"), 98 JOptionPane.ERROR_MESSAGE); 99 } 100 }); 101 } 130 102 return; 131 103 }
Note:
See TracChangeset
for help on using the changeset viewer.