- Timestamp:
- 2024-03-08T10:58:03+01:00 (9 months ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs/relation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r18968 r19014 56 56 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 57 57 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 58 import org.openstreetmap.josm.data.osm.IRelation;59 58 import org.openstreetmap.josm.data.osm.OsmPrimitive; 60 59 import org.openstreetmap.josm.data.osm.Relation; … … 406 405 * builds the panel with the OK and the Cancel button 407 406 * @param okAction OK action 407 * @param deleteAction Delete action 408 408 * @param cancelAction Cancel action 409 409 * … … 422 422 // Keep users from saving invalid relations -- a relation MUST have at least a tag with the key "type" 423 423 // AND must contain at least one other OSM object. 424 final TableModelListener listener = l -> updateOkPanel( this.actionAccess.getChangedRelation(),okButton, deleteButton);424 final TableModelListener listener = l -> updateOkPanel(okButton, deleteButton); 425 425 listener.tableChanged(null); 426 426 this.memberTableModel.addTableModelListener(listener); … … 430 430 431 431 /** 432 * Update the OK panel area 433 * @param newRelation What the new relation would "look" like if it were to be saved now 432 * Update the OK panel area with a temporary relation that looks if it were to be saved now. 434 433 * @param okButton The OK button 435 434 * @param deleteButton The delete button 436 435 */ 437 private void updateOkPanel(IRelation<?> newRelation, JButton okButton, JButton deleteButton) { 438 okButton.setVisible(newRelation.isUseful() || this.getRelationSnapshot() == null); 439 deleteButton.setVisible(!newRelation.isUseful() && this.getRelationSnapshot() != null); 440 if (this.getRelationSnapshot() == null && !newRelation.isUseful()) { 436 private void updateOkPanel(JButton okButton, JButton deleteButton) { 437 boolean useful = this.actionAccess.wouldRelationBeUseful(); 438 okButton.setVisible(useful || this.getRelationSnapshot() == null); 439 deleteButton.setVisible(!useful && this.getRelationSnapshot() != null); 440 if (this.getRelationSnapshot() == null && !useful) { 441 441 okButton.setText(tr("Delete")); 442 442 } else { -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java
r18413 r19014 36 36 @Override 37 37 public void updateEnabledState() { 38 setEnabled(this.editorAccess. getChangedRelation().isUseful() && isEditorDirty());38 setEnabled(this.editorAccess.wouldRelationBeUseful() && isEditorDirty()); 39 39 } 40 40 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java
r18413 r19014 9 9 import javax.swing.RootPaneContainer; 10 10 11 import org.openstreetmap.josm.data.osm.IRelation;12 11 import org.openstreetmap.josm.data.osm.Relation; 13 12 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 49 48 && !(snapshot == null && getTagModel().getTags().isEmpty())) { 50 49 //give the user a chance to save the changes 51 int ret = confirmClosingByCancel(this.editorAccess. getChangedRelation());50 int ret = confirmClosingByCancel(this.editorAccess.wouldRelationBeUseful()); 52 51 if (ret == 0) { //Yes, save the changes 53 52 //copied from OKAction.run() … … 62 61 } 63 62 64 protected int confirmClosingByCancel( final IRelation<?> newRelation) {63 protected int confirmClosingByCancel(boolean isUseful) { 65 64 ButtonSpec[] options = { 66 65 new ButtonSpec( … … 86 85 // Keep users from saving invalid relations -- a relation MUST have at least a tag with the key "type" 87 86 // AND must contain at least one other OSM object. 88 options[0].setEnabled( newRelation.isUseful());87 options[0].setEnabled(isUseful); 89 88 90 89 return HelpAwareOptionPane.showOptionDialog( -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java
r18584 r19014 72 72 /** 73 73 * Get the changed relation 74 * @return The changed relation (note: will not be part of a dataset). This should never be {@code null}. 74 * @return The changed relation (note: will not be part of a dataset) or the 75 * value returned by {@code getEditor().getRelation()}. This should never be {@code null}. 76 * If called for a temporary use of the relation instance, make sure to cleanup a copy to avoid memory leaks, see #23527 75 77 * @since 18413 76 78 */ … … 98 100 99 101 /** 102 * Check if the changed relation would be useful. 103 * @return true if the saved relation has at least one tag and one member 104 * @since 19014 105 */ 106 default boolean wouldRelationBeUseful() { 107 return (getTagModel().getRowCount() > 0 && getMemberTableModel().getRowCount() > 0); 108 } 109 110 /** 100 111 * Get the text field that is used to edit the role. 101 112 * @return The role text field.
Note:
See TracChangeset
for help on using the changeset viewer.