source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java@ 14027

Last change on this file since 14027 was 14027, checked in by michael2402, 6 years ago

See #16388: New mechanism for plugins to register relation editor actions.

File size: 4.0 KB
RevLine 
[9665]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7
8import javax.swing.JOptionPane;
9import javax.swing.RootPaneContainer;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.osm.Relation;
13import org.openstreetmap.josm.gui.HelpAwareOptionPane;
14import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
[12846]15import org.openstreetmap.josm.spi.preferences.Config;
[9665]16import org.openstreetmap.josm.tools.ImageProvider;
[10791]17import org.openstreetmap.josm.tools.InputMapUtils;
[9665]18
19/**
20 * Cancel the updates and close the dialog
21 * @since 9496
22 */
23public class CancelAction extends SavingAction {
[14027]24 private static final long serialVersionUID = 1L;
[9665]25
26 /**
27 * Constructs a new {@code CancelAction}.
28 * @param memberTable member table
29 * @param memberTableModel member table model
30 * @param tagModel tag editor model
31 * @param layer OSM data layer
32 * @param editor relation editor
33 * @param tfRole role text field
34 */
[14027]35 public CancelAction(IRelationEditorActionAccess editorAccess) {
36 super(editorAccess);
[9665]37 putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog"));
[10424]38 new ImageProvider("cancel").getResource().attachImageIcon(this);
[9665]39 putValue(NAME, tr("Cancel"));
40
[14027]41 if (getEditor() instanceof RootPaneContainer) {
42 InputMapUtils.addEscapeAction(((RootPaneContainer) getEditor()).getRootPane(), this);
[9665]43 }
44 setEnabled(true);
45 }
46
47 @Override
48 public void actionPerformed(ActionEvent e) {
[14027]49 getMemberTable().stopHighlighting();
50 Relation snapshot = getEditor().getRelationSnapshot();
51 if ((!getMemberTableModel().hasSameMembersAs(snapshot) || getTagModel().isDirty())
52 && !(snapshot == null && getTagModel().getTags().isEmpty())) {
[9665]53 //give the user a chance to save the changes
54 int ret = confirmClosingByCancel();
55 if (ret == 0) { //Yes, save the changes
56 //copied from OKAction.run()
[12846]57 Config.getPref().put("relation.editor.generic.lastrole", tfRole.getText());
[9665]58 if (!applyChanges())
59 return;
60 } else if (ret == 2 || ret == JOptionPane.CLOSED_OPTION) //Cancel, continue editing
61 return;
62 //in case of "No, discard", there is no extra action to be performed here.
63 }
64 hideEditor();
65 }
66
67 protected int confirmClosingByCancel() {
68 ButtonSpec[] options = new ButtonSpec[] {
69 new ButtonSpec(
70 tr("Yes, save the changes and close"),
[13842]71 new ImageProvider("ok"),
[9665]72 tr("Click to save the changes and close this relation editor"),
73 null /* no specific help topic */
74 ),
75 new ButtonSpec(
76 tr("No, discard the changes and close"),
[13842]77 new ImageProvider("cancel"),
[9665]78 tr("Click to discard the changes and close this relation editor"),
79 null /* no specific help topic */
80 ),
81 new ButtonSpec(
82 tr("Cancel, continue editing"),
[13842]83 new ImageProvider("cancel"),
[9665]84 tr("Click to return to the relation editor and to resume relation editing"),
85 null /* no specific help topic */
86 )
87 };
88
89 return HelpAwareOptionPane.showOptionDialog(
90 Main.parent,
91 tr("<html>The relation has been changed.<br><br>Do you want to save your changes?</html>"),
92 tr("Unsaved changes"),
93 JOptionPane.WARNING_MESSAGE,
94 null,
95 options,
96 options[0], // OK is default,
97 "/Dialog/RelationEditor#DiscardChanges"
98 );
99 }
100}
Note: See TracBrowser for help on using the repository browser.