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

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

See #16388: Fix Checkstyle / Test issues.

File size: 3.8 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 {
[14029]24 private static final long serialVersionUID = 1L;
[9665]25
26 /**
27 * Constructs a new {@code CancelAction}.
[14030]28 * @param editorAccess An interface to access the relation editor contents.
[9665]29 */
[14027]30 public CancelAction(IRelationEditorActionAccess editorAccess) {
31 super(editorAccess);
[9665]32 putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog"));
[10424]33 new ImageProvider("cancel").getResource().attachImageIcon(this);
[9665]34 putValue(NAME, tr("Cancel"));
35
[14027]36 if (getEditor() instanceof RootPaneContainer) {
37 InputMapUtils.addEscapeAction(((RootPaneContainer) getEditor()).getRootPane(), this);
[9665]38 }
39 setEnabled(true);
40 }
41
42 @Override
43 public void actionPerformed(ActionEvent e) {
[14027]44 getMemberTable().stopHighlighting();
45 Relation snapshot = getEditor().getRelationSnapshot();
46 if ((!getMemberTableModel().hasSameMembersAs(snapshot) || getTagModel().isDirty())
47 && !(snapshot == null && getTagModel().getTags().isEmpty())) {
[9665]48 //give the user a chance to save the changes
49 int ret = confirmClosingByCancel();
50 if (ret == 0) { //Yes, save the changes
51 //copied from OKAction.run()
[12846]52 Config.getPref().put("relation.editor.generic.lastrole", tfRole.getText());
[9665]53 if (!applyChanges())
54 return;
55 } else if (ret == 2 || ret == JOptionPane.CLOSED_OPTION) //Cancel, continue editing
56 return;
57 //in case of "No, discard", there is no extra action to be performed here.
58 }
59 hideEditor();
60 }
61
62 protected int confirmClosingByCancel() {
63 ButtonSpec[] options = new ButtonSpec[] {
64 new ButtonSpec(
65 tr("Yes, save the changes and close"),
[13842]66 new ImageProvider("ok"),
[9665]67 tr("Click to save the changes and close this relation editor"),
68 null /* no specific help topic */
69 ),
70 new ButtonSpec(
71 tr("No, discard the changes and close"),
[13842]72 new ImageProvider("cancel"),
[9665]73 tr("Click to discard the changes and close this relation editor"),
74 null /* no specific help topic */
75 ),
76 new ButtonSpec(
77 tr("Cancel, continue editing"),
[13842]78 new ImageProvider("cancel"),
[9665]79 tr("Click to return to the relation editor and to resume relation editing"),
80 null /* no specific help topic */
81 )
82 };
83
84 return HelpAwareOptionPane.showOptionDialog(
85 Main.parent,
86 tr("<html>The relation has been changed.<br><br>Do you want to save your changes?</html>"),
87 tr("Unsaved changes"),
88 JOptionPane.WARNING_MESSAGE,
89 null,
90 options,
91 options[0], // OK is default,
92 "/Dialog/RelationEditor#DiscardChanges"
93 );
94 }
95}
Note: See TracBrowser for help on using the repository browser.