From 238092bd18da57fa66609fa8c4287fbc909405ef Mon Sep 17 00:00:00 2001 From: GerdP Date: Fri, 10 Jan 2025 06:16:23 +0000 Subject: [PATCH] fix #24037 - revert the changes from r17423 in `GenericRelationEditor` - use GuiHelper.runInEDT() to avoid the EDT violations reported in #20228 git-svn-id: https://josm.openstreetmap.de/svn/trunk@19279 0c6e7542-c601-0410-84e7-c038aed88b3b --- .../relation/GenericRelationEditor.java | 34 +++---------------- .../dialogs/relation/MemberTableModel.java | 6 ++-- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java index 2fb49413e44..45d3b581374 100644 --- a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java +++ b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java @@ -5,7 +5,6 @@ import static org.openstreetmap.josm.tools.I18n.tr; import java.awt.BorderLayout; -import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; @@ -161,9 +160,6 @@ public class GenericRelationEditor extends RelationEditor implements CommandQueu */ private final ArrayList clipboardListeners = new ArrayList<>(); - private Component selectedTabPane; - private final JTabbedPane tabbedPane; - /** * Creates a new relation editor for the given relation. The relation will be saved if the user * selects "ok" in the editor. @@ -235,12 +231,12 @@ public Collection getSelection() { pnl.setBorder(BorderFactory.createRaisedBevelBorder()); getContentPane().setLayout(new BorderLayout()); + final JTabbedPane tabbedPane; tabbedPane = new JTabbedPane(); tabbedPane.add(tr("Tags and Members"), pnl); referrerBrowser = new ReferringRelationsBrowser(getLayer(), referrerModel); tabbedPane.add(tr("Parent Relations"), referrerBrowser); tabbedPane.add(tr("Child Relations"), new ChildRelationBrowser(getLayer(), relation)); - selectedTabPane = tabbedPane.getSelectedComponent(); tabbedPane.addChangeListener(e -> { JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource(); int index = sourceTabbedPane.getSelectedIndex(); @@ -248,14 +244,6 @@ public Collection getSelection() { if (title.equals(tr("Parent Relations"))) { referrerBrowser.init(); } - // see #20228 - boolean selIsTagsAndMembers = sourceTabbedPane.getSelectedComponent() == pnl; - if (selectedTabPane == pnl && !selIsTagsAndMembers) { - unregisterMain(); - } else if (selectedTabPane != pnl && selIsTagsAndMembers) { - registerMain(); - } - selectedTabPane = sourceTabbedPane.getSelectedComponent(); }); actionAccess = new RelationEditorActionAccess(); @@ -330,18 +318,6 @@ public void actionPerformed(ActionEvent e) { UndoRedoHandler.getInstance().addCommandQueueListener(this); } - private void registerMain() { - selectionTableModel.register(); - memberTableModel.register(); - memberTable.registerListeners(); - } - - private void unregisterMain() { - selectionTableModel.unregister(); - memberTableModel.unregister(); - memberTable.unregisterListeners(); - } - @Override public void reloadDataFromRelation() { setRelation(getRelation()); @@ -788,9 +764,10 @@ public void setVisible(boolean visible) { // make sure all registered listeners are unregistered // memberTable.stopHighlighting(); - if (tabbedPane != null && tr("Tags and Members").equals(tabbedPane.getTitleAt(tabbedPane.getSelectedIndex()))) { - unregisterMain(); - } + selectionTableModel.unregister(); + memberTableModel.unregister(); + memberTable.unregisterListeners(); + if (windowMenuItem != null) { MainApplication.getMenu().windowMenu.remove(windowMenuItem); windowMenuItem = null; @@ -897,7 +874,6 @@ public void dispose() { UndoRedoHandler.getInstance().removeCommandQueueListener(this); super.dispose(); // call before setting relation to null, see #20304 setRelation(null); - selectedTabPane = null; } /** diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java b/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java index 2686e10234d..32d6db84617 100644 --- a/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java +++ b/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java @@ -132,8 +132,10 @@ public void selectionChanged(SelectionChangeEvent event) { public void dataChanged(DataChangedEvent event) { // just trigger a repaint - the display name of the relation members may have changed Collection sel = getSelectedMembers(); - GuiHelper.runInEDT(this::fireTableDataChanged); - setSelectedMembers(sel); + GuiHelper.runInEDT(() -> { + fireTableDataChanged(); + setSelectedMembers(sel); + }); } @Override