source: josm/trunk/src/org/openstreetmap/josm/actions/DeleteAction.java@ 14628

Last change on this file since 14628 was 14397, checked in by Don-vip, 5 years ago

fix #16935 - simplify/cleanup help topics of ToggleDialog/ToggleDialogAction

  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6import static org.openstreetmap.josm.tools.I18n.trn;
7
8import java.awt.GridBagLayout;
9import java.awt.event.ActionEvent;
10import java.awt.event.KeyEvent;
11import java.util.Collection;
12
13import javax.swing.JOptionPane;
14import javax.swing.JPanel;
15
16import org.openstreetmap.josm.command.DeleteCommand.DeletionCallback;
17import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
18import org.openstreetmap.josm.data.osm.OsmPrimitive;
19import org.openstreetmap.josm.data.osm.Relation;
20import org.openstreetmap.josm.data.osm.RelationToChildReference;
21import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
22import org.openstreetmap.josm.gui.MainApplication;
23import org.openstreetmap.josm.gui.MapFrame;
24import org.openstreetmap.josm.gui.dialogs.DeleteFromRelationConfirmationDialog;
25import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
26import org.openstreetmap.josm.tools.Shortcut;
27
28/**
29 * Action that deletes selected objects.
30 * @since 770
31 */
32public final class DeleteAction extends JosmAction {
33
34 /**
35 * The default {@link DeletionCallback} for {@code DeleteCommand}.
36 * @since 12760
37 */
38 public static final DeletionCallback defaultDeletionCallback = new DeletionCallback() {
39 @Override
40 public boolean checkAndConfirmOutlyingDelete(Collection<? extends OsmPrimitive> primitives,
41 Collection<? extends OsmPrimitive> ignore) {
42 return DeleteAction.checkAndConfirmOutlyingDelete(primitives, ignore);
43 }
44
45 @Override
46 public boolean confirmRelationDeletion(Collection<Relation> relations) {
47 return DeleteAction.confirmRelationDeletion(relations);
48 }
49
50 @Override
51 public boolean confirmDeletionFromRelation(Collection<RelationToChildReference> references) {
52 DeleteFromRelationConfirmationDialog dialog = DeleteFromRelationConfirmationDialog.getInstance();
53 dialog.getModel().populate(references);
54 dialog.setVisible(true);
55 return !dialog.isCanceled();
56 }
57 };
58
59 /**
60 * Constructs a new {@code DeleteAction}.
61 */
62 public DeleteAction() {
63 super(tr("Delete"), "dialogs/delete", tr("Delete selected objects."),
64 Shortcut.registerShortcut("system:delete", tr("Edit: {0}", tr("Delete")), KeyEvent.VK_DELETE, Shortcut.DIRECT), true);
65 setHelpId(ht("/Action/Delete"));
66 }
67
68 @Override
69 public void actionPerformed(ActionEvent e) {
70 MapFrame map = MainApplication.getMap();
71 if (!isEnabled() || !map.mapView.isActiveLayerVisible())
72 return;
73 map.mapModeDelete.doActionPerformed(e);
74 }
75
76 @Override
77 protected void updateEnabledState() {
78 updateEnabledStateOnCurrentSelection();
79 }
80
81 @Override
82 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
83 updateEnabledStateOnModifiableSelection(selection);
84 }
85
86 /**
87 * Check whether user is about to delete data outside of the download area.
88 * Request confirmation if he is.
89 * @param primitives the primitives to operate on
90 * @param ignore {@code null} or a primitive to be ignored
91 * @return true, if operating on outlying primitives is OK; false, otherwise
92 * @since 12749 (moved from DeleteCommand)
93 */
94 public static boolean checkAndConfirmOutlyingDelete(Collection<? extends OsmPrimitive> primitives,
95 Collection<? extends OsmPrimitive> ignore) {
96 return checkAndConfirmOutlyingOperation("delete",
97 tr("Delete confirmation"),
98 tr("You are about to delete nodes outside of the area you have downloaded."
99 + "<br>"
100 + "This can cause problems because other objects (that you do not see) might use them."
101 + "<br>"
102 + "Do you really want to delete?"),
103 tr("You are about to delete incomplete objects."
104 + "<br>"
105 + "This will cause problems because you don''t see the real object."
106 + "<br>" + "Do you really want to delete?"),
107 primitives, ignore);
108 }
109
110 /**
111 * Confirm before deleting a relation, as it is a common newbie error.
112 * @param relations relation to check for deletion
113 * @return {@code true} if user confirms the deletion
114 * @since 12760
115 */
116 public static boolean confirmRelationDeletion(Collection<Relation> relations) {
117 JPanel msg = new JPanel(new GridBagLayout());
118 msg.add(new JMultilineLabel("<html>" + trn(
119 "You are about to delete {0} relation: {1}"
120 + "<br/>"
121 + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
122 + "<br/>"
123 + "Do you really want to delete?",
124 "You are about to delete {0} relations: {1}"
125 + "<br/>"
126 + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
127 + "<br/>"
128 + "Do you really want to delete?",
129 relations.size(), relations.size(), DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(relations, 20))
130 + "</html>"));
131 return ConditionalOptionPaneUtil.showConfirmationDialog(
132 "delete_relations",
133 MainApplication.getMainFrame(),
134 msg,
135 tr("Delete relation?"),
136 JOptionPane.YES_NO_OPTION,
137 JOptionPane.QUESTION_MESSAGE,
138 JOptionPane.YES_OPTION);
139 }
140}
Note: See TracBrowser for help on using the repository browser.