Changeset 2077 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2009-09-07T23:06:19+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 3 edited
-
UpdateSelectionAction.java (modified) (3 diffs)
-
UploadAction.java (modified) (11 diffs)
-
downloadtasks/DownloadOsmTaskList.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r2025 r2077 16 16 import org.openstreetmap.josm.data.osm.Node; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 18 19 import org.openstreetmap.josm.data.osm.Relation; 19 20 import org.openstreetmap.josm.data.osm.Way; … … 39 40 * @param id the primitive id 40 41 */ 41 protected void handlePrimitiveGoneException(long id) { 42 protected void handlePrimitiveGoneException(long id, OsmPrimitiveType type) { 42 43 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 43 reader.append(getCurrentDataSet(),id); 44 reader.append(getCurrentDataSet(),id, type); 44 45 DataSet ds = null; 45 46 try { … … 73 74 * 74 75 */ 75 public void updatePrimitive(long id) throws IllegalStateException{ 76 public void updatePrimitive(OsmPrimitiveType type, long id) throws IllegalStateException{ 76 77 if (getEditLayer() == null) 77 78 throw new IllegalStateException(tr("No current dataset found")); 78 OsmPrimitive primitive = getEditLayer().data.getPrimitiveById(id); 79 OsmPrimitive primitive = getEditLayer().data.getPrimitiveById(id, type); 79 80 if (primitive == null) 80 81 throw new IllegalStateException(tr("Didn't find a primitive with id {0} in the current dataset", id)); -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r2074 r2077 41 41 import org.openstreetmap.josm.data.osm.DataSet; 42 42 import org.openstreetmap.josm.data.osm.OsmPrimitive; 43 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 43 44 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 44 45 import org.openstreetmap.josm.gui.ExtendedDialog; … … 191 192 * @param id the primitive ID 192 193 */ 193 protected void synchronizePrimitive(final String id) {194 Main.worker.execute(new UpdatePrimitiveTask( Long.parseLong(id)));194 protected void synchronizePrimitive(final OsmPrimitiveType type, final long id) { 195 Main.worker.execute(new UpdatePrimitiveTask(type, id)); 195 196 } 196 197 … … 217 218 * @param myVersion the version of the primitive in the local dataset 218 219 */ 219 protected void handleUploadConflictForKnownConflict( StringprimitiveType,String id, String serverVersion, String myVersion) {220 protected void handleUploadConflictForKnownConflict(OsmPrimitiveType primitiveType, long id, String serverVersion, String myVersion) { 220 221 Object[] options = new Object[] { 221 tr("Synchronize {0} {1} only", tr(primitiveType), id), 222 tr("Synchronize {0} {1} only", tr(primitiveType.getAPIName()), id), 222 223 tr("Synchronize entire dataset"), 223 224 tr("Cancel") … … 232 233 + "Click <strong>{5}</strong> to synchronize the entire local dataset with the server.<br>" 233 234 + "Click <strong>{6}</strong> to abort and continue editing.<br></html>", 234 tr(primitiveType), id, serverVersion, myVersion, 235 tr(primitiveType.getAPIName()), id, serverVersion, myVersion, 235 236 options[0], options[1], options[2] 236 237 ); … … 247 248 ); 248 249 switch(ret) { 249 case JOptionPane.CLOSED_OPTION: return;250 case JOptionPane.CANCEL_OPTION: return;251 case 0: synchronizePrimitive(id); break;252 case 1: synchronizeDataSet(); break;253 default:254 // should not happen255 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret));250 case JOptionPane.CLOSED_OPTION: return; 251 case JOptionPane.CANCEL_OPTION: return; 252 case 0: synchronizePrimitive(primitiveType, id); break; 253 case 1: synchronizeDataSet(); break; 254 default: 255 // should not happen 256 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret)); 256 257 } 257 258 } … … 287 288 ); 288 289 switch(ret) { 289 case JOptionPane.CLOSED_OPTION: return;290 case 1: return;291 case 0: synchronizeDataSet(); break;292 default:293 // should not happen294 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret));290 case JOptionPane.CLOSED_OPTION: return; 291 case 1: return; 292 case 0: synchronizeDataSet(); break; 293 default: 294 // should not happen 295 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret)); 295 296 } 296 297 } … … 306 307 Matcher m = p.matcher(e.getErrorHeader()); 307 308 if (m.matches()) { 308 handleUploadConflictForKnownConflict(m.group(3) ,m.group(4), m.group(2),m.group(1));309 handleUploadConflictForKnownConflict(OsmPrimitiveType.from(m.group(3)), Long.parseLong(m.group(4)), m.group(2),m.group(1)); 309 310 } else { 310 311 logger.warning(tr("Warning: error header \"{0}\" did not match expected pattern \"{1}\"", e.getErrorHeader(),pattern)); … … 326 327 * @see UpdateSelectionAction#handlePrimitiveGoneException(long) 327 328 */ 328 protected void handleGoneForKnownPrimitive( StringprimitiveType, String id) {329 protected void handleGoneForKnownPrimitive(OsmPrimitiveType primitiveType, String id) { 329 330 UpdateSelectionAction act = new UpdateSelectionAction(); 330 act.handlePrimitiveGoneException(Long.parseLong(id)); 331 act.handlePrimitiveGoneException(Long.parseLong(id),primitiveType); 331 332 } 332 333 … … 344 345 Matcher m = p.matcher(e.getErrorHeader()); 345 346 if (m.matches()) { 346 handleGoneForKnownPrimitive(m.group(1), m.group(2)); 347 handleGoneForKnownPrimitive(OsmPrimitiveType.from(m.group(1)), m.group(2)); 347 348 } else { 348 349 logger.warning(tr("Error header \"{0}\" does not match expected pattern \"{1}\"",e.getErrorHeader(), pattern)); … … 424 425 private Exception lastException = null; 425 426 private long id; 426 427 public UpdatePrimitiveTask(long id) { 427 private OsmPrimitiveType type; 428 429 public UpdatePrimitiveTask(OsmPrimitiveType type, long id) { 428 430 super(tr("Updating primitive"),false /* don't ignore exceptions */); 429 431 this.id = id; 432 this.type = type; 430 433 } 431 434 … … 433 436 try { 434 437 UpdateSelectionAction act = new UpdateSelectionAction(); 435 act.updatePrimitive(id); 438 act.updatePrimitive(type, id); 436 439 } catch (Exception sxe) { 437 440 if (uploadCancelled) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r2017 r2077 125 125 final OsmDataLayer editLayer = Main.map.mapView.getEditLayer(); 126 126 if (editLayer != null) { 127 Set<Long> myPrimitiveIds = editLayer.data.getCompletePrimitiveIds(); 128 Set<Long> downloadedIds = getDownloadedIds(); 129 myPrimitiveIds.removeAll(downloadedIds); 130 myPrimitiveIds.remove(new Long(0)); // ignore new primitives 131 if (! myPrimitiveIds.isEmpty()) { 132 handlePotentiallyDeletedPrimitives(myPrimitiveIds); 133 } 134 } 127 Set<OsmPrimitive> myPrimitives = getCompletePrimitives(editLayer.data); 128 for (DownloadTask task : osmTasks) { 129 if(task instanceof DownloadOsmTask) { 130 DataSet ds = ((DownloadOsmTask)task).getDownloadedData(); 131 if (ds != null) { 132 myPrimitives.removeAll(ds.nodes); 133 myPrimitives.removeAll(ds.ways); 134 myPrimitives.removeAll(ds.relations); 135 } 136 } 137 } 138 if (! myPrimitives.isEmpty()) { 139 handlePotentiallyDeletedPrimitives(myPrimitives); 140 } 141 } 142 } 143 144 145 /** 146 * Replies the set of ids of all complete primitives (i.e. those with 147 * ! primitive.incomplete) 148 * 149 * @return the set of ids of all complete primitives 150 */ 151 protected Set<OsmPrimitive> getCompletePrimitives(DataSet ds) { 152 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 153 for (OsmPrimitive primitive : ds.nodes) { 154 if (!primitive.incomplete && primitive.getId() == 0) { 155 ret.add(primitive); 156 } 157 } 158 for (OsmPrimitive primitive : ds.ways) { 159 if (! primitive.incomplete && primitive.getId() == 0) { 160 ret.add(primitive); 161 } 162 } 163 for (OsmPrimitive primitive : ds.relations) { 164 if (! primitive.incomplete && primitive.getId() == 0) { 165 ret.add(primitive);; 166 } 167 } 168 return ret; 135 169 } 136 170 … … 141 175 * @param potentiallyDeleted a set of ids to check update from the server 142 176 */ 143 protected void updatePotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) { 144 DataSet ds = Main.map.mapView.getEditLayer().data; 177 protected void updatePotentiallyDeletedPrimitives(Set<OsmPrimitive> potentiallyDeleted) { 145 178 final ArrayList<OsmPrimitive> toSelect = new ArrayList<OsmPrimitive>(); 146 for (Long id : potentiallyDeleted) { 147 OsmPrimitive primitive = ds.getPrimitiveById(id); 179 for (OsmPrimitive primitive : potentiallyDeleted) { 148 180 if (primitive != null) { 149 181 toSelect.add(primitive); … … 167 199 * @param potentiallyDeleted a set of primitives (given by their ids) 168 200 */ 169 protected void handlePotentiallyDeletedPrimitives(Set< Long> potentiallyDeleted) {201 protected void handlePotentiallyDeletedPrimitives(Set<OsmPrimitive> potentiallyDeleted) { 170 202 String [] options = { 171 203 "Check on the server", … … 197 229 ); 198 230 switch(ret) { 199 case JOptionPane.CLOSED_OPTION: return; 200 case JOptionPane.NO_OPTION: return; 201 case JOptionPane.YES_OPTION: updatePotentiallyDeletedPrimitives(potentiallyDeleted); break; 202 } 203 } 204 205 /** 206 * replies true, if the primitive with id <code>id</code> was downloaded into the 207 * dataset <code>ds</code> 208 * 209 * @param id the id 210 * @param ds the dataset 211 * @return true, if the primitive with id <code>id</code> was downloaded into the 212 * dataset <code>ds</code>; false otherwise 213 */ 214 protected boolean wasDownloaded(long id, DataSet ds) { 215 OsmPrimitive primitive = ds.getPrimitiveById(id); 216 return primitive != null; 217 } 218 219 /** 220 * replies true, if the primitive with id <code>id</code> was downloaded into the 221 * dataset of one of the download tasks 222 * 223 * @param id the id 224 * @return true, if the primitive with id <code>id</code> was downloaded into the 225 * dataset of one of the download tasks 226 * 227 */ 228 public boolean wasDownloaded(long id) { 229 for (DownloadTask task : osmTasks) { 230 if(task instanceof DownloadOsmTask) { 231 DataSet ds = ((DownloadOsmTask)task).getDownloadedData(); 232 if(wasDownloaded(id,ds)) return true; 233 } 234 } 235 return false; 231 case JOptionPane.CLOSED_OPTION: return; 232 case JOptionPane.NO_OPTION: return; 233 case JOptionPane.YES_OPTION: updatePotentiallyDeletedPrimitives(potentiallyDeleted); break; 234 } 236 235 } 237 236 … … 241 240 * @return the set of primitive ids which have been downloaded by this task list 242 241 */ 243 public Set< Long> getDownloadedIds() {244 HashSet< Long> ret = new HashSet<Long>();242 public Set<OsmPrimitive> getDownloadedPrimitives() { 243 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 245 244 for (DownloadTask task : osmTasks) { 246 245 if(task instanceof DownloadOsmTask) { 247 246 DataSet ds = ((DownloadOsmTask)task).getDownloadedData(); 248 247 if (ds != null) { 249 ret.addAll(ds.getPrimitiveIds()); 248 ret.addAll(ds.nodes); 249 ret.addAll(ds.ways); 250 ret.addAll(ds.relations); 250 251 } 251 252 }
Note:
See TracChangeset
for help on using the changeset viewer.
