Skip to content

Commit 45c7cf7

Browse files
committed
Automatically refresh relation editor when relation is changed outside of editor
Relation in editor is automatically refreshed when no changes have been made in the editor yet. Display a warning notification about required conflict resolution otherwise.
1 parent c4af10f commit 45c7cf7

File tree

6 files changed

+59
-23
lines changed

6 files changed

+59
-23
lines changed

src/org/openstreetmap/josm/data/conflict/ConflictCollection.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,17 @@ public final Collection<Conflict<? extends OsmPrimitive>> getNodeConflicts() {
316316
}
317317

318318
/**
319-
* Returns the list of conflicts involving nodes.
320-
* @return The list of conflicts involving nodes.
319+
* Returns the list of conflicts involving ways.
320+
* @return The list of conflicts involving ways.
321321
* @since 6555
322322
*/
323323
public final Collection<Conflict<? extends OsmPrimitive>> getWayConflicts() {
324324
return SubclassFilteredCollection.filter(conflicts, c -> c != null && c.getMy() instanceof Way);
325325
}
326326

327327
/**
328-
* Returns the list of conflicts involving nodes.
329-
* @return The list of conflicts involving nodes.
328+
* Returns the list of conflicts involving relations.
329+
* @return The list of conflicts involving relations.
330330
* @since 6555
331331
*/
332332
public final Collection<Conflict<? extends OsmPrimitive>> getRelationConflicts() {

src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
6363
import org.openstreetmap.josm.gui.MainApplication;
6464
import org.openstreetmap.josm.gui.MainMenu;
65+
import org.openstreetmap.josm.gui.Notification;
6566
import org.openstreetmap.josm.gui.ScrollViewport;
6667
import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
6768
import org.openstreetmap.josm.gui.dialogs.relation.actions.AbstractRelationEditorAction;
@@ -1048,10 +1049,27 @@ public AutoCompletingTextField getTextFieldRole() {
10481049
@Override
10491050
public void commandChanged(int queueSize, int redoSize) {
10501051
Relation r = getRelation();
1051-
if (r != null && r.getDataSet() == null) {
1052-
// see #19915
1053-
setRelation(null);
1054-
applyAction.updateEnabledState();
1052+
if (r != null) {
1053+
if (r.getDataSet() == null) {
1054+
// see #19915
1055+
setRelation(null);
1056+
applyAction.updateEnabledState();
1057+
} else if (isDirtyRelation()) {
1058+
if (!isDirtyEditor()) {
1059+
reloadDataFromRelation();
1060+
} else {
1061+
new Notification(tr("Relation modified outside of relation editor with pending changes. Conflict resolution required."))
1062+
.setIcon(JOptionPane.WARNING_MESSAGE).show();
1063+
}
1064+
}
10551065
}
10561066
}
1067+
1068+
@Override
1069+
public boolean isDirtyEditor() {
1070+
Relation snapshot = getRelationSnapshot();
1071+
Relation relation = getRelation();
1072+
return (snapshot != null && !memberTableModel.hasSameMembersAs(snapshot)) ||
1073+
tagEditorPanel.getModel().isDirty() || relation == null || relation.getDataSet() == null;
1074+
}
10571075
}

src/org/openstreetmap/josm/gui/dialogs/relation/IRelationEditor.java

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ public interface IRelationEditor {
4141
*/
4242
boolean isDirtyRelation();
4343

44+
/**
45+
* Replies true if the currently edited relation has been changed elsewhere.
46+
*
47+
* In this case a relation editor can't apply updates to the relation directly. Rather,
48+
* it has to create a conflict.
49+
*
50+
* @param ignoreUninterestingTags whether to ignore uninteresting tag changes
51+
* @return true if the currently edited relation has been changed elsewhere.
52+
*/
53+
boolean isDirtyRelation(boolean ignoreUninterestingTags);
54+
55+
/**
56+
* Replies true if the relation has been changed in the editor (but not yet applied).
57+
*
58+
* Reloading data from the relation would cause the pending changes to be lost.
59+
*
60+
* @return true if the currently edited relation has been changed in the editor.
61+
*/
62+
boolean isDirtyEditor();
63+
4464
/**
4565
* Reloads data from relation.
4666
*/

src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,17 @@ protected final void setRelationSnapshot(Relation snapshot) {
147147

148148
@Override
149149
public final boolean isDirtyRelation() {
150-
return !relation.hasEqualSemanticAttributes(relationSnapshot);
150+
return isDirtyRelation(false);
151+
}
152+
153+
@Override
154+
public final boolean isDirtyRelation(boolean ignoreUninterestingTags) {
155+
if (relation != null && relation.getDataSet() == null &&
156+
relationSnapshot != null && relationSnapshot.getDataSet() == null) {
157+
return false;
158+
}
159+
160+
return !relation.hasEqualSemanticAttributes(relationSnapshot, ignoreUninterestingTags);
151161
}
152162

153163
/* ----------------------------------------------------------------------- */

src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,7 @@ public void actionPerformed(ActionEvent e) {
6767

6868
@Override
6969
public void updateEnabledState() {
70-
Relation snapshot = getEditor().getRelationSnapshot();
71-
Relation relation = getEditor().getRelation();
72-
if (relation != null && relation.getDataSet() == null)
73-
relation = null; // see #19915
74-
if (relation != null && snapshot != null && snapshot.getDataSet() == null) {
75-
// relation was changed outside of the editor
76-
// either it was modified or deleted or changed by an undo
77-
setEnabled(!snapshot.hasEqualSemanticAttributes(relation, false /* don't ignore uninteresting keys */));
78-
return;
79-
}
80-
setEnabled(false);
70+
setEnabled(getEditor().isDirtyRelation());
8171
}
8272

8373
protected int confirmDiscardDirtyData() {

src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ protected void hideEditor() {
192192
}
193193

194194
protected boolean isEditorDirty() {
195-
Relation snapshot = editorAccess.getEditor().getRelationSnapshot();
196-
return (snapshot != null && !getMemberTableModel().hasSameMembersAs(snapshot)) || getTagModel().isDirty()
197-
|| getEditor().getRelation() == null || getEditor().getRelation().getDataSet() == null;
195+
return editorAccess.getEditor().isDirtyEditor();
198196
}
199197
}

0 commit comments

Comments
 (0)