Ticket #23527: 23527-beta.patch
File 23527-beta.patch, 8.5 KB (added by , 11 months ago) |
---|
-
src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
55 55 import org.openstreetmap.josm.data.UndoRedoHandler; 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; 61 60 import org.openstreetmap.josm.data.osm.RelationMember; … … 405 404 /** 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 * 410 410 * @return the panel with the OK and the Cancel button … … 421 421 pnl.add(new JButton(new ContextSensitiveHelpAction(ht("/Dialog/RelationEditor")))); 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); 427 427 this.tagEditorPanel.getModel().addTableModelListener(listener); … … 429 429 } 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 { 443 443 okButton.setText(tr("OK")); -
src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java
35 35 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 } -
src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java
8 8 import javax.swing.JOptionPane; 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; 14 13 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; … … 48 47 if ((!getMemberTableModel().hasSameMembersAs(snapshot) || getTagModel().isDirty()) 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() 54 53 Config.getPref().put("relation.editor.generic.lastrole", Utils.strip(tfRole.getText())); … … 61 60 hideEditor(); 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( 67 66 tr("Yes, save the changes and close"), … … 85 84 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( 91 90 MainApplication.getMainFrame(), -
src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java
74 74 * @return The changed relation (note: will not be part of a dataset). This should never be {@code null}. 75 75 * @since 18413 76 76 */ 77 @Deprecated 77 78 default IRelation<?> getChangedRelation() { 78 79 final Relation newRelation; 79 80 final Relation oldRelation = getEditor().getRelation(); … … 97 98 } 98 99 99 100 /** 101 * Check if the changed relation would be useful. 102 * @return true if the saved relation would be useful 103 * @since xxx 104 */ 105 default boolean wouldRelationBeUseful() { 106 final Relation newRelation; 107 final Relation oldRelation = getEditor().getRelation(); 108 boolean isUploadInProgress = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class) 109 .stream().anyMatch(OsmDataLayer::isUploadInProgress); 110 if (isUploadInProgress || (oldRelation != null && oldRelation.getDataSet() != null && oldRelation.getDataSet().isLocked())) { 111 // If the dataset is locked, then we cannot change the relation. See JOSM #22024. 112 // We should also avoid changing the relation if there is an upload in progress. See JOSM #22268/#22398. 113 // There appears to be a race condition where a dataset might not be locked in the check, then is locked while using the 114 // copy relation constructor. 115 // This is due to the `setMembers` -> `addReferrer` call chain requires that the dataset is not read only. 116 return oldRelation != null && oldRelation.isUseful(); 117 } else if (oldRelation != null) { 118 newRelation = new Relation(oldRelation); 119 } else { 120 newRelation = new Relation(); 121 } 122 getTagModel().applyToPrimitive(newRelation); 123 getMemberTableModel().applyToRelation(newRelation); 124 boolean res = newRelation.isUseful(); 125 newRelation.setMembers(null); 126 return res; 127 } 128 129 /** 100 130 * Get the text field that is used to edit the role. 101 131 * @return The role text field. 102 132 */ -
test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java
169 169 relationEditorAccess.getTagModel().initFromPrimitive(relation); 170 170 relationEditorAccess.getEditor().reloadDataFromRelation(); 171 171 assertDoesNotThrow(relationEditorAccess::getChangedRelation); 172 assertDoesNotThrow(relationEditorAccess::wouldRelationBeUseful); 172 173 } 173 174 }