Changeset 4677 in josm for trunk/src/org


Ignore:
Timestamp:
2011-12-21T10:13:49+01:00 (13 years ago)
Author:
simon04
Message:

fix #3423 - Warn when deleting a large relation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r4458 r4677  
    22package org.openstreetmap.josm.command;
    33
     4import java.awt.GridBagLayout;
    45import java.awt.geom.Area;
    56import static org.openstreetmap.josm.tools.I18n.marktr;
     
    2122import javax.swing.JLabel;
    2223
     24import javax.swing.JOptionPane;
     25import javax.swing.JPanel;
     26import org.openstreetmap.josm.Main;
    2327import org.openstreetmap.josm.actions.SplitWayAction;
    2428import org.openstreetmap.josm.data.osm.Node;
     
    3034import org.openstreetmap.josm.data.osm.Way;
    3135import org.openstreetmap.josm.data.osm.WaySegment;
     36import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    3237import org.openstreetmap.josm.gui.DefaultNameFormatter;
    3338import org.openstreetmap.josm.gui.actionsupport.DeleteFromRelationConfirmationDialog;
     
    3540import org.openstreetmap.josm.tools.CheckParameterUtil;
    3641import org.openstreetmap.josm.tools.ImageProvider;
     42import org.openstreetmap.josm.tools.Utils;
    3743
    3844/**
     
    317323
    318324        Set<OsmPrimitive> primitivesToDelete = new HashSet<OsmPrimitive>(selection);
     325
     326        Collection<Relation> relationsToDelete = Utils.filteredCollection(primitivesToDelete, Relation.class);
     327        if(!relationsToDelete.isEmpty() && !silent && !confirmRelationDeletion(relationsToDelete)) {
     328            return null;
     329        }
     330
    319331        Collection<Way> waysToBeChanged = new HashSet<Way>();
    320332
     
    441453    }
    442454
     455    private static boolean confirmRelationDeletion(Collection<Relation> relations) {
     456        String relationString = "<ul>";
     457        for(Relation r:relations) {
     458            relationString += "<li>"+DefaultNameFormatter.getInstance().format(r) + "</li>";
     459        }
     460        relationString += "</ul>";
     461       
     462        JPanel msg = new JPanel(new GridBagLayout());
     463        msg.add(new JLabel("<html>" + trn(
     464                "You are about to delete {0} relation: {1}"
     465                + "<br/>"
     466                + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
     467                + "<br/>"
     468                + "Do you really want to delete?",
     469                "You are about to delete {0} relations: {1}"
     470                + "<br/>"
     471                + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
     472                + "<br/>"
     473                + "Do you really want to delete?",
     474                relations.size(), relations.size(), relationString) + "</html>"));
     475        boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     476                "delete_relations",
     477                Main.parent,
     478                msg,
     479                tr("Delete relation?"),
     480                JOptionPane.YES_NO_OPTION,
     481                JOptionPane.QUESTION_MESSAGE,
     482                JOptionPane.YES_OPTION);
     483        return answer;
     484    }
    443485}
Note: See TracChangeset for help on using the changeset viewer.