Changeset 12101 in josm


Ignore:
Timestamp:
2017-05-10T23:24:52+02:00 (3 years ago)
Author:
michael2402
Message:

Fix #14765: Don't use runAndWait for table updates.

UserListDialog now does all table updates in EDT, this should make it thread safe. There was a bug where changes of the active layer were not registered when showing the dialog. This is fixed, too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r11747 r12101  
    3131import org.openstreetmap.josm.Main;
    3232import org.openstreetmap.josm.actions.AbstractInfoAction;
    33 import org.openstreetmap.josm.data.SelectionChangedListener;
    34 import org.openstreetmap.josm.data.osm.DataSet;
     33import org.openstreetmap.josm.data.osm.DataSelectionListener;
    3534import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3635import org.openstreetmap.josm.data.osm.User;
     36import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    3737import org.openstreetmap.josm.gui.SideButton;
    3838import org.openstreetmap.josm.gui.layer.Layer;
     
    5151 *
    5252 */
    53 public class UserListDialog extends ToggleDialog implements SelectionChangedListener, ActiveLayerChangeListener {
     53public class UserListDialog extends ToggleDialog implements DataSelectionListener, ActiveLayerChangeListener {
    5454
    5555    /**
     
    7171    @Override
    7272    public void showNotify() {
    73         DataSet.addSelectionListener(this);
     73        SelectionEventManager.getInstance().addSelectionListenerForEdt(this);
    7474        Main.getLayerManager().addActiveLayerChangeListener(this);
    7575    }
     
    7878    public void hideNotify() {
    7979        Main.getLayerManager().removeActiveLayerChangeListener(this);
    80         DataSet.removeSelectionListener(this);
     80        SelectionEventManager.getInstance().removeSelectionListener(this);
    8181    }
    8282
     
    103103    }
    104104
    105     /**
    106      * Called when the selection in the dataset changed.
    107      * @param newSelection The new selection array.
    108      */
    109     @Override
    110     public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    111         refresh(newSelection);
     105    @Override
     106    public void selectionChanged(SelectionChangeEvent event) {
     107        refresh(event.getSelection());
    112108    }
    113109
     
    115111    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    116112        Layer activeLayer = e.getSource().getActiveLayer();
     113        refreshForActiveLayer(activeLayer);
     114    }
     115
     116    private void refreshForActiveLayer(Layer activeLayer) {
    117117        if (activeLayer instanceof OsmDataLayer) {
    118118            refresh(((OsmDataLayer) activeLayer).data.getAllSelected());
     
    127127     */
    128128    public void refresh(Collection<? extends OsmPrimitive> fromPrimitives) {
    129         model.populate(fromPrimitives);
    130129        GuiHelper.runInEDT(() -> {
     130            model.populate(fromPrimitives);
    131131            if (model.getRowCount() != 0) {
    132132                setTitle(trn("{0} Author", "{0} Authors", model.getRowCount(), model.getRowCount()));
     
    140140    public void showDialog() {
    141141        super.showDialog();
    142         Layer layer = Main.getLayerManager().getActiveLayer();
    143         if (layer instanceof OsmDataLayer) {
    144             refresh(((OsmDataLayer) layer).data.getAllSelected());
    145         }
     142        refreshForActiveLayer(Main.getLayerManager().getActiveLayer());
    146143    }
    147144
     
    308305
    309306        public void populate(Collection<? extends OsmPrimitive> primitives) {
     307            GuiHelper.assertCallFromEdt();
    310308            Map<User, Integer> statistics = computeStatistics(primitives);
    311309            data.clear();
     
    316314            }
    317315            Collections.sort(data);
    318             GuiHelper.runInEDTAndWait(this::fireTableDataChanged);
     316            this.fireTableDataChanged();
    319317        }
    320318
Note: See TracChangeset for help on using the changeset viewer.