Changeset 5400 in josm for trunk/src/org
- Timestamp:
- 2012-08-06T17:13:23+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
r5266 r5400 36 36 import org.openstreetmap.josm.command.Command; 37 37 import org.openstreetmap.josm.corrector.UserCancelException; 38 import org.openstreetmap.josm.data.osm.NameFormatter;39 38 import org.openstreetmap.josm.data.osm.Node; 40 39 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 47 46 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 48 47 import org.openstreetmap.josm.gui.help.HelpUtil; 48 import org.openstreetmap.josm.tools.CheckParameterUtil; 49 49 import org.openstreetmap.josm.tools.ImageProvider; 50 50 import org.openstreetmap.josm.tools.Utils; … … 82 82 * which reflect the conflict resolution decisions the user made in the dialog: 83 83 * see {@link #buildResolutionCommands()} 84 *85 *86 84 */ 87 85 public class CombinePrimitiveResolverDialog extends JDialog { … … 127 125 128 126 /** 129 * Sets the primitive the collection of primitives is merged or combined 130 * to. 127 * Sets the primitive the collection of primitives is merged or combined to. 131 128 * 132 129 * @param primitive the target primitive … … 182 179 183 180 protected JPanel buildButtonPanel() { 184 JPanel pnl = new JPanel(); 185 pnl.setLayout(new FlowLayout(FlowLayout.CENTER)); 181 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 186 182 187 183 // -- apply button … … 204 200 } 205 201 206 public CombinePrimitiveResolverDialog(Component owner) { 207 super(JOptionPane.getFrameForComponent(owner), ModalityType.DOCUMENT_MODAL); 202 /** 203 * Constructs a new {@code CombinePrimitiveResolverDialog}. 204 * @param parent The parent component in which this dialog will be displayed. 205 */ 206 public CombinePrimitiveResolverDialog(Component parent) { 207 super(JOptionPane.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL); 208 208 build(); 209 209 } 210 210 211 /** 212 * Replies the tag conflict resolver model. 213 * @return The tag conflict resolver model. 214 */ 211 215 public TagConflictResolverModel getTagConflictResolverModel() { 212 216 return pnlTagConflictResolver.getModel(); 213 217 } 214 218 219 /** 220 * Replies the relation membership conflict resolver model. 221 * @return The relation membership conflict resolver model. 222 */ 215 223 public RelationMemberConflictResolverModel getRelationMemberConflictResolverModel() { 216 224 return pnlRelationMemberConflictResolver.getModel(); … … 234 242 } 235 243 244 /** 245 * Replies the list of {@link Command commands} needed to apply resolution choices. 246 * @return The list of {@link Command commands} needed to apply resolution choices. 247 */ 236 248 public List<Command> buildResolutionCommands() { 237 249 List<Command> cmds = new LinkedList<Command>(); … … 287 299 } 288 300 301 /** 302 * Prepares the default decisions for populated tag and relation membership conflicts. 303 */ 289 304 public void prepareDefaultDecisions() { 290 305 prepareDefaultTagDecisions(); … … 293 308 294 309 protected JPanel buildEmptyConflictsPanel() { 295 JPanel pnl = new JPanel(); 296 pnl.setLayout(new BorderLayout()); 310 JPanel pnl = new JPanel(new BorderLayout()); 297 311 pnl.add(new JLabel(tr("No conflicts to resolve"))); 298 312 return pnl; … … 305 319 306 320 if (relModel.getNumDecisions() > 0 && tagModel.getNumDecisions() > 0) { 307 // display both, the dialog for resolving relation conflicts and for resolving 308 // tag conflicts 321 // display both, the dialog for resolving relation conflicts and for resolving tag conflicts 309 322 spTagConflictTypes.setTopComponent(pnlTagConflictResolver); 310 323 spTagConflictTypes.setBottomComponent(pnlRelationMemberConflictResolver); … … 312 325 } else if (relModel.getNumDecisions() > 0) { 313 326 // relation conflicts only 314 //315 327 getContentPane().add(pnlRelationMemberConflictResolver, BorderLayout.CENTER); 316 328 } else if (tagModel.getNumDecisions() > 0) { 317 329 // tag conflicts only 318 //319 330 getContentPane().add(pnlTagConflictResolver, BorderLayout.CENTER); 320 331 } else { … … 336 347 } 337 348 349 /** 350 * Determines if this dialog has been cancelled. 351 * @return true if this dialog has been cancelled, false otherwise. 352 */ 338 353 public boolean isCanceled() { 339 354 return canceled; … … 436 451 } 437 452 453 /** 454 * Replies the list of {@link Command commands} needed to resolve specified conflicts, 455 * by displaying if necessary a {@link CombinePrimitiveResolverDialog} to the user. 456 * This dialog will allow the user to choose conflict resolution actions. 457 * 458 * Non-expert users are informed first of the meaning of these operations, allowing them to cancel. 459 * 460 * @param tagsOfPrimitives The tag collection of the primitives to be combined. 461 * Should generally be equal to {@code TagCollection.unionOfAllPrimitives(primitives)} 462 * @param primitives The primitives to be combined 463 * @param targetPrimitives The primitives the collection of primitives are merged or combined to. 464 * @return The list of {@link Command commands} needed to apply resolution actions. 465 * @throws UserCancelException If the user cancelled a dialog. 466 */ 438 467 public static List<Command> launchIfNecessary( 439 468 final TagCollection tagsOfPrimitives, 440 469 final Collection<? extends OsmPrimitive> primitives, 441 470 final Collection<? extends OsmPrimitive> targetPrimitives) throws UserCancelException { 471 472 CheckParameterUtil.ensureParameterNotNull(tagsOfPrimitives, "tagsOfPrimitives"); 473 CheckParameterUtil.ensureParameterNotNull(primitives, "primitives"); 474 CheckParameterUtil.ensureParameterNotNull(targetPrimitives, "targetPrimitives"); 442 475 443 476 final TagCollection completeWayTags = new TagCollection(tagsOfPrimitives); … … 447 480 TagConflictResolutionUtil.completeTagCollectionForEditing(tagsToEdit); 448 481 482 final Set<Relation> parentRelations = OsmPrimitive.getParentRelations(primitives); 483 484 // Show information dialogs about conflicts to non-experts 485 if (!ExpertToggleAction.isExpert()) { 486 // Tag conflicts 487 if (!completeWayTags.isApplicableToPrimitive()) { 488 informAboutTagConflicts(primitives, completeWayTags); 489 } 490 // Relation membership conflicts 491 if (!parentRelations.isEmpty()) { 492 informAboutRelationMembershipConflicts(primitives, parentRelations); 493 } 494 } 495 496 // Build conflict resolution dialog 449 497 final CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance(); 450 498 451 499 dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues()); 452 453 final Set<Relation> parentRelations = OsmPrimitive.getParentRelations(primitives);454 500 dialog.getRelationMemberConflictResolverModel().populate(parentRelations, primitives); 455 501 dialog.prepareDefaultDecisions(); 456 457 // show information dialog to non-experts 458 if (!completeWayTags.isApplicableToPrimitive() && !ExpertToggleAction.isExpert()) { 459 String conflicts = Utils.joinAsHtmlUnorderedList(Utils.transform(completeWayTags.getKeysWithMultipleValues(), new Function<String, String>() { 460 461 @Override 462 public String apply(String key) { 463 return tr("{0} ({1})", key, Utils.join(tr(", "), Utils.transform(completeWayTags.getValues(key), new Function<String, String>() { 464 465 @Override 466 public String apply(String x) { 467 return x == null || x.isEmpty() ? tr("<i>missing</i>") : x; 468 } 469 }))); 470 } 471 })); 472 String msg = tr("You are about to combine {0} objects, " 473 + "but the following tags are used conflictingly:<br/>{1}" 474 + "If these objects are combined, the resulting object may have unwanted tags.<br/>" 475 + "If you want to continue, you are shown a dialog to fix the conflicting tags.<br/><br/>" 476 + "Do you want to continue?", 477 primitives.size(), conflicts); 478 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 479 "combine_tags", 480 Main.parent, 481 "<html>" + msg + "</html>", 482 tr("Combine confirmation"), 483 JOptionPane.YES_NO_OPTION, 484 JOptionPane.QUESTION_MESSAGE, 485 JOptionPane.YES_OPTION)) { 486 throw new UserCancelException(); 487 } 488 } 489 490 if (!parentRelations.isEmpty() && !ExpertToggleAction.isExpert()) { 491 String msg = trn("You are about to combine {1} objects, " 492 + "which are part of {0} relation:<br/>{2}" 493 + "Combining these objects may break this relation. If you are unsure, please cancel this operation.<br/>" 494 + "If you want to continue, you are shown a dialog to decide how to adapt the relation.<br/><br/>" 495 + "Do you want to continue?", 496 "You are about to combine {1} objects, " 497 + "which are part of {0} relations:<br/>{2}" 498 + "Combining these objects may break these relations. If you are unsure, please cancel this operation.<br/>" 499 + "If you want to continue, you are shown a dialog to decide how to adapt the relations.<br/><br/>" 500 + "Do you want to continue?", 501 parentRelations.size(), parentRelations.size(), primitives.size(), 502 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(parentRelations)); 503 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 504 "combine_tags", 505 Main.parent, 506 "<html>" + msg + "</html>", 507 tr("Combine confirmation"), 508 JOptionPane.YES_NO_OPTION, 509 JOptionPane.QUESTION_MESSAGE, 510 JOptionPane.YES_OPTION)) { 511 throw new UserCancelException(); 512 } 513 } 514 515 // resolve tag conflicts if necessary 502 503 // Ensure a proper title is displayed instead of a previous target (fix #7925) 504 if (targetPrimitives.size() == 1) { 505 dialog.setTargetPrimitive(targetPrimitives.iterator().next()); 506 } else { 507 dialog.setTargetPrimitive(null); 508 } 509 510 // Resolve tag conflicts if necessary 516 511 if (!completeWayTags.isApplicableToPrimitive() || !parentRelations.isEmpty()) { 517 512 dialog.setVisible(true); … … 527 522 return cmds; 528 523 } 524 525 /** 526 * Inform a non-expert user about what relation membership conflict resolution means. 527 * @param primitives The primitives to be combined 528 * @param parentRelations The parent relations of the primitives 529 * @throws UserCancelException If the user cancels the dialog. 530 */ 531 protected static void informAboutRelationMembershipConflicts( 532 final Collection<? extends OsmPrimitive> primitives, 533 final Set<Relation> parentRelations) throws UserCancelException { 534 String msg = trn("You are about to combine {1} objects, " 535 + "which are part of {0} relation:<br/>{2}" 536 + "Combining these objects may break this relation. If you are unsure, please cancel this operation.<br/>" 537 + "If you want to continue, you are shown a dialog to decide how to adapt the relation.<br/><br/>" 538 + "Do you want to continue?", 539 "You are about to combine {1} objects, " 540 + "which are part of {0} relations:<br/>{2}" 541 + "Combining these objects may break these relations. If you are unsure, please cancel this operation.<br/>" 542 + "If you want to continue, you are shown a dialog to decide how to adapt the relations.<br/><br/>" 543 + "Do you want to continue?", 544 parentRelations.size(), parentRelations.size(), primitives.size(), 545 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(parentRelations)); 546 547 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 548 "combine_tags", 549 Main.parent, 550 "<html>" + msg + "</html>", 551 tr("Combine confirmation"), 552 JOptionPane.YES_NO_OPTION, 553 JOptionPane.QUESTION_MESSAGE, 554 JOptionPane.YES_OPTION)) { 555 throw new UserCancelException(); 556 } 557 } 558 559 /** 560 * Inform a non-expert user about what tag conflict resolution means. 561 * @param primitives The primitives to be combined 562 * @param normalizedTags The normalized tag collection of the primitives to be combined 563 * @throws UserCancelException If the user cancels the dialog. 564 */ 565 protected static void informAboutTagConflicts( 566 final Collection<? extends OsmPrimitive> primitives, 567 final TagCollection normalizedTags) throws UserCancelException { 568 String conflicts = Utils.joinAsHtmlUnorderedList(Utils.transform(normalizedTags.getKeysWithMultipleValues(), new Function<String, String>() { 569 570 @Override 571 public String apply(String key) { 572 return tr("{0} ({1})", key, Utils.join(tr(", "), Utils.transform(normalizedTags.getValues(key), new Function<String, String>() { 573 574 @Override 575 public String apply(String x) { 576 return x == null || x.isEmpty() ? tr("<i>missing</i>") : x; 577 } 578 }))); 579 } 580 })); 581 String msg = tr("You are about to combine {0} objects, " 582 + "but the following tags are used conflictingly:<br/>{1}" 583 + "If these objects are combined, the resulting object may have unwanted tags.<br/>" 584 + "If you want to continue, you are shown a dialog to fix the conflicting tags.<br/><br/>" 585 + "Do you want to continue?", 586 primitives.size(), conflicts); 587 588 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 589 "combine_tags", 590 Main.parent, 591 "<html>" + msg + "</html>", 592 tr("Combine confirmation"), 593 JOptionPane.YES_NO_OPTION, 594 JOptionPane.QUESTION_MESSAGE, 595 JOptionPane.YES_OPTION)) { 596 throw new UserCancelException(); 597 } 598 } 529 599 }
Note:
See TracChangeset
for help on using the changeset viewer.