Subject: [PATCH] Fix #23018: `RelationListDialog` should not re-init on every `DataChangedEvent`
A `DataChangedEvent` can have no subevents, one subevent, or many subevents.
As an example, adding the first node via the `Draw` command will fire an event
with a single `PRIMITIVES_ADDED` subevent, adding the second node will fire an
event with two `PRIMITIVES_ADDED` events and one `PRIMITIVE_FLAGS_CHANGED` event,
adding the third (and further) node will fire an event with one `PRIMITIVES_ADDED`
event, one `WAY_NODES_CHANGED` event, and one `PRIMITIVE_FLAGS_CHANGED` event.
Therefore, the `RelationListDialog` ''should not'' call `initFromData` every time
a `DataChangedEvent` is fired. We do this by adding a default method in
`DataSetListener` which iterates through each event individually and calls the
appropriate function. It is not and should not be called by event firers.
---
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/org/openstreetmap/josm/data/osm/event/DataSetListener.java b/src/org/openstreetmap/josm/data/osm/event/DataSetListener.java
|
a
|
b
|
|
| 63 | 63 | * @param event data change event |
| 64 | 64 | */ |
| 65 | 65 | void dataChanged(DataChangedEvent event); |
| | 66 | |
| | 67 | /** |
| | 68 | * Call each subevent of a {@link DataChangedEvent}. This should only ever be called from |
| | 69 | * {@link #dataChanged(DataChangedEvent)}. |
| | 70 | * @param event The event to call the individual elements from |
| | 71 | * @implNote Implementors should decide what they want to do with {@code event == null}, |
| | 72 | * {@code event.getEvents() == null}, and {@code event.getEvents().isEmpty()}. |
| | 73 | * @since xxx |
| | 74 | */ |
| | 75 | default void dataChangedIndividualEvents(DataChangedEvent event) { |
| | 76 | for (AbstractDatasetChangedEvent subEvent : event.getEvents()) { |
| | 77 | if (subEvent instanceof PrimitivesAddedEvent) { |
| | 78 | this.primitivesAdded((PrimitivesAddedEvent) subEvent); |
| | 79 | } else if (subEvent instanceof PrimitivesRemovedEvent) { |
| | 80 | this.primitivesRemoved((PrimitivesRemovedEvent) subEvent); |
| | 81 | } else if (subEvent instanceof TagsChangedEvent) { |
| | 82 | this.tagsChanged((TagsChangedEvent) subEvent); |
| | 83 | } else if (subEvent instanceof NodeMovedEvent) { |
| | 84 | this.nodeMoved((NodeMovedEvent) subEvent); |
| | 85 | } else if (subEvent instanceof WayNodesChangedEvent) { |
| | 86 | this.wayNodesChanged((WayNodesChangedEvent) subEvent); |
| | 87 | } else if (subEvent instanceof RelationMembersChangedEvent) { |
| | 88 | this.relationMembersChanged((RelationMembersChangedEvent) subEvent); |
| | 89 | } else { |
| | 90 | this.otherDatasetChange(subEvent); |
| | 91 | } |
| | 92 | } |
| | 93 | } |
| 66 | 94 | } |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
|
a
|
b
|
|
| 735 | 735 | |
| 736 | 736 | @Override |
| 737 | 737 | public void dataChanged(DataChangedEvent event) { |
| 738 | | initFromData(MainApplication.getLayerManager().getActiveData()); |
| | 738 | // I have no clue how it would be empty, but just in case use the original code. |
| | 739 | // {@code null} is used during initialization |
| | 740 | if (event == null || Utils.isEmpty(event.getEvents())) { |
| | 741 | initFromData(MainApplication.getLayerManager().getActiveData()); |
| | 742 | } else { |
| | 743 | dataChangedIndividualEvents(event); |
| | 744 | } |
| 739 | 745 | } |
| 740 | 746 | |
| 741 | 747 | @Override |