- Timestamp:
- 2009-07-26T11:09:46+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ChildRelationBrowser.java
r1847 r1850 10 10 import java.awt.event.ActionEvent; 11 11 import java.io.IOException; 12 import java.net.HttpURLConnection; 12 13 import java.util.HashSet; 13 14 import java.util.Iterator; … … 19 20 import javax.swing.AbstractAction; 20 21 import javax.swing.JButton; 21 import javax.swing.JDialog;22 22 import javax.swing.JOptionPane; 23 23 import javax.swing.JPanel; … … 41 41 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 42 42 import org.openstreetmap.josm.io.OsmApi; 43 import org.openstreetmap.josm.io.OsmApiException; 43 44 import org.openstreetmap.josm.io.OsmServerObjectReader; 44 45 import org.openstreetmap.josm.io.OsmTransferException; … … 346 347 } 347 348 349 /** 350 * warns the user if a relation couldn't be loaded because it was deleted on 351 * the server (the server replied a HTTP code 410) 352 * 353 * @param r the relation 354 */ 355 protected void warnBecauseOfDeletedRelation(Relation r) { 356 PrimitiveNameFormatter nameFormatter = new PrimitiveNameFormatter(); 357 358 String message = tr("<html>The child relation<br>" 359 + "{0}<br>" 360 + "is deleted on the server. It can't be loaded", 361 nameFormatter.getName(r) 362 ); 363 364 OptionPaneUtil.showMessageDialog( 365 Main.parent, 366 message, 367 tr("Relation is deleted"), 368 JOptionPane.WARNING_MESSAGE 369 ); 370 } 371 372 /** 373 * Remembers the child relations to download 374 * 375 * @param parent the parent relation 376 */ 377 protected void rememberChildRelationsToDownload(Relation parent) { 378 downloadedRelationIds.add(parent.id); 379 for (RelationMember member: parent.members) { 380 if (member.member instanceof Relation) { 381 Relation child = (Relation)member.member; 382 if (!downloadedRelationIds.contains(child)) { 383 relationsToDownload.push(child); 384 } 385 } 386 } 387 } 388 389 /** 390 * Merges the primitives in <code>ds</code> to the dataset of the 391 * edit layer 392 * 393 * @param ds the data set 394 */ 395 protected void mergeDataSet(DataSet ds) { 396 if (ds != null) { 397 final MergeVisitor visitor = new MergeVisitor(getLayer().data, ds); 398 visitor.merge(); 399 // FIXME: this is necessary because there are dialogs listening 400 // for DataChangeEvents which manipulate Swing components on this 401 // thread. 402 // 403 SwingUtilities.invokeLater(new Runnable() { 404 public void run() { 405 getLayer().fireDataChange(); 406 } 407 }); 408 if (!visitor.getConflicts().isEmpty()) { 409 getLayer().getConflicts().add(visitor.getConflicts()); 410 conflictsCount += visitor.getConflicts().size(); 411 } 412 } 413 } 414 348 415 @Override 349 416 protected void realRun() throws SAXException, IOException, OsmTransferException { … … 352 419 while(! relationsToDownload.isEmpty() && !cancelled) { 353 420 Relation r = relationsToDownload.pop(); 354 downloadedRelationIds.add(r.id); 355 for (RelationMember member: r.members) { 356 if (member.member instanceof Relation) { 357 Relation child = (Relation)member.member; 358 if (!downloadedRelationIds.contains(child)) { 359 relationsToDownload.push(child); 360 } 361 } 362 } 421 rememberChildRelationsToDownload(r); 363 422 progressMonitor.setCustomText(tr("Downloading relation {0}", nameFormatter.getName(r))); 364 423 OsmServerObjectReader reader = new OsmServerObjectReader(r.id, OsmPrimitiveType.RELATION, 365 424 true); 366 DataSet dataSet = reader.parseOsm(progressMonitor 367 .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 368 if (dataSet != null) { 369 final MergeVisitor visitor = new MergeVisitor(getLayer().data, dataSet); 370 visitor.merge(); 371 // FIXME: this is necessary because there are dialogs listening 372 // for DataChangeEvents which manipulate Swing components on this 373 // thread. 374 // 375 SwingUtilities.invokeLater(new Runnable() { 376 public void run() { 377 getLayer().fireDataChange(); 378 } 379 }); 380 if (!visitor.getConflicts().isEmpty()) { 381 getLayer().getConflicts().add(visitor.getConflicts()); 382 conflictsCount += visitor.getConflicts().size(); 425 DataSet dataSet = null; 426 try { 427 dataSet = reader.parseOsm(progressMonitor 428 .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 429 } catch(OsmApiException e) { 430 if (e.getResponseCode() == HttpURLConnection.HTTP_GONE) { 431 warnBecauseOfDeletedRelation(r); 432 continue; 383 433 } 434 throw e; 384 435 } 436 mergeDataSet(dataSet); 385 437 refreshView(r); 386 438 }
Note:
See TracChangeset
for help on using the changeset viewer.