Changeset 12760 in josm for trunk/src/org/openstreetmap


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

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

Location:
trunk/src/org/openstreetmap/josm
Files:
3 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}
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r12749 r12760  
    66import static org.openstreetmap.josm.tools.I18n.trn;
    77
    8 import java.awt.GridBagLayout;
    98import java.util.ArrayList;
    109import java.util.Arrays;
     
    2221
    2322import javax.swing.Icon;
    24 import javax.swing.JOptionPane;
    25 import javax.swing.JPanel;
    26 
    27 import org.openstreetmap.josm.Main;
     23
    2824import org.openstreetmap.josm.actions.SplitWayAction;
    2925import org.openstreetmap.josm.actions.SplitWayAction.SplitWayResult;
     
    3834import org.openstreetmap.josm.data.osm.Way;
    3935import org.openstreetmap.josm.data.osm.WaySegment;
    40 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    4136import org.openstreetmap.josm.gui.dialogs.DeleteFromRelationConfirmationDialog;
    4237import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    43 import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    4438import org.openstreetmap.josm.tools.CheckParameterUtil;
    4539import org.openstreetmap.josm.tools.ImageProvider;
     
    8377     * @since 12749
    8478     */
    85     @FunctionalInterface
    8679    public interface DeletionCallback {
    8780        /**
     
    9386         */
    9487        boolean checkAndConfirmOutlyingDelete(Collection<? extends OsmPrimitive> primitives, Collection<? extends OsmPrimitive> ignore);
     88
     89        /**
     90         * Confirm before deleting a relation, as it is a common newbie error.
     91         * @param relations relation to check for deletion
     92         * @return {@code true} if user confirms the deletion
     93         * @since 12760
     94         */
     95        boolean confirmRelationDeletion(Collection<Relation> relations);
    9596    }
    9697
     
    545546
    546547        Collection<Relation> relationsToDelete = Utils.filteredCollection(primitivesToDelete, Relation.class);
    547         if (!relationsToDelete.isEmpty() && !silent && !confirmRelationDeletion(relationsToDelete))
     548        if (!relationsToDelete.isEmpty() && !silent && !callback.confirmRelationDeletion(relationsToDelete))
    548549            return null;
    549550
     
    658659    }
    659660
    660     private static boolean confirmRelationDeletion(Collection<Relation> relations) {
    661         JPanel msg = new JPanel(new GridBagLayout());
    662         msg.add(new JMultilineLabel("<html>" + trn(
    663                 "You are about to delete {0} relation: {1}"
    664                 + "<br/>"
    665                 + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
    666                 + "<br/>"
    667                 + "Do you really want to delete?",
    668                 "You are about to delete {0} relations: {1}"
    669                 + "<br/>"
    670                 + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
    671                 + "<br/>"
    672                 + "Do you really want to delete?",
    673                 relations.size(), relations.size(), DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(relations, 20))
    674                 + "</html>"));
    675         return ConditionalOptionPaneUtil.showConfirmationDialog(
    676                 "delete_relations",
    677                 Main.parent,
    678                 msg,
    679                 tr("Delete relation?"),
    680                 JOptionPane.YES_NO_OPTION,
    681                 JOptionPane.QUESTION_MESSAGE,
    682                 JOptionPane.YES_OPTION);
    683     }
    684 
    685661    @Override
    686662    public int hashCode() {
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12755 r12760  
    968968
    969969    static void setupCallbacks() {
    970         DeleteCommand.setDeletionCallback(DeleteAction::checkAndConfirmOutlyingDelete);
     970        DeleteCommand.setDeletionCallback(DeleteAction.defaultDeletionCallback);
    971971    }
    972972
Note: See TracChangeset for help on using the changeset viewer.