Changeset 5400 in josm for trunk/src/org


Ignore:
Timestamp:
2012-08-06T17:13:23+02:00 (12 years ago)
Author:
Don-vip
Message:

fix #7925 - tag conflict dialog shows wrong information in title

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java

    r5266 r5400  
    3636import org.openstreetmap.josm.command.Command;
    3737import org.openstreetmap.josm.corrector.UserCancelException;
    38 import org.openstreetmap.josm.data.osm.NameFormatter;
    3938import org.openstreetmap.josm.data.osm.Node;
    4039import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    4746import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
    4847import org.openstreetmap.josm.gui.help.HelpUtil;
     48import org.openstreetmap.josm.tools.CheckParameterUtil;
    4949import org.openstreetmap.josm.tools.ImageProvider;
    5050import org.openstreetmap.josm.tools.Utils;
     
    8282 * which reflect the conflict resolution decisions the user made in the dialog:
    8383 * see {@link #buildResolutionCommands()}
    84  *
    85  *
    8684 */
    8785public class CombinePrimitiveResolverDialog extends JDialog {
     
    127125
    128126    /**
    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.
    131128     *
    132129     * @param primitive the target primitive
     
    182179
    183180    protected JPanel buildButtonPanel() {
    184         JPanel pnl = new JPanel();
    185         pnl.setLayout(new FlowLayout(FlowLayout.CENTER));
     181        JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));
    186182
    187183        // -- apply button
     
    204200    }
    205201
    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);
    208208        build();
    209209    }
    210210
     211    /**
     212     * Replies the tag conflict resolver model.
     213     * @return The tag conflict resolver model.
     214     */
    211215    public TagConflictResolverModel getTagConflictResolverModel() {
    212216        return pnlTagConflictResolver.getModel();
    213217    }
    214218
     219    /**
     220     * Replies the relation membership conflict resolver model.
     221     * @return The relation membership conflict resolver model.
     222     */
    215223    public RelationMemberConflictResolverModel getRelationMemberConflictResolverModel() {
    216224        return pnlRelationMemberConflictResolver.getModel();
     
    234242    }
    235243
     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     */
    236248    public List<Command> buildResolutionCommands() {
    237249        List<Command> cmds = new LinkedList<Command>();
     
    287299    }
    288300
     301    /**
     302     * Prepares the default decisions for populated tag and relation membership conflicts.
     303     */
    289304    public void prepareDefaultDecisions() {
    290305        prepareDefaultTagDecisions();
     
    293308
    294309    protected JPanel buildEmptyConflictsPanel() {
    295         JPanel pnl = new JPanel();
    296         pnl.setLayout(new BorderLayout());
     310        JPanel pnl = new JPanel(new BorderLayout());
    297311        pnl.add(new JLabel(tr("No conflicts to resolve")));
    298312        return pnl;
     
    305319
    306320        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
    309322            spTagConflictTypes.setTopComponent(pnlTagConflictResolver);
    310323            spTagConflictTypes.setBottomComponent(pnlRelationMemberConflictResolver);
     
    312325        } else if (relModel.getNumDecisions() > 0) {
    313326            // relation conflicts only
    314             //
    315327            getContentPane().add(pnlRelationMemberConflictResolver, BorderLayout.CENTER);
    316328        } else if (tagModel.getNumDecisions() > 0) {
    317329            // tag conflicts only
    318             //
    319330            getContentPane().add(pnlTagConflictResolver, BorderLayout.CENTER);
    320331        } else {
     
    336347    }
    337348
     349    /**
     350     * Determines if this dialog has been cancelled.
     351     * @return true if this dialog has been cancelled, false otherwise.
     352     */
    338353    public boolean isCanceled() {
    339354        return canceled;
     
    436451    }
    437452
     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     */
    438467    public static List<Command> launchIfNecessary(
    439468            final TagCollection tagsOfPrimitives,
    440469            final Collection<? extends OsmPrimitive> primitives,
    441470            final Collection<? extends OsmPrimitive> targetPrimitives) throws UserCancelException {
     471       
     472        CheckParameterUtil.ensureParameterNotNull(tagsOfPrimitives, "tagsOfPrimitives");
     473        CheckParameterUtil.ensureParameterNotNull(primitives, "primitives");
     474        CheckParameterUtil.ensureParameterNotNull(targetPrimitives, "targetPrimitives");
    442475
    443476        final TagCollection completeWayTags = new TagCollection(tagsOfPrimitives);
     
    447480        TagConflictResolutionUtil.completeTagCollectionForEditing(tagsToEdit);
    448481
     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
    449497        final CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance();
    450498
    451499        dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues());
    452 
    453         final Set<Relation> parentRelations = OsmPrimitive.getParentRelations(primitives);
    454500        dialog.getRelationMemberConflictResolverModel().populate(parentRelations, primitives);
    455501        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
    516511        if (!completeWayTags.isApplicableToPrimitive() || !parentRelations.isEmpty()) {
    517512            dialog.setVisible(true);
     
    527522        return cmds;
    528523    }
     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    }
    529599}
Note: See TracChangeset for help on using the changeset viewer.