Changeset 2860 in josm for trunk


Ignore:
Timestamp:
2010-01-14T22:06:53+01:00 (10 years ago)
Author:
jttt
Message:

Fixed #3233 Relation list doesn't update when a data layer is deleted

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r2809 r2860  
    312312     * @return the next active data layer
    313313     */
    314     protected Layer determineNextActiveLayer(Layer ignoredLayer) {
     314    protected Layer determineNextActiveLayer(List<Layer> layersList) {
    315315        // First look for data layer
    316         for (Layer layer:layers) {
    317             if (layer instanceof OsmDataLayer && layer != ignoredLayer)
     316        for (Layer layer:layersList) {
     317            if (layer instanceof OsmDataLayer)
    318318                return layer;
    319319        }
    320320
    321321        // Then any layer
    322         for (Layer layer:layers) {
    323             if (layer != ignoredLayer)
    324                 return layer;
    325         }
     322        if (!layersList.isEmpty())
     323            return layersList.get(0);
    326324
    327325        // and then give up
     
    335333     */
    336334    public void removeLayer(Layer layer) {
     335        List<Layer> layersList = new ArrayList<Layer>(layers);
     336
     337        if (!layersList.remove(layer))
     338            return;
     339
     340        setEditLayer(layersList);
     341
    337342        if (layer == activeLayer) {
    338             setActiveLayer(determineNextActiveLayer(activeLayer));
    339         }
    340         if (layers.remove(layer)) {
    341             fireLayerRemoved(layer);
    342         }
     343            setActiveLayer(determineNextActiveLayer(layersList), false);
     344        }
     345
     346        layers.remove(layer);
     347        fireLayerRemoved(layer);
    343348        layer.removePropertyChangeListener(this);
    344349        layer.destroy();
     
    378383            layers.add(pos, layer);
    379384        }
    380         setEditLayer();
     385        setEditLayer(layers);
    381386        AudioPlayer.reset();
    382387        repaint();
     
    577582    }
    578583
    579     private void setEditLayer() {
    580         OsmDataLayer newEditLayer = editLayer;
     584    private void setEditLayer(List<Layer> layersList) {
     585        OsmDataLayer newEditLayer = layersList.contains(editLayer)?editLayer:null;
    581586        OsmDataLayer oldEditLayer = editLayer;
    582587
    583588        // Find new edit layer
    584         if (activeLayer != editLayer) {
    585             if (activeLayer instanceof OsmDataLayer) {
     589        if (activeLayer != editLayer || !layersList.contains(editLayer)) {
     590            if (activeLayer instanceof OsmDataLayer && layersList.contains(activeLayer)) {
    586591                newEditLayer = (OsmDataLayer) activeLayer;
    587592            } else {
    588                 for (Layer layer:layers) {
     593                for (Layer layer:layersList) {
    589594                    if (layer instanceof OsmDataLayer) {
    590595                        newEditLayer = (OsmDataLayer) layer;
     
    616621     */
    617622    public void setActiveLayer(Layer layer) {
     623        setActiveLayer(layer, true);
     624    }
     625
     626    private void setActiveLayer(Layer layer, boolean setEditLayer) {
    618627        if (layer != null && !layers.contains(layer))
    619628            throw new IllegalArgumentException(tr("Layer ''{0}'' must be in list of layers", layer.toString()));
     
    624633        Layer old = activeLayer;
    625634        activeLayer = layer;
    626         setEditLayer();
     635        if (setEditLayer) {
     636            setEditLayer(layers);
     637        }
    627638        fireActiveLayerChanged(old, layer);
    628639
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r2741 r2860  
    736736
    737737    public void dataChanged(DataChangedEvent event) {
    738         Layer l = Main.main.getEditLayer();
    739         if (l != null) {
    740             initFromLayer(l);
    741         }
     738        initFromLayer(Main.main.getEditLayer());
    742739    }
    743740
Note: See TracChangeset for help on using the changeset viewer.