Changeset 8573 in josm


Ignore:
Timestamp:
2015-07-05T18:20:17+02:00 (6 years ago)
Author:
bastiK
Message:

fixed #11647 - Regression: relation list empty (patch by michael2402)

File:
1 edited

Legend:

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

    r8557 r8573  
    2727import java.util.Collections;
    2828import java.util.Comparator;
     29import java.util.EnumSet;
    2930import java.util.LinkedHashSet;
    3031import java.util.List;
     
    407408        layerLock.writeLock().lock();
    408409        layerLock.readLock().lock();
    409         boolean fireSetActiveLayer = false;
     410        EnumSet<LayerListenerType> listenersToFire = EnumSet.noneOf(LayerListenerType.class);
    410411        Layer oldActiveLayer = activeLayer;
     412        OsmDataLayer oldEditLayer = editLayer;
    411413        try {
    412414            try {
     
    433435                if (isOsmDataLayer || oldActiveLayer == null) {
    434436                    // autoselect the new layer
    435                     fireSetActiveLayer = setActiveLayer(layer, true);
     437                    listenersToFire.addAll(setActiveLayer(layer, true));
    436438                }
    437439            } finally {
     
    443445                ((OsmDataLayer) layer).addLayerStateChangeListener(this);
    444446            }
    445             if (fireSetActiveLayer) {
    446                 onActiveLayerChanged(oldActiveLayer);
    447             }
     447            onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
    448448            layer.addPropertyChangeListener(this);
    449449            Main.addProjectionChangeListener(layer);
     
    452452            layerLock.readLock().unlock();
    453453        }
    454         if (!fireSetActiveLayer) {
     454        if (!listenersToFire.isEmpty()) {
    455455            repaint();
    456456        }
     
    531531     */
    532532    public void removeLayer(Layer layer) {
    533         boolean fireEditLayerChanged;
    534         boolean fireSetActiveLayer = false;
    535533        layerLock.writeLock().lock();
    536534        layerLock.readLock().lock();
    537535
     536        EnumSet<LayerListenerType> listenersToFire = EnumSet.noneOf(LayerListenerType.class);
     537        Layer oldActiveLayer = activeLayer;
    538538        OsmDataLayer oldEditLayer = editLayer;
    539         Layer oldActiveLayer = activeLayer;
    540 
    541539        try {
    542540            try {
     
    546544                    return;
    547545
    548                 fireEditLayerChanged = setEditLayer(layersList);
     546                listenersToFire = setEditLayer(layersList);
    549547
    550548                if (layer == activeLayer) {
    551                     fireSetActiveLayer = setActiveLayer(determineNextActiveLayer(layersList), false);
     549                    listenersToFire.addAll(setActiveLayer(determineNextActiveLayer(layersList), false));
    552550                }
    553551
     
    562560                layerLock.writeLock().unlock();
    563561            }
    564             if (fireEditLayerChanged) {
    565                onEditLayerChanged(oldEditLayer);
    566             }
    567             if (fireSetActiveLayer) {
    568                 onActiveLayerChanged(oldActiveLayer);
    569             }
     562            onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
    570563            fireLayerRemoved(layer);
    571564            layer.removePropertyChangeListener(this);
     
    611604        layerLock.writeLock().lock();
    612605        layerLock.readLock().lock();
    613         boolean fireEditLayerChanged;
     606        EnumSet<LayerListenerType> listenersToFire;
     607        Layer oldActiveLayer = activeLayer;
    614608        OsmDataLayer oldEditLayer = editLayer;
    615609        try {
     
    626620                    layers.add(pos, layer);
    627621                }
    628                 fireEditLayerChanged = setEditLayer(layers);
     622                listenersToFire = setEditLayer(layers);
    629623            } finally {
    630624                layerLock.writeLock().unlock();
    631625            }
    632             if (fireEditLayerChanged) {
    633                 onEditLayerChanged(editLayer);
    634             }
     626            onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
    635627            AudioPlayer.reset();
    636628        } finally {
     
    946938     * You must own a write {@link #layerLock} when calling this method.
    947939     * @param layersList A list to select that layer from.
    948      * @return <code>true</code> if the edit layer was really changed and the listeners should be informed.
    949      */
    950     private boolean setEditLayer(List<Layer> layersList) {
     940     * @return A list of change listeners that should be fired using {@link #onActiveEditLayerChanged(Layer, OsmDataLayer, EnumSet)}
     941     */
     942    private EnumSet<LayerListenerType> setEditLayer(List<Layer> layersList) {
    951943        final OsmDataLayer newEditLayer = findNewEditLayer(layersList);
    952944
     
    959951
    960952            editLayer = newEditLayer;
    961             return true;
     953            return EnumSet.of(LayerListenerType.EDIT_LAYER_CHANGE);
    962954        } else {
    963             return false;
     955            return EnumSet.noneOf(LayerListenerType.class);
    964956        }
    965957
     
    994986        layerLock.writeLock().lock();
    995987        layerLock.readLock().lock();
     988        EnumSet<LayerListenerType> listenersToFire;
    996989        Layer oldActiveLayer = activeLayer;
    997         try {
    998             boolean fireSetActiveLayer;
     990        OsmDataLayer oldEditLayer = editLayer;
     991        try {
    999992            try {
    1000                 fireSetActiveLayer = setActiveLayer(layer, true);
     993                listenersToFire = setActiveLayer(layer, true);
    1001994            } finally {
    1002995                layerLock.writeLock().unlock();
    1003996            }
    1004             if (fireSetActiveLayer) {
    1005                 onActiveLayerChanged(oldActiveLayer);
    1006             }
     997            onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
    1007998        } finally {
    1008999            layerLock.readLock().unlock();
     
    10151006     * @param layer The layer to be active.
    10161007     * @param setEditLayer if this is <code>true</code>, the edit layer is also set.
    1017      * @return {@code true} if the active layer has changed, {@code false otherwise}
    1018      */
    1019     private boolean setActiveLayer(final Layer layer, boolean setEditLayer) {
     1008     * @return A list of change listeners that should be fired using {@link #onActiveEditLayerChanged(Layer, OsmDataLayer, EnumSet)}
     1009     */
     1010    private EnumSet<LayerListenerType> setActiveLayer(final Layer layer, boolean setEditLayer) {
    10201011        if (layer != null && !layers.contains(layer))
    10211012            throw new IllegalArgumentException(tr("Layer ''{0}'' must be in list of layers", layer.toString()));
    10221013
    10231014        if (layer == activeLayer)
    1024             return false;
     1015            return EnumSet.noneOf(LayerListenerType.class);
    10251016
    10261017        activeLayer = layer;
     1018        EnumSet<LayerListenerType> listenersToFire = EnumSet.of(LayerListenerType.ACTIVE_LAYER_CHANGE);
    10271019        if (setEditLayer) {
    1028             setEditLayer(layers);
    1029         }
    1030 
    1031         return true;
     1020            listenersToFire.addAll(setEditLayer(layers));
     1021        }
     1022
     1023        return listenersToFire;
    10321024    }
    10331025
     
    10431035        } finally {
    10441036            layerLock.readLock().unlock();
     1037        }
     1038    }
     1039
     1040    private enum LayerListenerType {
     1041        ACTIVE_LAYER_CHANGE,
     1042        EDIT_LAYER_CHANGE
     1043    }
     1044
     1045    /**
     1046     * This is called whenever one of active layer/edit layer or both may have been changed,
     1047     * @param oldActive The old active layer
     1048     * @param oldEdit The old edit layer.
     1049     * @param listenersToFire A mask of listeners to fire using {@link LayerListenerType}s
     1050     */
     1051    private void onActiveEditLayerChanged(final Layer oldActive, final OsmDataLayer oldEdit, EnumSet<LayerListenerType> listenersToFire) {
     1052        if (listenersToFire.contains(LayerListenerType.EDIT_LAYER_CHANGE)) {
     1053            onEditLayerChanged(oldEdit);
     1054        }
     1055        if (listenersToFire.contains(LayerListenerType.ACTIVE_LAYER_CHANGE)) {
     1056            onActiveLayerChanged(oldActive);
    10451057        }
    10461058    }
Note: See TracChangeset for help on using the changeset viewer.