Ignore:
Timestamp:
2014-11-03T09:48:03+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #10700 - Add note upload functionality (patch by ToeBee)

File:
1 edited

Legend:

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

    r7608 r7699  
    55import java.util.Date;
    66import java.util.List;
     7import java.util.Map;
    78
    89import org.openstreetmap.josm.Main;
     
    5960    public void setSelectedNote(Note note) {
    6061        selectedNote = note;
    61         Main.map.noteDialog.selectionChanged();
    62         Main.map.mapView.repaint();
     62        if (Main.map != null) {
     63            Main.map.noteDialog.selectionChanged();
     64            Main.map.mapView.repaint();
     65        }
     66    }
     67
     68    /**
     69     * Return whether or not there are any changes in the note data set.
     70     * These changes may need to be either uploaded or saved.
     71     * @return true if local modifications have been made to the note data set. False otherwise.
     72     */
     73    public synchronized boolean isModified() {
     74        for (Note note : noteList) {
     75            if (note.getId() < 0) { //notes with negative IDs are new
     76                return true;
     77            }
     78            for (NoteComment comment : note.getComments()) {
     79                if (comment.getIsNew()) {
     80                    return true;
     81                }
     82            }
     83        }
     84        return false;
    6385    }
    6486
     
    6789     * @param newNotes A list of notes to add
    6890     */
    69     public void addNotes(List<Note> newNotes) {
     91    public synchronized void addNotes(List<Note> newNotes) {
    7092        for (Note newNote : newNotes) {
    7193            if (!noteList.contains(newNote)) {
     
    7799        }
    78100        dataUpdated();
    79         Main.debug("notes in current set: " + noteList.size());
     101        if (Main.isDebugEnabled()) {
     102            Main.debug("notes in current set: " + noteList.size());
     103        }
    80104    }
    81105
     
    85109     * @param text Required comment with which to open the note
    86110     */
    87     public void createNote(LatLon location, String text) {
     111    public synchronized void createNote(LatLon location, String text) {
    88112        if(text == null || text.isEmpty()) {
    89113            throw new IllegalArgumentException("Comment can not be blank when creating a note");
     
    95119        NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.opened, true);
    96120        note.addComment(comment);
    97         Main.debug("Created note {0} with comment: {1}", note.getId(), text);
     121        if (Main.isDebugEnabled()) {
     122            Main.debug("Created note {0} with comment: {1}", note.getId(), text);
     123        }
    98124        noteList.add(note);
    99125        dataUpdated();
     
    105131     * @param text Comment to add
    106132     */
    107     public void addCommentToNote(Note note, String text) {
     133    public synchronized void addCommentToNote(Note note, String text) {
    108134        if (!noteList.contains(note)) {
    109135            throw new IllegalArgumentException("Note to modify must be in layer");
     
    112138            throw new IllegalStateException("Cannot add a comment to a closed note");
    113139        }
    114         Main.debug("Adding comment to note {0}: {1}", note.getId(), text);
     140        if (Main.isDebugEnabled()) {
     141            Main.debug("Adding comment to note {0}: {1}", note.getId(), text);
     142        }
    115143        NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.commented, true);
    116144        note.addComment(comment);
     
    123151     * @param text Comment to attach to close action, if desired
    124152     */
    125     public void closeNote(Note note, String text) {
     153    public synchronized void closeNote(Note note, String text) {
    126154        if (!noteList.contains(note)) {
    127155            throw new IllegalArgumentException("Note to close must be in layer");
     
    130158            throw new IllegalStateException("Cannot close a note that isn't open");
    131159        }
    132         Main.debug("closing note {0} with comment: {1}", note.getId(), text);
     160        if (Main.isDebugEnabled()) {
     161            Main.debug("closing note {0} with comment: {1}", note.getId(), text);
     162        }
    133163        NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.closed, true);
    134164        note.addComment(comment);
     
    143173     * @param text Comment to attach to the reopen action, if desired
    144174     */
    145     public void reOpenNote(Note note, String text) {
     175    public synchronized void reOpenNote(Note note, String text) {
    146176        if (!noteList.contains(note)) {
    147177            throw new IllegalArgumentException("Note to reopen must be in layer");
     
    150180            throw new IllegalStateException("Cannot reopen a note that isn't closed");
    151181        }
    152         Main.debug("reopening note {0} with comment: {1}", note.getId(), text);
     182        if (Main.isDebugEnabled()) {
     183            Main.debug("reopening note {0} with comment: {1}", note.getId(), text);
     184        }
    153185        NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.reopened, true);
    154186        note.addComment(comment);
     
    166198        return User.createOsmUser(userMgr.getUserId(), userMgr.getUserName());
    167199    }
     200
     201    /**
     202     * Updates notes with new state. Primarily to be used when updating the
     203     * note layer after uploading note changes to the server.
     204     * @param updatedNotes Map containing the original note as the key and the updated note as the value
     205     */
     206    public synchronized void updateNotes(Map<Note, Note> updatedNotes) {
     207        for (Map.Entry<Note, Note> entry : updatedNotes.entrySet()) {
     208            Note oldNote = entry.getKey();
     209            Note newNote = entry.getValue();
     210            oldNote.updateWith(newNote);
     211        }
     212        dataUpdated();
     213    }
    168214}
Note: See TracChangeset for help on using the changeset viewer.