Ticket #5135: undelete.2.diff
| File undelete.2.diff, 9.5 KB (added by , 16 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/UploadSelectionAction.java
79 79 for (OsmPrimitive p: primitives) { 80 80 if (p.isNew()) { 81 81 ret.add(p); 82 } else if (p.is Visible() && p.isModified() && !p.isIncomplete()) {82 } else if (p.isModified() && !p.isIncomplete()) { 83 83 ret.add(p); 84 84 } 85 85 } … … 170 170 /** 171 171 * Computes the collection of primitives to upload, given a collection of candidate 172 172 * primitives. 173 * Some of the candidates are excluded, i.e. if they aren't modified or if they 174 * aren't visible. 173 * Some of the candidates are excluded, i.e. if they aren't modified. 175 174 * Other primitives are added. A typical case is a primitive which is new and and 176 175 * which is referred by a modified relation. In order to upload the relation the 177 176 * new primitive has to be uploaded as well, even if it isn't included in the … … 186 185 } 187 186 188 187 public void visit(Node n) { 189 if (n.isNew() || ((n.isModified() || n.isDeleted()) && n.isVisible())) {188 if (n.isNew() || n.isModified() || n.isDeleted()) { 190 189 // upload new nodes as well as modified and deleted ones 191 190 hull.add(n); 192 191 } 193 192 } 194 193 195 194 public void visit(Way w) { 196 if (w.isNew() || ((w.isModified() || w.isDeleted()) && w.isVisible())) {195 if (w.isNew() || w.isModified() || w.isDeleted()) { 197 196 // upload new ways as well as modified and deleted ones 198 197 hull.add(w); 199 198 for (Node n: w.getNodes()) { … … 205 204 } 206 205 207 206 public void visit(Relation r) { 208 if (r.isNew() || ((r.isModified() || r.isDeleted()) && r.isVisible())) {207 if (r.isNew() || r.isModified() || r.isDeleted()) { 209 208 hull.add(r); 210 209 for (OsmPrimitive p : r.getMemberPrimitives()) { 211 210 // add new relation members. Don't include modified -
src/org/openstreetmap/josm/io/DiffResultProcessor.java
124 124 processed.add(p); 125 125 if (!p.isDeleted()) { 126 126 p.setOsmId(entry.new_id, entry.new_version); 127 p.setVisible(true); 127 128 } 128 129 if (cs != null && !cs.isNew()) { 129 130 p.setChangesetId(cs.getId()); -
src/org/openstreetmap/josm/io/OsmApi.java
274 274 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor); 275 275 osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim())); 276 276 osm.setChangesetId(getChangeset().getId()); 277 osm.setVisible(true); 277 278 } catch(NumberFormatException e) { 278 279 throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret)); 279 280 } -
src/org/openstreetmap/josm/io/OsmWriter.java
97 97 } 98 98 99 99 private boolean shouldWrite(OsmPrimitive osm) { 100 return !osm.isNew() || !osm.isDeleted();100 return (!osm.isNew() && osm.isVisible()) || !osm.isDeleted(); 101 101 } 102 102 103 103 public void writeDataSources(DataSet ds) { -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
391 391 } 392 392 393 393 /** 394 * Replies <code>true</code> if the object has been deleted on the server and was undeleted by the user. 395 * @return <code>true</code> if the object has been undeleted 396 */ 397 public boolean isUndeleted() { 398 return (flags & (FLAG_VISIBLE + FLAG_DELETED)) == 0; 399 } 400 401 /** 394 402 * Replies <code>true</code>, if the object is usable (i.e. complete 395 403 * and not deleted). 396 404 * … … 426 434 427 435 public static Predicate<OsmPrimitive> nonDeletedPredicate = new Predicate<OsmPrimitive>() { 428 436 public boolean evaluate(OsmPrimitive primitive) { 429 return primitive.isVisible() &&!primitive.isDeleted();437 return !primitive.isDeleted(); 430 438 } 431 439 }; 432 440 433 441 public static Predicate<OsmPrimitive> nonDeletedCompletePredicate = new Predicate<OsmPrimitive>() { 434 442 public boolean evaluate(OsmPrimitive primitive) { 435 return primitive.isVisible() &&!primitive.isDeleted() && !primitive.isIncomplete();443 return !primitive.isDeleted() && !primitive.isIncomplete(); 436 444 } 437 445 }; 438 446 439 447 public static Predicate<OsmPrimitive> nonDeletedPhysicalPredicate = new Predicate<OsmPrimitive>() { 440 448 public boolean evaluate(OsmPrimitive primitive) { 441 return primitive.isVisible() &&!primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation);449 return !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation); 442 450 } 443 451 }; 444 452 445 453 public static Predicate<OsmPrimitive> modifiedPredicate = new Predicate<OsmPrimitive>() { 446 454 public boolean evaluate(OsmPrimitive primitive) { 447 return primitive.is Visible() && primitive.isModified();455 return primitive.isModified(); 448 456 } 449 457 }; 450 458 … … 721 729 } else { 722 730 flags &= ~FLAG_DELETED; 723 731 } 724 setModified(deleted );732 setModified(deleted ^ !isVisible()); 725 733 if (dataSet != null) { 726 734 if (deleted) { 727 735 dataSet.firePrimitivesRemoved(Collections.singleton(this), false); -
src/org/openstreetmap/josm/data/APIDataSet.java
56 56 toUpdate.clear(); 57 57 toDelete.clear(); 58 58 59 boolean sortUpdated = false; 59 60 for (OsmPrimitive osm :ds.allPrimitives()) { 60 61 if (osm.get("josm/ignore") != null) { 61 62 continue; … … 63 64 if (osm.isNew() && !osm.isDeleted()) { 64 65 toAdd.add(osm); 65 66 } else if (osm.isModified() && !osm.isDeleted()) { 67 if (osm.isUndeleted()) { 68 sortUpdated = true; 69 } 66 70 toUpdate.add(osm); 67 71 } else if (osm.isDeleted() && !osm.isNew() && osm.isModified()) { 68 72 toDelete.add(osm); … … 70 74 } 71 75 sortDeleted(); 72 76 sortNew(); 77 if (sortUpdated) { 78 sortUpdated(); 79 } 73 80 } 74 81 75 82 /** … … 131 138 } 132 139 ); 133 140 } 141 134 142 /** 143 * Ensures that primitives are modified in the following order: Nodes, then Ways, 144 * then Relations. It's necessary for uploading undeleted objects. 145 * 146 */ 147 protected void sortUpdated() { 148 Collections.sort( 149 toUpdate, 150 new Comparator<OsmPrimitive>() { 151 public int compare(OsmPrimitive o1, OsmPrimitive o2) { 152 if (o1 instanceof Node && o2 instanceof Node) 153 return 0; 154 else if (o1 instanceof Node) 155 return -1; 156 else if (o2 instanceof Node) 157 return 1; 158 159 if (o1 instanceof Way && o2 instanceof Way) 160 return 0; 161 else if (o1 instanceof Way && o2 instanceof Relation) 162 return -1; 163 else if (o2 instanceof Way && o1 instanceof Relation) 164 return 1; 165 166 return 0; 167 } 168 } 169 ); 170 } 171 172 /** 135 173 * initializes the API data set with the modified primitives in <code>ds</code> 136 174 * 137 175 * @param ds the data set. Ignored, if null. … … 196 234 toAdd.clear(); 197 235 toUpdate.clear(); 198 236 toDelete.clear(); 237 238 boolean sortUpdated = false; 199 239 for (OsmPrimitive osm: primitives) { 200 240 if (osm.isNew() && !osm.isDeleted()) { 201 241 toAdd.addLast(osm); 202 242 } else if (osm.isModified() && !osm.isDeleted()) { 203 243 toUpdate.addLast(osm); 244 if (osm.isUndeleted()) { 245 sortUpdated = true; 246 } 204 247 } else if (osm.isDeleted() && !osm.isNew() && osm.isModified()) { 205 248 toDelete.addFirst(osm); 206 249 } 207 250 } 208 251 sortNew(); 209 252 sortDeleted(); 253 if (sortUpdated) { 254 sortUpdated(); 255 } 210 256 } 211 257 212 258 /**
