Skip to content

Commit

Permalink
fix #24037
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
GerdP authored and GerdP committed Jan 10, 2025
1 parent bc5a3b2 commit 238092b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,9 +160,6 @@ public class GenericRelationEditor extends RelationEditor implements CommandQueu
*/
private final ArrayList<FlavorListener> 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.
Expand Down Expand Up @@ -235,27 +231,19 @@ public Collection<OsmPrimitive> 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();
String title = sourceTabbedPane.getTitleAt(index);
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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RelationMember> sel = getSelectedMembers();
GuiHelper.runInEDT(this::fireTableDataChanged);
setSelectedMembers(sel);
GuiHelper.runInEDT(() -> {
fireTableDataChanged();
setSelectedMembers(sel);
});
}

@Override
Expand Down

0 comments on commit 238092b

Please sign in to comment.