Changeset 5132 in josm for trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
- Timestamp:
- 2012-03-29T23:22:07+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
r4310 r5132 4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.tools.I18n.trn; 6 7 7 8 import java.awt.BorderLayout; … … 16 17 import java.beans.PropertyChangeEvent; 17 18 import java.beans.PropertyChangeListener; 19 import java.util.Collection; 18 20 import java.util.HashSet; 19 21 import java.util.LinkedList; … … 30 32 31 33 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.actions.ExpertToggleAction; 32 35 import org.openstreetmap.josm.command.ChangePropertyCommand; 33 36 import org.openstreetmap.josm.command.Command; 37 import org.openstreetmap.josm.corrector.UserCancelException; 38 import org.openstreetmap.josm.data.osm.NameFormatter; 34 39 import org.openstreetmap.josm.data.osm.Node; 35 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 37 42 import org.openstreetmap.josm.data.osm.TagCollection; 38 43 import org.openstreetmap.josm.data.osm.Way; 44 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 39 45 import org.openstreetmap.josm.gui.DefaultNameFormatter; 40 46 import org.openstreetmap.josm.gui.SideButton; … … 42 48 import org.openstreetmap.josm.gui.help.HelpUtil; 43 49 import org.openstreetmap.josm.tools.ImageProvider; 50 import org.openstreetmap.josm.tools.Utils; 51 import org.openstreetmap.josm.tools.Utils.Function; 44 52 import org.openstreetmap.josm.tools.WindowGeometry; 45 53 … … 47 55 * This dialog helps to resolve conflicts occurring when ways are combined or 48 56 * nodes are merged. 57 * 58 * Usage: {@link #launchIfNecessary} followed by {@link #buildResolutionCommands}. 59 * 60 * Prior to {@link #launchIfNecessary}, the following usage sequence was needed: 49 61 * 50 62 * There is a singleton instance of this dialog which can be retrieved using … … 82 94 * 83 95 * @return the unique instance of the dialog 96 * @deprecated use {@link #launchIfNecessary} instead. 84 97 */ 98 @Deprecated 85 99 public static CombinePrimitiveResolverDialog getInstance() { 86 100 if (instance == null) { … … 421 435 } 422 436 } 437 438 public static List<Command> launchIfNecessary( 439 final TagCollection tagsOfPrimitives, 440 final Collection<? extends OsmPrimitive> primitives, 441 final Collection<? extends OsmPrimitive> targetPrimitives) throws UserCancelException { 442 443 final TagCollection completeWayTags = new TagCollection(tagsOfPrimitives); 444 TagConflictResolutionUtil.combineTigerTags(completeWayTags); 445 TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing(completeWayTags, primitives); 446 final TagCollection tagsToEdit = new TagCollection(completeWayTags); 447 TagConflictResolutionUtil.completeTagCollectionForEditing(tagsToEdit); 448 449 final CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance(); 450 451 dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues()); 452 453 final Set<Relation> parentRelations = OsmPrimitive.getParentRelations(primitives); 454 dialog.getRelationMemberConflictResolverModel().populate(parentRelations, primitives); 455 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 516 if (!completeWayTags.isApplicableToPrimitive() || !parentRelations.isEmpty()) { 517 dialog.setVisible(true); 518 if (dialog.isCanceled()) { 519 throw new UserCancelException(); 520 } 521 } 522 List<Command> cmds = new LinkedList<Command>(); 523 for (OsmPrimitive i : targetPrimitives) { 524 dialog.setTargetPrimitive(i); 525 cmds.addAll(dialog.buildResolutionCommands()); 526 } 527 return cmds; 528 } 423 529 }
Note:
See TracChangeset
for help on using the changeset viewer.