diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
index 743e05f4e0..7ab8f6638f 100644
a
|
b
|
import javax.swing.JTabbedPane;
|
47 | 47 | import javax.swing.JTable; |
48 | 48 | import javax.swing.JToolBar; |
49 | 49 | import javax.swing.KeyStroke; |
| 50 | import javax.swing.event.TableModelListener; |
50 | 51 | |
51 | 52 | import org.openstreetmap.josm.actions.JosmAction; |
52 | 53 | import org.openstreetmap.josm.command.ChangeMembersCommand; |
… |
… |
public class GenericRelationEditor extends RelationEditor implements CommandQueu
|
276 | 277 | |
277 | 278 | getContentPane().add(buildToolBar(refreshAction, applyAction, selectAction, duplicateAction, deleteAction), BorderLayout.NORTH); |
278 | 279 | getContentPane().add(tabbedPane, BorderLayout.CENTER); |
279 | | getContentPane().add(buildOkCancelButtonPanel(okAction, cancelAction), BorderLayout.SOUTH); |
| 280 | getContentPane().add(buildOkCancelButtonPanel(okAction, deleteAction, cancelAction), BorderLayout.SOUTH); |
280 | 281 | |
281 | 282 | setSize(findMaxDialogSize()); |
282 | 283 | |
… |
… |
public class GenericRelationEditor extends RelationEditor implements CommandQueu
|
407 | 408 | * |
408 | 409 | * @return the panel with the OK and the Cancel button |
409 | 410 | */ |
410 | | protected static JPanel buildOkCancelButtonPanel(OKAction okAction, CancelAction cancelAction) { |
| 411 | protected JPanel buildOkCancelButtonPanel(OKAction okAction, DeleteCurrentRelationAction deleteAction, |
| 412 | CancelAction cancelAction) { |
411 | 413 | JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
412 | | pnl.add(new JButton(okAction)); |
| 414 | final JButton okButton = new JButton(okAction); |
| 415 | final JButton deleteButton = new JButton(deleteAction); |
| 416 | okButton.setPreferredSize(deleteButton.getPreferredSize()); |
| 417 | pnl.add(okButton); |
| 418 | pnl.add(deleteButton); |
413 | 419 | pnl.add(new JButton(cancelAction)); |
414 | 420 | pnl.add(new JButton(new ContextSensitiveHelpAction(ht("/Dialog/RelationEditor")))); |
| 421 | // Keep users from saving invalid relations -- a relation MUST have at least a tag with the key "type" |
| 422 | // AND must contain at least one other OSM object. |
| 423 | final TableModelListener listener = l -> { |
| 424 | final boolean delete = this.memberTableModel.getRowCount() == 0 |
| 425 | || !this.tagEditorPanel.getModel().includesTag("type"); |
| 426 | okButton.setVisible(!delete || this.getRelationSnapshot() == null); |
| 427 | deleteButton.setVisible(delete && this.getRelationSnapshot() != null); |
| 428 | if (this.getRelationSnapshot() == null && delete) { |
| 429 | okButton.setText(tr("Delete")); |
| 430 | } else { |
| 431 | okButton.setText(tr("OK")); |
| 432 | } |
| 433 | }; |
| 434 | listener.tableChanged(null); |
| 435 | this.memberTableModel.addTableModelListener(listener); |
| 436 | this.tagEditorPanel.getModel().addTableModelListener(listener); |
415 | 437 | return pnl; |
416 | 438 | } |
417 | 439 | |
diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java
index 6efdaeabdf..c41649b396 100644
a
|
b
|
public class CancelAction extends SavingAction {
|
82 | 82 | ) |
83 | 83 | }; |
84 | 84 | |
| 85 | // Keep users from saving invalid relations -- a relation MUST have at least a tag with the key "type" |
| 86 | // AND must contain at least one other OSM object. |
| 87 | options[0].setEnabled(getMemberTableModel().getRowCount() > 0 && getTagModel().includesTag("type")); |
| 88 | |
85 | 89 | return HelpAwareOptionPane.showOptionDialog( |
86 | 90 | MainApplication.getMainFrame(), |
87 | 91 | tr("<html>The relation has been changed.<br><br>Do you want to save your changes?</html>"), |
diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
index 26813f23c1..d83ba8f6cd 100644
a
|
b
|
abstract class SavingAction extends AbstractRelationEditorAction {
|
54 | 54 | tagEditorModel.applyToPrimitive(newRelation); |
55 | 55 | getMemberTableModel().applyToRelation(newRelation); |
56 | 56 | // If the user wanted to create a new relation, but hasn't added any members or |
57 | | // tags, don't add an empty relation |
58 | | if (newRelation.isEmpty() && !newRelation.hasKeys()) |
| 57 | // tags (specifically the "type" tag), don't add the relation |
| 58 | if (newRelation.isEmpty() || !newRelation.hasKey("type")) |
59 | 59 | return; |
60 | 60 | UndoRedoHandler.getInstance().add(new AddCommand(getLayer().getDataSet(), newRelation)); |
61 | 61 | |