Changeset 15010 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-04-21T17:55:22+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r14977 r15010 17 17 import java.lang.Character.UnicodeBlock; 18 18 import java.util.ArrayList; 19 import java.util.Arrays; 19 20 import java.util.Collection; 20 21 import java.util.Collections; … … 26 27 import java.util.Optional; 27 28 import java.util.concurrent.TimeUnit; 29 import java.util.stream.Collectors; 28 30 29 31 import javax.swing.AbstractAction; … … 490 492 } 491 493 494 /** 495 * Displays a warning message indicating that the upload comment is rejected. 496 * @param details details explaining why 497 * @return {@code true} 498 */ 499 protected boolean warnRejectedUploadComment(String details) { 500 return warnRejectedUploadTag( 501 tr("Please revise upload comment"), 502 tr("Your upload comment is <i>rejected</i>.") + "<br />" + details 503 ); 504 } 505 506 /** 507 * Displays a warning message indicating that the changeset source is rejected. 508 * @param details details explaining why 509 * @return {@code true} 510 */ 511 protected boolean warnRejectedUploadSource(String details) { 512 return warnRejectedUploadTag( 513 tr("Please revise changeset source"), 514 tr("Your changeset source is <i>rejected</i>.") + "<br />" + details 515 ); 516 } 517 518 /** 519 * Warn about an upload tag with the possibility of resuming the upload. 520 * @param title dialog title 521 * @param message dialog message 522 * @param togglePref preference entry to offer the user a "Do not show again" checkbox for the dialog 523 * @return {@code true} if the user wants to revise the upload tag 524 */ 492 525 protected boolean warnUploadTag(final String title, final String message, final String togglePref) { 493 String[] buttonTexts = new String[] {tr("Revise"), tr("Cancel"), tr("Continue as is")}; 494 Icon[] buttonIcons = new Icon[] { 526 return warnUploadTag(title, message, togglePref, true); 527 } 528 529 /** 530 * Warn about an upload tag without the possibility of resuming the upload. 531 * @param title dialog title 532 * @param message dialog message 533 * @return {@code true} 534 */ 535 protected boolean warnRejectedUploadTag(final String title, final String message) { 536 return warnUploadTag(title, message, null, false); 537 } 538 539 private boolean warnUploadTag(final String title, final String message, final String togglePref, boolean allowContinue) { 540 List<String> buttonTexts = new ArrayList<>(Arrays.asList(tr("Revise"), tr("Cancel"))); 541 List<Icon> buttonIcons = new ArrayList<>(Arrays.asList( 495 542 new ImageProvider("ok").setMaxSize(ImageSizes.LARGEICON).get(), 496 new ImageProvider("cancel").setMaxSize(ImageSizes.LARGEICON).get(), 497 new ImageProvider("upload").setMaxSize(ImageSizes.LARGEICON).addOverlay( 498 new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0)).get()}; 499 String[] tooltips = new String[] { 543 new ImageProvider("cancel").setMaxSize(ImageSizes.LARGEICON).get())); 544 List<String> tooltips = new ArrayList<>(Arrays.asList( 500 545 tr("Return to the previous dialog to enter a more descriptive comment"), 501 tr("Cancel and return to the previous dialog"), 502 tr("Ignore this hint and upload anyway")}; 503 504 ExtendedDialog dlg = new ExtendedDialog((Component) dialog, title, buttonTexts) { 546 tr("Cancel and return to the previous dialog"))); 547 if (allowContinue) { 548 buttonTexts.add(tr("Continue as is")); 549 buttonIcons.add(new ImageProvider("upload").setMaxSize(ImageSizes.LARGEICON).addOverlay( 550 new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0)).get()); 551 tooltips.add(tr("Ignore this hint and upload anyway")); 552 } 553 554 ExtendedDialog dlg = new ExtendedDialog((Component) dialog, title, buttonTexts.toArray(new String[] {})) { 505 555 @Override 506 556 public void setupDialog() { … … 510 560 }; 511 561 dlg.setContent("<html>" + message + "</html>"); 512 dlg.setButtonIcons(buttonIcons); 513 dlg.setToolTipTexts(tooltips); 562 dlg.setButtonIcons(buttonIcons.toArray(new Icon[] {})); 563 dlg.setToolTipTexts(tooltips.toArray(new String[] {})); 514 564 dlg.setIcon(JOptionPane.WARNING_MESSAGE); 515 dlg.toggleEnable(togglePref); 565 if (allowContinue) { 566 dlg.toggleEnable(togglePref); 567 } 516 568 dlg.setCancelButton(1, 2); 517 569 return dlg.showDialog().getValue() != 3; … … 542 594 } 543 595 596 static String validateUploadTag(String uploadValue, String preferencePrefix) { 597 // Check mandatory terms 598 List<String> missingTerms = Config.getPref().getList(preferencePrefix+".mandatory-terms") 599 .stream().filter(x -> !uploadValue.contains(x)).collect(Collectors.toList()); 600 if (!missingTerms.isEmpty()) { 601 return tr("The following required terms are missing: {0}", missingTerms); 602 } 603 // Check forbidden terms 604 List<String> forbiddenTerms = Config.getPref().getList(preferencePrefix+".forbidden-terms") 605 .stream().filter(uploadValue::contains).collect(Collectors.toList()); 606 if (!forbiddenTerms.isEmpty()) { 607 return tr("The following forbidden terms have been found: {0}", forbiddenTerms); 608 } 609 return null; 610 } 611 544 612 @Override 545 613 public void actionPerformed(ActionEvent e) { … … 547 615 dialog.forceUpdateActiveField(); 548 616 549 if (isUploadCommentTooShort(dialog.getUploadComment()) && warnUploadComment()) { 550 // abort for missing comment 617 final String uploadComment = dialog.getUploadComment(); 618 final String uploadCommentRejection = validateUploadTag(uploadComment, "upload.comment"); 619 if ((isUploadCommentTooShort(uploadComment) && warnUploadComment()) || 620 (uploadCommentRejection != null && warnRejectedUploadComment(uploadCommentRejection))) { 621 // abort for missing or rejected comment 551 622 dialog.handleMissingComment(); 552 623 return; 553 624 } 554 if (dialog.getUploadSource().trim().isEmpty() && warnUploadSource()) { 555 // abort for missing changeset source 625 final String uploadSource = dialog.getUploadSource(); 626 final String uploadSourceRejection = validateUploadTag(uploadSource, "upload.source"); 627 if ((Utils.isStripEmpty(uploadSource) && warnUploadSource()) || 628 (uploadSourceRejection != null && warnRejectedUploadSource(uploadSourceRejection))) { 629 // abort for missing or rejected changeset source 556 630 dialog.handleMissingSource(); 557 631 return; … … 562 636 List<String> emptyChangesetTags = new ArrayList<>(); 563 637 for (final Entry<String, String> i : dialog.getTags(true).entrySet()) { 564 final boolean isKeyEmpty = i.getKey() == null || i.getKey().trim().isEmpty();565 final boolean isValueEmpty = i.getValue() == null || i.getValue().trim().isEmpty();638 final boolean isKeyEmpty = Utils.isStripEmpty(i.getKey()); 639 final boolean isValueEmpty = Utils.isStripEmpty(i.getValue()); 566 640 final boolean ignoreKey = "comment".equals(i.getKey()) || "source".equals(i.getKey()); 567 641 if ((isKeyEmpty ^ isValueEmpty) && !ignoreKey) { … … 648 722 if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) { 649 723 Changeset cs = (Changeset) evt.getNewValue(); 650 setChangesetTags(dataSet, cs == null); // keep comment/source of first tab for new changesets 724 setChangesetTags(dataSet, cs == null); // keep comment/source of first tab for new changesets 651 725 if (cs == null) { 652 726 tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
Note:
See TracChangeset
for help on using the changeset viewer.
