Skip to content

Commit

Permalink
Handle empty firstComment of a Note
Browse files Browse the repository at this point in the history
Resolves #27
  • Loading branch information
kmpoppe committed Apr 21, 2023
1 parent b27f78d commit b97df9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private List<JMenuItem> mainMenuEntries(Enum<menuTypes> menuType) {
returnList.add(
createMenuItem(
NoteText.noteShortText(note),
note.getFirstComment().toString(),
(note.getFirstComment() != null ? note.getFirstComment().toString() : ""),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package org.openstreetmap.josm.plugins.notesolver;

import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.data.notes.*;

public class NoteText {
private static int maxMenuItemLen = 50;
public static String noteShortText(Note n) {
String firstComment = n.getFirstComment().toString();
if (firstComment.length() > maxMenuItemLen) firstComment = firstComment.substring(0, maxMenuItemLen) + "...";
String firstComment = "";
String firstUser = "";
if (n.getFirstComment() != null) {
firstUser = n.getFirstComment().getUser().getName().toString();
firstComment = n.getFirstComment().toString();
if (firstComment.length() > maxMenuItemLen) firstComment = firstComment.substring(0, maxMenuItemLen) + "...";
} else {
firstUser = I18n.tr("Deleted user");
firstComment = I18n.tr("Deleted comment");
}
String menuItemText =
"* " + Long.toString(n.getId()) + " " +
"[" + n.getFirstComment().getUser().getName().toString() +
"[" + firstUser +
": " + firstComment +
"]";
return menuItemText;
Expand Down

0 comments on commit b97df9c

Please sign in to comment.