- Timestamp:
- 2009-08-03T15:00:34+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r1890 r1894 216 216 return; 217 217 } 218 layer.clean Data(null, false);218 layer.cleanupAfterSaveToDisk(); 219 219 } catch (IOException e) { 220 220 e.printStackTrace(); -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1885 r1894 235 235 ); 236 236 switch(ret) { 237 case JOptionPane.CLOSED_OPTION: return;238 case JOptionPane.CANCEL_OPTION: return;239 case 0: synchronizePrimitive(id); break;240 case 1: synchronizeDataSet(); break;241 default:242 // should not happen243 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret));237 case JOptionPane.CLOSED_OPTION: return; 238 case JOptionPane.CANCEL_OPTION: return; 239 case 0: synchronizePrimitive(id); break; 240 case 1: synchronizeDataSet(); break; 241 default: 242 // should not happen 243 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret)); 244 244 } 245 245 } … … 274 274 ); 275 275 switch(ret) { 276 case JOptionPane.CLOSED_OPTION: return;277 case 1: return;278 case 0: synchronizeDataSet(); break;279 default:280 // should not happen281 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret));276 case JOptionPane.CLOSED_OPTION: return; 277 case 1: return; 278 case 0: synchronizeDataSet(); break; 279 default: 280 // should not happen 281 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret)); 282 282 } 283 283 } … … 537 537 try { 538 538 writer.uploadOsm(getCurrentDataSet().version, toUpload, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 539 getEditLayer().cleanData(writer.processed, !toUpload.isEmpty());540 539 } catch (Exception sxe) { 541 540 if (uploadCancelled) { … … 550 549 if (uploadCancelled) 551 550 return; 551 552 // we always clean the data, even in case of errors. It's possible the data was 553 // partially uploaded 554 // 555 getEditLayer().cleanupAfterUpload(writer.getProcessedPrimitives()); 552 556 if (lastException != null) { 553 557 handleFailedUpload(lastException); -
trunk/src/org/openstreetmap/josm/command/Command.java
r1856 r1894 89 89 e.getKey().cloneFrom(e.getValue()); 90 90 } 91 getLayer().setModified(true); 91 92 } 92 93 -
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r1877 r1894 99 99 } 100 100 101 public void layerRemoved(Layer oldLayer) { 101 public void clean(Layer layer) { 102 if (layer == null) 103 return; 102 104 boolean changed = false; 103 105 for (Iterator<Command> it = commands.iterator(); it.hasNext();) { 104 if (it.next().invalidBecauselayerRemoved( oldLayer)) {106 if (it.next().invalidBecauselayerRemoved(layer)) { 105 107 it.remove(); 106 108 changed = true; … … 108 110 } 109 111 for (Iterator<Command> it = redoCommands.iterator(); it.hasNext();) { 110 if (it.next().invalidBecauselayerRemoved( oldLayer)) {112 if (it.next().invalidBecauselayerRemoved(layer)) { 111 113 it.remove(); 112 114 changed = true; … … 118 120 } 119 121 122 public void layerRemoved(Layer oldLayer) { 123 clean(oldLayer); 124 } 125 120 126 public void layerAdded(Layer newLayer) {} 121 127 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r1890 r1894 65 65 import org.openstreetmap.josm.tools.ImageProvider; 66 66 67 import sun.security.action.GetLongAction; 68 67 69 /** 68 70 * A layer holding data from a specific dataset. … … 317 319 318 320 /** 321 * Cleanup the layer after save to disk. Just marks the layer as unmodified. 322 * Leaves the undo/redo stack unchanged. 323 * 324 */ 325 public void cleanupAfterSaveToDisk() { 326 setModified(false); 327 } 328 329 /** 319 330 * Clean out the data behind the layer. This means clearing the redo/undo lists, 320 * really deleting all deleted objects and reset the modified flags. This is done321 * after a successfull upload.331 * really deleting all deleted objects and reset the modified flags. This should 332 * be done after an upload, even after a partial upload. 322 333 * 323 334 * @param processed A list of all objects that were actually uploaded. 324 * May be <code>null</code>, which means nothing has been uploaded but 325 * saved to disk instead. Note that an empty collection for "processed" 326 * means that an upload has been attempted but failed. 327 */ 328 public void cleanData(final Collection<OsmPrimitive> processed, boolean dataAdded) { 335 * May be <code>null</code>, which means nothing has been uploaded 336 */ 337 public void cleanupAfterUpload(final Collection<OsmPrimitive> processed) { 329 338 330 339 // return immediately if an upload attempt failed 331 if (processed != null && processed.isEmpty() && !dataAdded)340 if (processed == null || processed.isEmpty()) 332 341 return; 333 342 334 Main.main.undoRedo.clean( );343 Main.main.undoRedo.clean(this); 335 344 336 345 // if uploaded, clean the modified flags as well 337 if (processed != null) { 338 final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed); 339 for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) { 340 cleanIterator(it, processedSet); 341 } 342 for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) { 343 cleanIterator(it, processedSet); 344 } 345 for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext();) { 346 cleanIterator(it, processedSet); 347 } 348 } 349 350 // update the modified flag 351 boolean b = (getAssociatedFile() != null && processed != null); 352 if (b && !dataAdded) 353 return; // do nothing when uploading non-harmful changes. 354 355 // modified if server changed the data (esp. the id). 356 uploadedModified = b && dataAdded; 357 setModified(uploadedModified); 346 final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed); 347 for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) { 348 cleanIterator(it, processedSet); 349 } 350 for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) { 351 cleanIterator(it, processedSet); 352 } 353 for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext();) { 354 cleanIterator(it, processedSet); 355 } 356 357 setModified(true); 358 358 } 359 359 -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r1879 r1894 507 507 } 508 508 509 /** 510 * Replies the current changeset 511 * 512 * @return the current changeset 513 */ 514 public Changeset getCurrentChangeset() { 515 return changeset; 516 } 509 517 } -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1879 r1894 5 5 6 6 import java.util.Collection; 7 import java.util.Collections; 7 8 import java.util.LinkedList; 8 9 import java.util.List; … … 11 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.actions.UploadAction; 14 import org.openstreetmap.josm.data.osm.Changeset; 13 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 34 36 * than where passed in the list to upload*. 35 37 */ 36 p ublicCollection<OsmPrimitive> processed;38 private Collection<OsmPrimitive> processed; 37 39 38 40 private OsmApi api = OsmApi.getOsmApi(); … … 79 81 80 82 /** 83 * Uploads the changes individually. Invokes one API call per uploaded primitmive. 84 * 85 * @param primitives the collection of primitives to upload 86 * @param progressMonitor the progress monitor 87 * @throws OsmTransferException thrown if an exception occurs 88 */ 89 protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 90 try { 91 progressMonitor.setTicksCount(primitives.size()); 92 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 93 uploadStartTime = System.currentTimeMillis(); 94 for (OsmPrimitive osm : primitives) { 95 int progress = progressMonitor.getTicks(); 96 String time_left_str = timeLeft(progress, primitives.size()); 97 progressMonitor.subTask( 98 tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})", 99 Math.round(100.0*progress/primitives.size()), progress, 100 primitives.size(), time_left_str, 101 OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(), 102 NAME_FORMATTER.getName(osm), 103 osm.id)); 104 makeApiRequest(osm,progressMonitor); 105 processed.add(osm); 106 progressMonitor.worked(1); 107 } 108 } catch(OsmTransferException e) { 109 throw e; 110 } catch(Exception e) { 111 throw new OsmTransferException(e); 112 } finally { 113 try { 114 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 115 } catch(Exception e) { 116 Changeset changeset = api.getCurrentChangeset(); 117 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.id)); 118 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}", 119 changesetId, e.toString())); 120 } 121 } 122 } 123 124 /** 125 * Upload all changes in one diff upload 126 * 127 * @param primitives the collection of primitives to upload 128 * @param progressMonitor the progress monitor 129 * @throws OsmTransferException thrown if an exception occurs 130 */ 131 protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 132 // upload everything in one changeset 133 // 134 try { 135 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 136 processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 137 } catch(OsmTransferException e) { 138 throw e; 139 } catch(Exception e) { 140 throw new OsmTransferException(e); 141 } finally { 142 try { 143 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 144 } catch (Exception ee) { 145 Changeset changeset = api.getCurrentChangeset(); 146 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.id)); 147 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}", 148 changesetId, ee.toString())); 149 } 150 } 151 } 152 153 /** 81 154 * Send the dataset to the server. 82 155 * … … 92 165 93 166 try { 94 95 167 // check whether we can use changeset 96 168 // … … 103 175 104 176 if (useChangeset) { 105 // upload everything in one changeset 106 // 107 try { 108 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 109 processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 110 } catch(OsmTransferException e) { 111 throw e; 112 } finally { 113 try { 114 if (canUseChangeset) { 115 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 116 } 117 } catch (Exception ee) { 118 ee.printStackTrace(); 119 // ignore nested exception 120 } 121 } 177 uploadChangesAsDiffUpload(primitives, progressMonitor); 122 178 } else { 123 // upload changes individually (90% of code is for the status display...) 124 // 125 progressMonitor.setTicksCount(primitives.size()); 126 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 127 uploadStartTime = System.currentTimeMillis(); 128 for (OsmPrimitive osm : primitives) { 129 int progress = progressMonitor.getTicks(); 130 String time_left_str = timeLeft(progress, primitives.size()); 131 progressMonitor.subTask( 132 tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})", 133 Math.round(100.0*progress/primitives.size()), progress, 134 primitives.size(), time_left_str, 135 OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(), 136 NAME_FORMATTER.getName(osm), 137 osm.id)); 138 makeApiRequest(osm,progressMonitor); 139 processed.add(osm); 140 progressMonitor.worked(1); 141 } 142 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 143 } 144 179 uploadChangesIndividually(primitives, progressMonitor); 180 } 145 181 } finally { 146 182 progressMonitor.finishTask(); … … 163 199 } 164 200 } 201 202 /** 203 * Replies the collection of successfully processed primitives 204 * 205 * @return the collection of successfully processed primitives 206 */ 207 public Collection<OsmPrimitive> getProcessedPrimitives() { 208 return processed; 209 } 165 210 }
Note:
See TracChangeset
for help on using the changeset viewer.