1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Component;
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
|
---|
11 | import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
|
---|
12 | import org.openstreetmap.josm.gui.dialogs.relation.RelationAware;
|
---|
13 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
14 | import org.openstreetmap.josm.gui.tagging.TagEditorModel;
|
---|
15 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Apply the updates and close the dialog.
|
---|
20 | */
|
---|
21 | public class OKAction extends SavingAction {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Constructs a new {@code OKAction}.
|
---|
25 | * @param memberTable member table
|
---|
26 | * @param memberTableModel member table model
|
---|
27 | * @param tagModel tag editor model
|
---|
28 | * @param layer OSM data layer
|
---|
29 | * @param editor relation editor
|
---|
30 | * @param tfRole role text field
|
---|
31 | */
|
---|
32 | public OKAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer,
|
---|
33 | RelationAware editor, AutoCompletingTextField tfRole) {
|
---|
34 | super(memberTable, memberTableModel, tagModel, layer, editor, tfRole);
|
---|
35 | putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog"));
|
---|
36 | putValue(SMALL_ICON, ImageProvider.get("ok"));
|
---|
37 | putValue(NAME, tr("OK"));
|
---|
38 | setEnabled(true);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public void actionPerformed(ActionEvent e) {
|
---|
43 | Main.pref.put("relation.editor.generic.lastrole", tfRole.getText());
|
---|
44 | memberTable.stopHighlighting();
|
---|
45 | if (editor.getRelation() == null) {
|
---|
46 | applyNewRelation(tagModel);
|
---|
47 | } else if (!memberTableModel.hasSameMembersAs(editor.getRelationSnapshot()) || tagModel.isDirty()) {
|
---|
48 | if (editor.isDirtyRelation()) {
|
---|
49 | if (confirmClosingBecauseOfDirtyState()) {
|
---|
50 | if (layer.getConflicts().hasConflictForMy(editor.getRelation())) {
|
---|
51 | warnDoubleConflict();
|
---|
52 | return;
|
---|
53 | }
|
---|
54 | applyExistingConflictingRelation(tagModel);
|
---|
55 | } else
|
---|
56 | return;
|
---|
57 | } else {
|
---|
58 | applyExistingNonConflictingRelation(tagModel);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | if (editor instanceof Component) {
|
---|
62 | ((Component) editor).setVisible(false);
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|