Changeset 7704 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-11-04T02:33:20+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Changeset.java
r7700 r7704 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import java.util.ArrayList; 4 5 import java.util.Collection; 6 import java.util.Collections; 5 7 import java.util.Date; 6 8 import java.util.HashMap; 9 import java.util.List; 7 10 import java.util.Map; 8 11 … … 39 42 /** the map of tags */ 40 43 private Map<String,String> tags; 41 /** indicates whether this changeset is incomplete. For an 42 * incomplete changeset we only know its id 43 */ 44 /** indicates whether this changeset is incomplete. For an incomplete changeset we only know its id */ 44 45 private boolean incomplete; 45 46 /** the changeset content */ 46 47 private ChangesetDataSet content = null; 48 /** the changeset discussion */ 49 private List<ChangesetDiscussionComment> discussion = null; 47 50 48 51 /** … … 328 331 this.content = content; 329 332 } 333 334 /** 335 * Replies the list of comments in the changeset discussion, if any. 336 * @return the list of comments in the changeset discussion. May be empty but never null 337 * @since 7704 338 */ 339 public synchronized final List<ChangesetDiscussionComment> getDiscussion() { 340 if (discussion == null) { 341 return Collections.emptyList(); 342 } 343 return new ArrayList<>(discussion); 344 } 345 346 /** 347 * Adds a comment to the changeset discussion. 348 * @param comment the comment to add. Ignored if null 349 * @since 7704 350 */ 351 public synchronized final void addDiscussionComment(ChangesetDiscussionComment comment) { 352 if (comment == null) { 353 return; 354 } 355 if (discussion == null) { 356 discussion = new ArrayList<>(); 357 } 358 discussion.add(comment); 359 } 330 360 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java
r7434 r7704 181 181 model.addPropertyChangeListener(pnlChangesetContent); 182 182 183 // -- add the panel for the changeset discussion 184 ChangesetDiscussionPanel pnlChangesetDiscussion = new ChangesetDiscussionPanel(); 185 tp.add(pnlChangesetDiscussion); 186 model.addPropertyChangeListener(pnlChangesetDiscussion); 187 183 188 tp.setTitleAt(0, tr("Properties")); 184 189 tp.setToolTipTextAt(0, tr("Display the basic properties of the changeset")); … … 187 192 tp.setTitleAt(2, tr("Content")); 188 193 tp.setToolTipTextAt(2, tr("Display the objects created, updated, and deleted by the changeset")); 194 tp.setTitleAt(3, tr("Discussion")); 195 tp.setToolTipTextAt(3, tr("Display the public discussion around this changeset")); 189 196 190 197 pnl.add(tp, BorderLayout.CENTER); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentDownloadTask.java
r7005 r7704 135 135 reader = new OsmServerChangesetReader(); 136 136 } 137 Changeset cs = reader.readChangeset(changesetId, getProgressMonitor().createSubTaskMonitor(0, false)); 137 Changeset cs = reader.readChangeset(changesetId, false, getProgressMonitor().createSubTaskMonitor(0, false)); 138 138 synchronized(this) { 139 139 reader = null; -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
r7509 r7704 53 53 54 54 /** 55 * The panel which displays the content of a changeset in a scollable table. 55 * The panel which displays the content of a changeset in a scrollable table. 56 56 * 57 57 * It listens to property change events for {@link ChangesetCacheManagerModel#CHANGESET_IN_DETAIL_VIEW_PROP} -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetHeaderDownloadTask.java
r7005 r7704 84 84 private Exception lastException; 85 85 private Set<Changeset> downloadedChangesets; 86 private final boolean includeDiscussion; 86 87 87 88 protected void init(Collection<Integer> ids) { … … 112 113 super(tr("Download changesets"), false /* don't ignore exceptions */); 113 114 init(ids); 115 this.includeDiscussion = false; 114 116 } 115 117 … … 125 127 */ 126 128 public ChangesetHeaderDownloadTask(Component dialogParent, Collection<Integer> ids) throws IllegalArgumentException{ 127 super(dialogParent,tr("Download changesets"), false /* don't ignore exceptions */); 129 this(dialogParent, ids, false); 130 } 131 132 /** 133 * Creates the download task for a collection of changeset ids, with possibility to download changeset discussion. 134 * Uses a {@link org.openstreetmap.josm.gui.PleaseWaitDialog} whose parent is the parent window of <code>dialogParent</code>. 135 * 136 * Null ids or or ids <= 0 in the id collection are ignored. 137 * 138 * @param dialogParent the parent reference component for the {@link org.openstreetmap.josm.gui.PleaseWaitDialog}. Must not be null. 139 * @param ids the collection of ids. Empty collection assumed if null. 140 * @param includeDiscussion determines if discussion comments must be downloaded or not 141 * @throws IllegalArgumentException thrown if dialogParent is null 142 * @since 7704 143 */ 144 public ChangesetHeaderDownloadTask(Component dialogParent, Collection<Integer> ids, boolean includeDiscussion) 145 throws IllegalArgumentException { 146 super(dialogParent, tr("Download changesets"), false /* don't ignore exceptions */); 128 147 init(ids); 148 this.includeDiscussion = includeDiscussion; 129 149 } 130 150 … … 180 200 } 181 201 downloadedChangesets = new HashSet<>(); 182 downloadedChangesets.addAll(reader.readChangesets(idsToDownload, getProgressMonitor().createSubTaskMonitor(0, false))); 202 downloadedChangesets.addAll(reader.readChangesets(idsToDownload, includeDiscussion, 203 getProgressMonitor().createSubTaskMonitor(0, false))); 183 204 } catch(OsmTransferException e) { 184 205 if (canceled) -
trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java
r7700 r7704 8 8 import java.nio.charset.StandardCharsets; 9 9 import java.text.MessageFormat; 10 import java.util.Date; 10 11 import java.util.LinkedList; 11 12 import java.util.List; … … 16 17 import org.openstreetmap.josm.data.coor.LatLon; 17 18 import org.openstreetmap.josm.data.osm.Changeset; 19 import org.openstreetmap.josm.data.osm.ChangesetDiscussionComment; 18 20 import org.openstreetmap.josm.data.osm.User; 19 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 70 72 private Changeset current = null; 71 73 74 /** The current comment */ 75 private ChangesetDiscussionComment comment = null; 76 77 /** The current comment text */ 78 private StringBuilder text = null; 79 72 80 protected void parseChangesetAttributes(Changeset cs, Attributes atts) throws XmlParsingException { 73 81 // -- id … … 78 86 current.setId(parseNumericAttribute(value, 1)); 79 87 80 // -- user 81 String user = atts.getValue("user"); 82 String uid = atts.getValue("uid"); 83 current.setUser(createUser(uid, user)); 88 // -- user / uid 89 current.setUser(createUser(atts)); 84 90 85 91 // -- created_at … … 155 161 } 156 162 163 private void parseCommentAttributes(Attributes atts) throws XmlParsingException { 164 // -- date 165 String value = atts.getValue("date"); 166 Date date = null; 167 if (value != null) { 168 date = DateUtils.fromString(value); 169 } 170 171 comment = new ChangesetDiscussionComment(date, createUser(atts)); 172 } 173 157 174 private int parseNumericAttribute(String value, int minAllowed) throws XmlParsingException { 158 175 int att = 0; … … 193 210 current.put(key, value); 194 211 break; 212 case "discussion": 213 break; 214 case "comment": 215 parseCommentAttributes(atts); 216 break; 217 case "text": 218 text = new StringBuilder(); 219 break; 195 220 default: 196 221 throwException(tr("Undefined element ''{0}'' found in input stream. Aborting.", qName)); 222 } 223 } 224 225 @Override 226 public void characters(char[] ch, int start, int length) throws SAXException { 227 if (text != null) { 228 text.append(ch, start, length); 197 229 } 198 230 } … … 202 234 if ("changeset".equals(qName)) { 203 235 changesets.add(current); 204 } 205 } 206 207 protected User createUser(String uid, String name) throws XmlParsingException { 236 current = null; 237 } else if ("comment".equals(qName)) { 238 current.addDiscussionComment(comment); 239 comment = null; 240 } else if ("text".equals(qName)) { 241 comment.setText(text.toString()); 242 text = null; 243 } 244 } 245 246 protected User createUser(Attributes atts) throws XmlParsingException { 247 String name = atts.getValue("user"); 248 String uid = atts.getValue("uid"); 208 249 if (uid == null) { 209 250 if (name == null) -
trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java
r7033 r7704 29 29 30 30 /** 31 * constructor 32 * 33 */ 34 public OsmServerChangesetReader(){ 31 * Constructs a new {@code OsmServerChangesetReader}. 32 */ 33 public OsmServerChangesetReader() { 35 34 setDoAuthenticate(false); 36 35 } … … 38 37 /** 39 38 * don't use - not implemented! 40 *41 39 */ 42 40 @Override 43 41 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 44 42 return null; 43 } 44 45 protected final InputStream getChangesetInputStream(long id, boolean includeDiscussion, ProgressMonitor monitor) 46 throws OsmTransferException { 47 StringBuilder sb = new StringBuilder(); 48 sb.append("changeset/").append(id); 49 if (includeDiscussion) { 50 sb.append("?include_discussion=true"); 51 } 52 return getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true)); 45 53 } 46 54 … … 82 90 83 91 /** 84 * Reads the changeset with id <code>id</code> from the server 92 * Reads the changeset with id <code>id</code> from the server. 85 93 * 86 * @param id the changeset id. id > 0 required. 94 * @param id the changeset id. id > 0 required. 95 * @param includeDiscussion determines if discussion comments must be downloaded or not 87 96 * @param monitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null 88 97 * @return the changeset read 89 98 * @throws OsmTransferException thrown if something goes wrong 90 99 * @throws IllegalArgumentException if id <= 0 91 */ 92 public Changeset readChangeset(long id, ProgressMonitor monitor) throws OsmTransferException { 100 * @since 7704 101 */ 102 public Changeset readChangeset(long id, boolean includeDiscussion, ProgressMonitor monitor) throws OsmTransferException { 93 103 if (id <= 0) 94 104 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got ''{1}''.", "id", id)); … … 99 109 try { 100 110 monitor.beginTask(tr("Reading changeset {0} ...",id)); 101 StringBuilder sb = new StringBuilder(); 102 sb.append("changeset/").append(id); 103 try (InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true))) { 111 try (InputStream in = getChangesetInputStream(id, includeDiscussion, monitor)) { 104 112 if (in == null) 105 113 return null; … … 123 131 124 132 /** 125 * Reads the changeset with id <code>id</code> from the server 133 * Reads the changesets with id <code>ids</code> from the server. 126 134 * 127 * @param ids the list of ids. Ignored if null. Only load changesets for ids > 0. 135 * @param ids the list of ids. Ignored if null. Only load changesets for ids > 0. 136 * @param includeDiscussion determines if discussion comments must be downloaded or not 128 137 * @param monitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null 129 138 * @return the changeset read 130 139 * @throws OsmTransferException thrown if something goes wrong 131 140 * @throws IllegalArgumentException if id <= 0 132 */ 133 public List<Changeset> readChangesets(Collection<Integer> ids, ProgressMonitor monitor) throws OsmTransferException { 141 * @since 7704 142 */ 143 public List<Changeset> readChangesets(Collection<Integer> ids, boolean includeDiscussion, ProgressMonitor monitor) throws OsmTransferException { 134 144 if (ids == null) 135 145 return Collections.emptyList(); … … 147 157 } 148 158 i++; 149 StringBuilder sb = new StringBuilder(); 150 sb.append("changeset/").append(id); 151 try (InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true))) { 159 try (InputStream in = getChangesetInputStream(id, includeDiscussion, monitor)) { 152 160 if (in == null) 153 161 return null;
Note:
See TracChangeset
for help on using the changeset viewer.