Ignore:
Timestamp:
2019-05-11T20:24:40+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17701, fix #17702 - add robustness when loading imagery layers from session

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java

    r14397 r15070  
    2222import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2323import org.openstreetmap.josm.gui.MainApplication;
     24import org.openstreetmap.josm.gui.Notification;
    2425import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    2526import org.openstreetmap.josm.gui.layer.Layer;
     
    3738import org.openstreetmap.josm.tools.Logging;
    3839import org.openstreetmap.josm.tools.Utils;
     40import org.openstreetmap.josm.tools.bugreport.ReportedException;
    3941
    4042/**
     
    138140                    if (canceled)
    139141                        return;
    140                     // NoteImporter directly loads notes into current note layer
    141                     if (!MainApplication.getLayerManager().containsLayer(l)) {
    142                         MainApplication.getLayerManager().addLayer(l);
    143                     }
     142                    addLayer(l);
    144143                }
    145144                if (active != null) {
     
    150149                }
    151150            }
     151        }
     152
     153        /**
     154         * Tries to add a new layer.
     155         * @param l layer to add
     156         * @return {@code true} if layer has been added, {@code false} if it wasn't needed or if an error occurred
     157         */
     158        static boolean addLayer(Layer l) {
     159            // NoteImporter directly loads notes into current note layer
     160            if (!MainApplication.getLayerManager().containsLayer(l)) {
     161                try {
     162                    MainApplication.getLayerManager().addLayer(l);
     163                } catch (ReportedException e) {
     164                    Logging.error(e);
     165                    new Notification(tr("Unable to add layer ''{0}'': {1}", l.getName(), e.getMessage()))
     166                        .setIcon(JOptionPane.ERROR_MESSAGE).setDuration(Notification.TIME_LONG).show();
     167                    if (MainApplication.getLayerManager().containsLayer(l)) {
     168                        MainApplication.getLayerManager().removeLayer(l);
     169                    }
     170                    return false;
     171                }
     172            }
     173            return true;
    152174        }
    153175
Note: See TracChangeset for help on using the changeset viewer.