Changeset 13437 in josm


Ignore:
Timestamp:
2018-02-18T16:51:54+01:00 (6 months ago)
Author:
Don-vip
Message:

fix #15967 - proper loading of notes layers

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

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

    r12636 r13437  
    138138                    if (canceled)
    139139                        return;
    140                     MainApplication.getLayerManager().addLayer(l);
     140                    // NoteImporter directly loads notes into current note layer
     141                    if (!MainApplication.getLayerManager().containsLayer(l)) {
     142                        MainApplication.getLayerManager().addLayer(l);
     143                    }
    141144                }
    142145                if (active != null) {
  • trunk/src/org/openstreetmap/josm/actions/UploadNotesAction.java

    r12675 r13437  
    55
    66import java.awt.event.ActionEvent;
    7 import java.util.List;
    87
    98import org.openstreetmap.josm.actions.upload.UploadNotesTask;
     
    1817 * On click, it finds the note layer and fires off an upload task
    1918 * with the note data contained in the layer.
    20  *
     19 * @since 7699
    2120 */
    2221public class UploadNotesAction extends JosmAction {
     
    3130    @Override
    3231    public void actionPerformed(ActionEvent e) {
    33         List<NoteLayer> noteLayers = getLayerManager().getLayersOfType(NoteLayer.class);
    34         NoteLayer layer;
    35         if (!noteLayers.isEmpty()) {
    36             layer = noteLayers.get(0);
    37         } else {
     32        NoteLayer layer = getLayerManager().getNoteLayer();
     33        if (layer == null) {
    3834            Logging.error("No note layer found");
    3935            return;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java

    r13352 r13437  
    134134
    135135            noteLayer = new NoteLayer(notesData, tr("Notes"));
    136             List<NoteLayer> noteLayers = MainApplication.getLayerManager().getLayersOfType(NoteLayer.class);
    137             if (!noteLayers.isEmpty()) {
    138                 noteLayers.get(0).getNoteData().addNotes(notesData);
     136            NoteLayer l = MainApplication.getLayerManager().getNoteLayer();
     137            if (l != null) {
     138                l.mergeFrom(noteLayer);
    139139                MapFrame map = MainApplication.getMap();
    140140                if (map != null && zoomAfterDownload) {
  • trunk/src/org/openstreetmap/josm/data/osm/NoteData.java

    r12743 r13437  
    119119        }
    120120        return false;
     121    }
     122
     123    /**
     124     * Merge notes from an existing note data.
     125     * @param from existing note data
     126     * @since 13437
     127     */
     128    public synchronized void mergeFrom(NoteData from) {
     129        if (this != from) {
     130            addNotes(from.noteList);
     131        }
    121132    }
    122133
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/NoteImporter.java

    r13352 r13437  
    6868            throws SAXException, IOException {
    6969        final List<Note> fileNotes = new NoteReader(in).parse();
    70         List<NoteLayer> noteLayers = null;
    71         if (MainApplication.getMap() != null) {
    72             noteLayers = MainApplication.getLayerManager().getLayersOfType(NoteLayer.class);
    73         }
    74         final NoteLayer layer;
    75         if (noteLayers != null && !noteLayers.isEmpty()) {
    76             layer = noteLayers.get(0);
     70        NoteLayer layer = MainApplication.getLayerManager().getNoteLayer();
     71        if (layer != null) {
    7772            layer.getNoteData().addNotes(fileNotes);
    7873        } else {
  • trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java

    r13435 r13437  
    421421            return null;
    422422        }
     423    }
     424
     425    /**
     426     * Returns the unique note layer, if present.
     427     * @return the unique note layer, or null
     428     * @since 13437
     429     */
     430    public NoteLayer getNoteLayer() {
     431        List<NoteLayer> col = getLayersOfType(NoteLayer.class);
     432        return col.isEmpty() ? null : col.get(0);
    423433    }
    424434
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r13206 r13437  
    349349    @Override
    350350    public String getToolTipText() {
    351         return trn("{0} note", "{0} notes", noteData.getNotes().size(), noteData.getNotes().size());
     351        int size = noteData.getNotes().size();
     352        return trn("{0} note", "{0} notes", size, size);
    352353    }
    353354
    354355    @Override
    355356    public void mergeFrom(Layer from) {
    356         throw new UnsupportedOperationException("Notes layer does not support merging yet");
     357        if (from instanceof NoteLayer && this != from) {
     358            noteData.mergeFrom(((NoteLayer) from).noteData);
     359        }
    357360    }
    358361
Note: See TracChangeset for help on using the changeset viewer.