Changeset 1870 in josm for trunk/src/org
- Timestamp:
- 2009-07-29T18:04:24+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1865 r1870 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.FlowLayout; 7 import java.awt.GridBagConstraints; 6 8 import java.awt.GridBagLayout; 7 9 import java.awt.event.ActionEvent; … … 16 18 import java.util.regex.Pattern; 17 19 20 import javax.swing.JCheckBox; 18 21 import javax.swing.JLabel; 19 22 import javax.swing.JList; 20 23 import javax.swing.JOptionPane; 21 24 import javax.swing.JPanel; 25 import javax.swing.JRadioButton; 22 26 import javax.swing.JScrollPane; 23 27 … … 92 96 * give the user the possibility to cancel the upload. 93 97 */ 94 uploadHooks.add(new UploadHook() { 95 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) { 96 97 JPanel p = new JPanel(new GridBagLayout()); 98 99 OsmPrimitivRenderer renderer = new OsmPrimitivRenderer(); 100 101 if (!add.isEmpty()) { 102 p.add(new JLabel(tr("Objects to add:")), GBC.eol()); 103 JList l = new JList(add.toArray()); 104 l.setCellRenderer(renderer); 105 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 106 p.add(new JScrollPane(l), GBC.eol().fill()); 107 } 108 109 if (!update.isEmpty()) { 110 p.add(new JLabel(tr("Objects to modify:")), GBC.eol()); 111 JList l = new JList(update.toArray()); 112 l.setCellRenderer(renderer); 113 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 114 p.add(new JScrollPane(l), GBC.eol().fill()); 115 } 116 117 if (!delete.isEmpty()) { 118 p.add(new JLabel(tr("Objects to delete:")), GBC.eol()); 119 JList l = new JList(delete.toArray()); 120 l.setCellRenderer(renderer); 121 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 122 p.add(new JScrollPane(l), GBC.eol().fill()); 123 } 124 125 p.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3)); 126 SuggestingJHistoryComboBox cmt = new SuggestingJHistoryComboBox(); 127 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>())); 128 cmt.setHistory(cmtHistory); 129 //final JTextField cmt = new JTextField(lastCommitComment); 130 p.add(cmt, GBC.eol().fill(GBC.HORIZONTAL)); 131 132 while(true) { 133 int result = new ExtendedDialog(Main.parent, 134 tr("Upload these changes?"), 135 p, 136 new String[] {tr("Upload Changes"), tr("Cancel")}, 137 new String[] {"upload.png", "cancel.png"}).getValue(); 138 139 // cancel pressed 140 if (result != 1) return false; 141 142 // don't allow empty commit message 143 if (cmt.getText().trim().length() < 3) { 144 continue; 145 } 146 147 // store the history of comments 148 cmt.addCurrentItemToHistory(); 149 Main.pref.putCollection(HISTORY_KEY, cmt.getHistory()); 150 151 break; 152 } 153 return true; 154 } 155 }); 98 uploadHooks.add(new UploadConfirmationHook()); 156 99 } 157 100 … … 275 218 */ 276 219 protected void synchronizePrimitive(final String id) { 277 278 /** 279 * The asynchronous task to update a a specific id 280 * 281 */ 282 class UpdatePrimitiveTask extends PleaseWaitRunnable { 283 284 private boolean uploadCancelled = false; 285 private boolean uploadFailed = false; 286 private Exception lastException = null; 287 288 public UpdatePrimitiveTask() { 289 super(tr("Updating primitive"),false /* don't ignore exceptions */); 290 } 291 292 @Override protected void realRun() throws SAXException, IOException { 293 try { 294 UpdateSelectionAction act = new UpdateSelectionAction(); 295 act.updatePrimitive(Long.parseLong(id)); 296 } catch (Exception sxe) { 297 if (uploadCancelled) { 298 System.out.println("Ignoring exception caught because upload is cancelled. Exception is: " + sxe.toString()); 299 return; 300 } 301 uploadFailed = true; 302 lastException = sxe; 303 } 304 } 305 306 @Override protected void finish() { 307 if (uploadFailed) { 308 handleFailedUpload(lastException); 309 } 310 } 311 312 @Override protected void cancel() { 313 OsmApi.getOsmApi().cancel(); 314 uploadCancelled = true; 315 } 316 } 317 318 Main.worker.execute(new UpdatePrimitiveTask()); 220 Main.worker.execute(new UpdatePrimitiveTask(Long.parseLong(id))); 319 221 } 320 222 … … 370 272 ); 371 273 switch(ret) { 372 case JOptionPane.CLOSED_OPTION: return;373 case JOptionPane.CANCEL_OPTION: return;374 case 0: synchronizePrimitive(id); break;375 case 1: synchronizeDataSet(); break;376 default:377 // should not happen378 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret));274 case JOptionPane.CLOSED_OPTION: return; 275 case JOptionPane.CANCEL_OPTION: return; 276 case 0: synchronizePrimitive(id); break; 277 case 1: synchronizeDataSet(); break; 278 default: 279 // should not happen 280 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret)); 379 281 } 380 282 } … … 409 311 ); 410 312 switch(ret) { 411 case JOptionPane.CLOSED_OPTION: return;412 case 1: return;413 case 0: synchronizeDataSet(); break;414 default:415 // should not happen416 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret));313 case JOptionPane.CLOSED_OPTION: return; 314 case 1: return; 315 case 0: synchronizeDataSet(); break; 316 default: 317 // should not happen 318 throw new IllegalStateException(tr("unexpected return value. Got {0}", ret)); 417 319 } 418 320 } … … 608 510 e.printStackTrace(); 609 511 } 512 513 /** 514 * The asynchronous task to update a specific id 515 * 516 */ 517 class UpdatePrimitiveTask extends PleaseWaitRunnable { 518 519 private boolean uploadCancelled = false; 520 private boolean uploadFailed = false; 521 private Exception lastException = null; 522 private long id; 523 524 public UpdatePrimitiveTask(long id) { 525 super(tr("Updating primitive"),false /* don't ignore exceptions */); 526 } 527 528 @Override protected void realRun() throws SAXException, IOException { 529 try { 530 UpdateSelectionAction act = new UpdateSelectionAction(); 531 act.updatePrimitive(id); 532 } catch (Exception sxe) { 533 if (uploadCancelled) { 534 System.out.println("Ignoring exception caught because upload is cancelled. Exception is: " + sxe.toString()); 535 return; 536 } 537 uploadFailed = true; 538 lastException = sxe; 539 } 540 } 541 542 @Override protected void finish() { 543 if (uploadFailed) { 544 handleFailedUpload(lastException); 545 } 546 } 547 548 @Override protected void cancel() { 549 OsmApi.getOsmApi().cancel(); 550 uploadCancelled = true; 551 } 552 } 553 554 555 class UploadConfirmationHook implements UploadHook { 556 557 private JCheckBox cbUseAtomicUpload; 558 559 protected JPanel buildChangesetControlPanel() { 560 JPanel pnl = new JPanel(); 561 pnl.setLayout(new FlowLayout(FlowLayout.LEFT)); 562 pnl.add(cbUseAtomicUpload = new JCheckBox(tr("upload all changes in one request"))); 563 cbUseAtomicUpload.setToolTipText(tr("Enable to upload all changes in one request, disable to use one request per changed primitive")); 564 boolean useAtomicUpload = Main.pref.getBoolean("osm-server.atomic-upload", true); 565 cbUseAtomicUpload.setSelected(useAtomicUpload); 566 cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasChangesetSupport()); 567 return pnl; 568 } 569 570 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) { 571 572 JPanel p = new JPanel(new GridBagLayout()); 573 574 OsmPrimitivRenderer renderer = new OsmPrimitivRenderer(); 575 576 if (!add.isEmpty()) { 577 p.add(new JLabel(tr("Objects to add:")), GBC.eol()); 578 JList l = new JList(add.toArray()); 579 l.setCellRenderer(renderer); 580 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 581 p.add(new JScrollPane(l), GBC.eol().fill()); 582 } 583 584 if (!update.isEmpty()) { 585 p.add(new JLabel(tr("Objects to modify:")), GBC.eol()); 586 JList l = new JList(update.toArray()); 587 l.setCellRenderer(renderer); 588 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 589 p.add(new JScrollPane(l), GBC.eol().fill()); 590 } 591 592 if (!delete.isEmpty()) { 593 p.add(new JLabel(tr("Objects to delete:")), GBC.eol()); 594 JList l = new JList(delete.toArray()); 595 l.setCellRenderer(renderer); 596 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 597 p.add(new JScrollPane(l), GBC.eol().fill()); 598 } 599 600 p.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3)); 601 SuggestingJHistoryComboBox cmt = new SuggestingJHistoryComboBox(); 602 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>())); 603 cmt.setHistory(cmtHistory); 604 p.add(cmt, GBC.eol().fill(GBC.HORIZONTAL)); 605 //final JTextField cmt = new JTextField(lastCommitComment); 606 607 // configuration options for atomic upload 608 p.add(buildChangesetControlPanel(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 609 610 while(true) { 611 int result = new ExtendedDialog(Main.parent, 612 tr("Upload these changes?"), 613 p, 614 new String[] {tr("Upload Changes"), tr("Cancel")}, 615 new String[] {"upload.png", "cancel.png"}).getValue(); 616 617 // cancel pressed 618 if (result != 1) return false; 619 620 // don't allow empty commit message 621 if (cmt.getText().trim().length() < 3) { 622 continue; 623 } 624 625 // store the history of comments 626 cmt.addCurrentItemToHistory(); 627 Main.pref.putCollection(HISTORY_KEY, cmt.getHistory()); 628 Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected()); 629 630 break; 631 } 632 return true; 633 } 634 } 610 635 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r1868 r1870 24 24 import java.util.Properties; 25 25 26 import javax.swing.JPopupMenu;27 26 import javax.xml.parsers.SAXParserFactory; 28 27
Note:
See TracChangeset
for help on using the changeset viewer.