Changeset 8224 in josm for trunk/src


Ignore:
Timestamp:
2015-04-18T22:37:12+02:00 (9 years ago)
Author:
simon04
Message:

see #10980 - Note download: update already downloaded non-modified notes; use Storage for internal storage

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/NoteData.java

    r7937 r8224  
    33
    44import java.util.ArrayList;
     5import java.util.Collection;
    56import java.util.Collections;
    67import java.util.Comparator;
    78import java.util.Date;
    8 import java.util.List;
    99import java.util.Map;
    1010
     
    1515import org.openstreetmap.josm.data.notes.NoteComment;
    1616import org.openstreetmap.josm.gui.JosmUserIdentityManager;
     17import org.openstreetmap.josm.tools.Predicate;
     18import org.openstreetmap.josm.tools.Utils;
    1719
    1820/**
     
    2325    private long newNoteId = -1;
    2426
    25     private final List<Note> noteList;
     27    private final Storage<Note> noteList;
    2628    private Note selectedNote = null;
    2729    private Comparator<Note> comparator = DEFAULT_COMPARATOR;
     
    8587
    8688    /**
    87      * Construct a new note container with an empty note list
    88      */
    89     public NoteData() {
    90         noteList = new ArrayList<>();
    91     }
    92 
    93     /**
    9489     * Construct a new note container with a given list of notes
    9590     * @param notes The list of notes to populate the container with
    9691     */
    97     public NoteData(List<Note> notes) {
    98         noteList = notes;
    99         Collections.sort(notes, comparator);
     92    public NoteData(Collection<Note> notes) {
     93        noteList = new Storage<>();
    10094        for (Note note : notes) {
     95            noteList.add(note);
    10196            if (note.getId() <= newNoteId) {
    10297                newNoteId = note.getId() - 1;
     
    107102    /**
    108103     * Returns the notes stored in this layer
    109      * @return List of Note objects
    110      */
    111     public List<Note> getNotes() {
    112         return noteList;
     104     * @return collection of notes
     105     */
     106    public Collection<Note> getNotes() {
     107        return Collections.unmodifiableCollection(noteList);
     108    }
     109
     110    /**
     111     * Returns the notes stored in this layer sorted according to {@link #comparator}
     112     * @return sorted collection of notes
     113     */
     114    public Collection<Note> getSortedNotes() {
     115        final ArrayList<Note> list = new ArrayList<>(noteList);
     116        Collections.sort(list, comparator);
     117        return list;
    113118    }
    114119
     
    155160     * @param newNotes A list of notes to add
    156161     */
    157     public synchronized void addNotes(List<Note> newNotes) {
     162    public synchronized void addNotes(Collection<Note> newNotes) {
    158163        for (Note newNote : newNotes) {
    159164            if (!noteList.contains(newNote)) {
    160165                noteList.add(newNote);
     166            } else {
     167                final Note existingNote = noteList.get(newNote);
     168                final boolean isDirty = Utils.exists(existingNote.getComments(), new Predicate<NoteComment>() {
     169                    @Override
     170                    public boolean evaluate(NoteComment object) {
     171                        return object.getIsNew();
     172                    }
     173                });
     174                if (!isDirty) {
     175                    noteList.put(newNote);
     176                } else {
     177                    // TODO merge comments?
     178                    Main.info("Keeping existing note id={0} with uncommitted changes", String.valueOf(newNote.getId()));
     179                }
    161180            }
    162181            if (newNote.getId() <= newNoteId) {
     
    165184        }
    166185        dataUpdated();
    167         if (Main.isDebugEnabled()) {
    168             Main.debug("notes in current set: " + noteList.size());
    169         }
    170186    }
    171187
     
    256272
    257273    private void dataUpdated() {
    258         Collections.sort(noteList, comparator);
    259         Main.map.noteDialog.setNoteList(noteList);
     274        Main.map.noteDialog.setNotes(getSortedNotes());
    260275        Main.map.mapView.repaint();
    261276    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

    r8212 r8224  
    1313import java.util.ArrayList;
    1414import java.util.Arrays;
     15import java.util.Collection;
    1516import java.util.List;
    1617
     
    186187            noteData = ((NoteLayer)newLayer).getNoteData();
    187188            model.setData(noteData.getNotes());
    188             setNoteList(noteData.getNotes());
     189            setNotes(noteData.getSortedNotes());
    189190        }
    190191    }
     
    193194    public void layerRemoved(Layer oldLayer) {
    194195        if (oldLayer instanceof NoteLayer) {
    195             if (Main.isDebugEnabled()) {
    196                 Main.debug("note layer removed. Clearing everything");
    197             }
    198196            noteData = null;
    199197            model.clearData();
     
    209207     * @param noteList List of notes to display
    210208     */
    211     public void setNoteList(List<Note> noteList) {
     209    public void setNotes(Collection<Note> noteList) {
    212210        model.setData(noteList);
    213211        updateButtonStates();
     
    265263
    266264        public NoteTableModel() {
    267             data = new ArrayList<Note>();
     265            data = new ArrayList<>();
    268266        }
    269267
     
    281279        }
    282280
    283         public void setData(List<Note> noteList) {
     281        public void setData(Collection<Note> noteList) {
    284282            data.clear();
    285283            data.addAll(noteList);
     
    315313            dialog.showNoteDialog(tr("Add comment to note:"), NotesDialog.ICON_COMMENT);
    316314            if (dialog.getValue() != 1) {
    317                 Main.debug("User aborted note reopening");
    318315                return;
    319316            }
     
    337334            dialog.showNoteDialog(tr("Close note with message:"), NotesDialog.ICON_CLOSED);
    338335            if (dialog.getValue() != 1) {
    339                 Main.debug("User aborted note closing");
    340336                return;
    341337            }
     
    377373            dialog.showNoteDialog(tr("Reopen note with message:"), NotesDialog.ICON_OPEN);
    378374            if (dialog.getValue() != 1) {
    379                 Main.debug("User aborted note reopening");
    380375                return;
    381376            }
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r8214 r8224  
    1313import java.text.DateFormat;
    1414import java.util.ArrayList;
     15import java.util.Collection;
     16import java.util.Collections;
    1517import java.util.List;
    1618
     
    5658     * @param name The name of the layer. Typically "Notes"
    5759     */
    58     public NoteLayer(List<Note> notes, String name) {
     60    public NoteLayer(Collection<Note> notes, String name) {
    5961        super(name);
    6062        noteData = new NoteData(notes);
     
    6365    /** Convenience constructor that creates a layer with an empty note list */
    6466    public NoteLayer() {
    65         super(tr("Notes"));
    66         noteData = new NoteData();
     67        this(Collections.<Note>emptySet(), tr("Notes"));
    6768    }
    6869
     
    9798    @Override
    9899    public boolean requiresSaveToFile() {
    99         Main.debug("associated notes file: " + getAssociatedFile());
    100100        return getAssociatedFile() != null && isModified();
    101101    }
  • trunk/src/org/openstreetmap/josm/io/NoteReader.java

    r7732 r8224  
    195195        @Override
    196196        public void endDocument() throws SAXException  {
    197             Main.info("parsed notes: " + notes.size());
    198197            parsedNotes = notes;
    199198        }
     
    210209                return sdf.parse(dateStr);
    211210            } catch(ParseException e) {
    212                 Main.error("error parsing date in note parser");
     211                Main.error(e);
    213212                return null;
    214213            }
Note: See TracChangeset for help on using the changeset viewer.