Ticket #9634: ticket9634_2014-04-06_08:56:16_+0200.patch
File ticket9634_2014-04-06_08:56:16_+0200.patch, 13.6 KB (added by , 9 years ago) |
---|
-
src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java
diff --git src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java index 5bae4eb..99e52d0 100644
import java.awt.Font; 9 9 import java.awt.GridBagLayout; 10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.KeyEvent; 12 import java.io.IOException; 12 13 import java.lang.reflect.InvocationTargetException; 13 14 import java.util.List; 14 15 import java.util.Set; … … import org.openstreetmap.josm.data.osm.DataSet; 26 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 28 import org.openstreetmap.josm.data.osm.PrimitiveId; 28 29 import org.openstreetmap.josm.gui.ExtendedDialog; 30 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 29 31 import org.openstreetmap.josm.gui.download.DownloadObjectDialog; 30 32 import org.openstreetmap.josm.gui.io.DownloadPrimitivesTask; 31 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 32 34 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 33 35 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 36 import org.openstreetmap.josm.io.OsmTransferException; 34 37 import org.openstreetmap.josm.tools.GBC; 35 38 import org.openstreetmap.josm.tools.Shortcut; 36 39 import org.openstreetmap.josm.tools.Utils; 40 import org.xml.sax.SAXException; 37 41 38 42 /** 39 43 * Download an OsmPrimitive by specifying type and ID … … public class DownloadPrimitiveAction extends JosmAction { 67 71 * @param full if the members of a relation should be downloaded as well 68 72 */ 69 73 public static void processItems(boolean newLayer, final List<PrimitiveId> ids, boolean downloadReferrers, boolean full) { 70 OsmDataLayer layer = getEditLayer(); 71 if ((layer == null) || newLayer) { 72 layer = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null); 73 Main.main.addLayer(layer); 74 } 75 final DownloadPrimitivesTask task = new DownloadPrimitivesTask(layer, ids, full); 76 Main.worker.submit(task); 74 75 class DownloadPrimitivesWithReferrersTask extends PleaseWaitRunnable { 76 final OsmDataLayer layer; 77 List<PrimitiveId> ids; 78 boolean full; 79 DownloadPrimitivesTask task; 80 81 DownloadPrimitivesWithReferrersTask(final OsmDataLayer layer, List<PrimitiveId> ids, 82 boolean full) { //, ProgressMonitor monitor) { 83 super(tr("Download objects"), false); 84 this.layer = layer; 85 this.ids = ids; 86 this.full = full; 87 } 88 89 @Override 90 protected void cancel() { 91 // FIXME: how to do ? 92 } 77 93 78 if (downloadReferrers) { 79 for (PrimitiveId id : ids) { 80 Main.worker.submit(new DownloadReferrersTask(layer, id)); 94 @Override 95 protected void realRun() throws SAXException, IOException, OsmTransferException { 96 task = new DownloadPrimitivesTask(layer, ids, full, getProgressMonitor().createSubTaskMonitor(1, false)); 97 // FIXME: Need to run task in an other thread (like Main.worker.submit(task) ? 98 task.run(); 99 getProgressMonitor().setTicksCount(ids.size()); 100 for(PrimitiveId id : ids) { 101 System.out.printf("referrers task %s\n", id.toString()); 102 // FIXME: In an other thread ? 103 new DownloadReferrersTask(layer, id, getProgressMonitor().createSubTaskMonitor(1, false)).run(); 104 } 81 105 } 82 }83 106 84 Runnable showErrorsAndWarnings = new Runnable() {85 107 @Override 86 public void run() { 87 final Set<PrimitiveId> errs = task.getMissingPrimitives(); 88 if (errs != null && !errs.isEmpty()) { 89 try { 90 SwingUtilities.invokeAndWait(new Runnable() { 91 @Override 92 public void run() { 93 reportProblemDialog(errs, 94 trn("Object could not be downloaded", "Some objects could not be downloaded", errs.size()), 95 trn("One object could not be downloaded.<br>", 96 "{0} objects could not be downloaded.<br>", 97 errs.size(), 98 errs.size()) 99 + tr("The server replied with response code 404.<br>" 100 + "This usually means, the server does not know an object with the requested id."), 101 tr("missing objects:"), 102 JOptionPane.ERROR_MESSAGE 103 ).showDialog(); 108 protected void finish() { 109 // FIXME: Does all task are really finish ? 110 System.out.printf("call to finish\n"); 111 Runnable showErrorsAndWarnings = new Runnable() { 112 @Override 113 public void run() { 114 final Set<PrimitiveId> errs = task.getMissingPrimitives(); 115 if (errs != null && !errs.isEmpty()) { 116 try { 117 SwingUtilities.invokeAndWait(new Runnable() { 118 @Override 119 public void run() { 120 reportProblemDialog(errs, 121 trn("Object could not be downloaded", "Some objects could not be downloaded", errs.size()), 122 trn("One object could not be downloaded.<br>", 123 "{0} objects could not be downloaded.<br>", 124 errs.size(), 125 errs.size()) 126 + tr("The server replied with response code 404.<br>" 127 + "This usually means, the server does not know an object with the requested id."), 128 tr("missing objects:"), 129 JOptionPane.ERROR_MESSAGE 130 ).showDialog(); 131 } 132 }); 133 } catch (InterruptedException ex) { 134 Main.warn("InterruptedException while displaying error dialog"); 135 } catch (InvocationTargetException ex) { 136 Main.warn(ex); 104 137 } 105 }); 106 } catch (InterruptedException ex) { 107 Main.warn("InterruptedException while displaying error dialog"); 108 } catch (InvocationTargetException ex) { 109 Main.warn(ex); 110 } 111 } 138 } 112 139 113 final Set<PrimitiveId> del = new TreeSet<PrimitiveId>(); 114 DataSet ds = getCurrentDataSet(); 115 for (PrimitiveId id : ids) { 116 OsmPrimitive osm = ds.getPrimitiveById(id); 117 if (osm != null && osm.isDeleted()) { 118 del.add(id); 119 } 120 } 121 if (!del.isEmpty()) { 122 SwingUtilities.invokeLater(new Runnable() { 123 @Override 124 public void run() { 125 reportProblemDialog(del, 126 trn("Object deleted", "Objects deleted", del.size()), 127 trn( 128 "One downloaded object is deleted.", 129 "{0} downloaded objects are deleted.", 130 del.size(), 131 del.size()), 132 null, 133 JOptionPane.WARNING_MESSAGE 134 ).showDialog(); 140 final Set<PrimitiveId> del = new TreeSet<PrimitiveId>(); 141 DataSet ds = getCurrentDataSet(); 142 for (PrimitiveId id : ids) { 143 OsmPrimitive osm = ds.getPrimitiveById(id); 144 if (osm != null && osm.isDeleted()) { 145 del.add(id); 146 } 135 147 } 136 }); 137 } 148 if (!del.isEmpty()) { 149 SwingUtilities.invokeLater(new Runnable() { 150 @Override 151 public void run() { 152 reportProblemDialog(del, 153 trn("Object deleted", "Objects deleted", del.size()), 154 trn( 155 "One downloaded object is deleted.", 156 "{0} downloaded objects are deleted.", 157 del.size(), 158 del.size()), 159 null, 160 JOptionPane.WARNING_MESSAGE 161 ).showDialog(); 162 } 163 }); 164 } 165 } 166 }; 167 Main.worker.submit(showErrorsAndWarnings); 138 168 } 139 }; 140 Main.worker.submit(showErrorsAndWarnings); 169 } 170 171 System.out.printf("DEBUG: DownloadPrimitiveAction.processItems\n"); 172 OsmDataLayer layer = getEditLayer(); 173 if ((layer == null) || newLayer) { 174 layer = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null); 175 Main.main.addLayer(layer); 176 } 177 178 final DownloadPrimitivesWithReferrersTask task = 179 new DownloadPrimitivesWithReferrersTask(layer, ids, full); //, monitor); 180 Main.worker.submit(task); 181 182 System.out.printf("task done\n"); 141 183 } 142 184 143 185 private static ExtendedDialog reportProblemDialog(Set<PrimitiveId> errs, -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java
diff --git src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java index ce7c850..5111174 100644
public class DownloadReferrersTask extends PleaseWaitRunnable { 141 141 parents = new DataSet(); 142 142 } 143 143 144 /** 145 * constructor 146 * 147 * @param targetLayer the target layer. Must not be null. 148 * @param primitiveId a PrimitiveId object. 149 * @exception IllegalArgumentException thrown if id <= 0 150 * @exception IllegalArgumentException thrown if targetLayer == null 151 * 152 */ 153 public DownloadReferrersTask(OsmDataLayer targetLayer, PrimitiveId primitiveId, 154 ProgressMonitor progressMonitor) throws IllegalArgumentException { 155 super("Download referrers", progressMonitor, false /* don't ignore exception*/); 156 CheckParameterUtil.ensureParameterNotNull(targetLayer, "targetLayer"); 157 if (primitiveId.isNew()) 158 throw new IllegalArgumentException(MessageFormat.format("Cannot download referrers for new primitives (ID {0})", primitiveId.getUniqueId())); 159 canceled = false; 160 this.children = new HashMap<Long, OsmPrimitiveType>(); 161 this.children.put(primitiveId.getUniqueId(), primitiveId.getType()); 162 this.targetLayer = targetLayer; 163 parents = new DataSet(); 164 } 165 144 166 @Override 145 167 protected void cancel() { 146 168 canceled = true; -
src/org/openstreetmap/josm/gui/io/DownloadPrimitivesTask.java
diff --git src/org/openstreetmap/josm/gui/io/DownloadPrimitivesTask.java src/org/openstreetmap/josm/gui/io/DownloadPrimitivesTask.java index 519a151..3f8758d 100644
public class DownloadPrimitivesTask extends PleaseWaitRunnable { 58 58 this.fullRelation = fullRelation; 59 59 } 60 60 61 /** 62 * Creates the task 63 * 64 * @param layer the layer in which primitives are updated. Must not be null. 65 * @param ids a collection of primitives to update from the server. Set to 66 * the empty collection if null. 67 * @param fullRelation true if a full download is required, i.e., 68 * a download including the immediate children of a relation. 69 * @throws IllegalArgumentException thrown if layer is null. 70 */ 71 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation, 72 ProgressMonitor progessMonitor) throws IllegalArgumentException { 73 super(tr("Download objects"), progessMonitor, false /* don't ignore exception */); 74 ensureParameterNotNull(layer, "layer"); 75 this.ids = ids; 76 this.layer = layer; 77 this.fullRelation = fullRelation; 78 } 79 61 80 @Override 62 81 protected void cancel() { 63 82 canceled = true;