Changeset 7699 in josm for trunk/src


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

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

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
3 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}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/NoteDialog.java

    r7608 r7699  
    2828
    2929import org.openstreetmap.josm.Main;
     30import org.openstreetmap.josm.actions.UploadNotesAction;
    3031import org.openstreetmap.josm.actions.mapmode.AddNoteAction;
    3132import org.openstreetmap.josm.data.notes.Note;
     
    7374    private final NewAction newAction;
    7475    private final ReopenAction reopenAction;
     76    private final UploadNotesAction uploadAction;
    7577
    7678    private NoteData noteData;
     
    7981    public NoteDialog() {
    8082        super("Notes", "notes/note_open.png", "List of notes", null, 150);
    81         Main.debug("constructed note dialog");
     83        if (Main.isDebugEnabled()) {
     84            Main.debug("constructed note dialog");
     85        }
    8286
    8387        addCommentAction = new AddCommentAction();
     
    8589        newAction = new NewAction();
    8690        reopenAction = new ReopenAction();
     91        uploadAction = new UploadNotesAction();
    8792        buildDialog();
    8893    }
     
    114119                new SideButton(addCommentAction, false),
    115120                new SideButton(closeAction, false),
    116                 new SideButton(reopenAction, false)}));
     121                new SideButton(reopenAction, false),
     122                new SideButton(uploadAction, false)}));
    117123        updateButtonStates();
    118124    }
     
    132138            reopenAction.setEnabled(true);
    133139        }
     140        if(noteData == null || !noteData.isModified()) {
     141            uploadAction.setEnabled(false);
     142        } else {
     143            uploadAction.setEnabled(true);
     144        }
    134145    }
    135146
     
    149160    @Override
    150161    public void layerAdded(Layer newLayer) {
    151         Main.debug("layer added: " + newLayer);
     162        if (Main.isDebugEnabled()) {
     163            Main.debug("layer added: " + newLayer);
     164        }
    152165        if (newLayer instanceof NoteLayer) {
    153             Main.debug("note layer added");
     166            if (Main.isDebugEnabled()) {
     167                Main.debug("note layer added");
     168            }
    154169            noteData = ((NoteLayer)newLayer).getNoteData();
    155170            model.setData(noteData.getNotes());
     
    160175    public void layerRemoved(Layer oldLayer) {
    161176        if (oldLayer instanceof NoteLayer) {
    162             Main.debug("note layer removed. Clearing everything");
     177            if (Main.isDebugEnabled()) {
     178                Main.debug("note layer removed. Clearing everything");
     179            }
    163180            noteData = null;
    164181            model.clearData();
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r7608 r7699  
    7373    @Override
    7474    public boolean isModified() {
    75         for (Note note : noteData.getNotes()) {
    76             if (note.getId() < 0) { //notes with negative IDs are new
    77                 return true;
    78             }
    79             for (NoteComment comment : note.getComments()) {
    80                 if (comment.getIsNew()) {
    81                     return true;
    82                 }
    83             }
    84         }
    85         return false;
     75        return noteData.isModified();
    8676    }
    8777
Note: See TracChangeset for help on using the changeset viewer.