Ignore:
Timestamp:
2017-09-06T17:27:26+02:00 (2 years ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - see #13036 - remove more GUI stuff from DeleteCommand

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DeleteAction.java

    r12749 r12760  
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    55import static org.openstreetmap.josm.tools.I18n.tr;
     6import static org.openstreetmap.josm.tools.I18n.trn;
    67
     8import java.awt.GridBagLayout;
    79import java.awt.event.ActionEvent;
    810import java.awt.event.KeyEvent;
    911import java.util.Collection;
    1012
     13import javax.swing.JOptionPane;
     14import javax.swing.JPanel;
     15
     16import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.command.DeleteCommand.DeletionCallback;
     18import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1119import org.openstreetmap.josm.data.osm.OsmPrimitive;
     20import org.openstreetmap.josm.data.osm.Relation;
     21import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    1222import org.openstreetmap.josm.gui.MainApplication;
    1323import org.openstreetmap.josm.gui.MapFrame;
     24import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    1425import org.openstreetmap.josm.tools.Shortcut;
    1526
     
    1930 */
    2031public final class DeleteAction extends JosmAction {
     32
     33    /**
     34     * The default {@link DeletionCallback} for {@code DeleteCommand}.
     35     * @since 12760
     36     */
     37    public static final DeletionCallback defaultDeletionCallback = new DeletionCallback() {
     38        @Override
     39        public boolean checkAndConfirmOutlyingDelete(Collection<? extends OsmPrimitive> primitives,
     40                Collection<? extends OsmPrimitive> ignore) {
     41            return checkAndConfirmOutlyingDelete(primitives, ignore);
     42        }
     43
     44        @Override
     45        public boolean confirmRelationDeletion(Collection<Relation> relations) {
     46            return confirmRelationDeletion(relations);
     47        }
     48    };
    2149
    2250    /**
     
    7098                primitives, ignore);
    7199    }
     100
     101    /**
     102     * Confirm before deleting a relation, as it is a common newbie error.
     103     * @param relations relation to check for deletion
     104     * @return {@code true} if user confirms the deletion
     105     * @since 12760
     106     */
     107    public static boolean confirmRelationDeletion(Collection<Relation> relations) {
     108        JPanel msg = new JPanel(new GridBagLayout());
     109        msg.add(new JMultilineLabel("<html>" + trn(
     110                "You are about to delete {0} relation: {1}"
     111                + "<br/>"
     112                + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
     113                + "<br/>"
     114                + "Do you really want to delete?",
     115                "You are about to delete {0} relations: {1}"
     116                + "<br/>"
     117                + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
     118                + "<br/>"
     119                + "Do you really want to delete?",
     120                relations.size(), relations.size(), DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(relations, 20))
     121                + "</html>"));
     122        return ConditionalOptionPaneUtil.showConfirmationDialog(
     123                "delete_relations",
     124                Main.parent,
     125                msg,
     126                tr("Delete relation?"),
     127                JOptionPane.YES_NO_OPTION,
     128                JOptionPane.QUESTION_MESSAGE,
     129                JOptionPane.YES_OPTION);
     130    }
    72131}
Note: See TracChangeset for help on using the changeset viewer.