Changeset 6440 in josm
- Timestamp:
- 2013-12-05T22:20:57+01:00 (11 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java
r6336 r6440 4 4 import java.text.MessageFormat; 5 5 import java.util.ArrayList; 6 import java.util.Collection; 6 7 import java.util.HashMap; 8 import java.util.HashSet; 7 9 import java.util.List; 8 10 import java.util.Map; … … 10 12 11 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.osm.Changeset; 12 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 13 16 import org.openstreetmap.josm.data.osm.PrimitiveId; … … 17 20 import org.openstreetmap.josm.gui.layer.Layer; 18 21 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 import org.openstreetmap.josm.tools.Utils; 19 23 20 24 /** … … 43 47 private Map<PrimitiveId, ArrayList<HistoryOsmPrimitive>> data; 44 48 private CopyOnWriteArrayList<HistoryDataSetListener> listeners; 49 private Map<Long, Changeset> changesets; 45 50 46 51 /** … … 50 55 data = new HashMap<PrimitiveId, ArrayList<HistoryOsmPrimitive>>(); 51 56 listeners = new CopyOnWriteArrayList<HistoryDataSetListener>(); 57 changesets = new HashMap<Long, Changeset>(); 52 58 } 53 59 … … 117 123 118 124 /** 125 * Adds a changeset to the data set 126 * 127 * @param changeset the changeset to add 128 */ 129 public void putChangeset(Changeset changeset) { 130 changesets.put((long) changeset.getId(), changeset); 131 fireHistoryUpdated(null); 132 } 133 134 /** 119 135 * Replies the history for a given primitive with id <code>id</code> 120 136 * and type <code>type</code>. … … 149 165 if (versions == null) 150 166 return null; 167 for (HistoryOsmPrimitive i : versions) { 168 i.setChangeset(changesets.get(i.getChangesetId())); 169 } 151 170 return new History(pid.getUniqueId(), pid.getType(), versions); 152 171 } … … 160 179 if (other == null) 161 180 return; 162 for (PrimitiveId id : other.data.keySet()) { 163 this.data.put(id, other.data.get(id)); 164 } 181 this.data.putAll(other.data); 182 this.changesets.putAll(other.changesets); 165 183 fireHistoryUpdated(null); 184 } 185 186 public Collection<Long> getChangesetIds() { 187 final HashSet<Long> ids = new HashSet<Long>(); 188 for (Collection<HistoryOsmPrimitive> i : data.values()) { 189 for (HistoryOsmPrimitive j : i) { 190 ids.add(j.getChangesetId()); 191 } 192 } 193 return ids; 166 194 } 167 195 -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java
r6317 r6440 11 11 import java.util.Map; 12 12 13 import org.openstreetmap.josm.data.osm.Changeset; 13 14 import org.openstreetmap.josm.data.osm.Node; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 32 33 private User user; 33 34 private long changesetId; 35 private Changeset changeset; 34 36 private Date timestamp; 35 37 private long version; … … 171 173 public Map<String,String> getTags() { 172 174 return Collections.unmodifiableMap(tags); 175 } 176 177 public Changeset getChangeset() { 178 return changeset; 179 } 180 181 public void setChangeset(Changeset changeset) { 182 this.changeset = changeset; 173 183 } 174 184 -
trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java
r6316 r6440 10 10 import java.util.Collection; 11 11 import java.util.HashSet; 12 import java.util.List; 12 13 import java.util.Set; 13 14 15 import org.openstreetmap.josm.data.osm.Changeset; 14 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 17 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 21 23 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 22 24 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 25 import org.openstreetmap.josm.io.ChangesetQuery; 26 import org.openstreetmap.josm.io.OsmServerChangesetReader; 23 27 import org.openstreetmap.josm.io.OsmServerHistoryReader; 24 28 import org.openstreetmap.josm.io.OsmTransferException; … … 201 205 reader = new OsmServerHistoryReader(pid.getType(), pid.getUniqueId()); 202 206 ds = reader.parseHistory(progressMonitor.createSubTaskMonitor(1, false)); 207 // load corresponding changesets (mostly for changeset comment) 208 for (final Changeset i : new OsmServerChangesetReader().queryChangesets( 209 new ChangesetQuery().forChangesetIds(ds.getChangesetIds()), progressMonitor.createSubTaskMonitor(1, false))) { 210 ds.putChangeset(i); 211 } 203 212 } catch(OsmTransferException e) { 204 213 if (canceled) -
trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java
r6340 r6440 5 5 6 6 import java.awt.BorderLayout; 7 import java.awt.Color; 7 8 import java.awt.GridBagConstraints; 8 9 import java.awt.GridBagLayout; … … 16 17 import javax.swing.JLabel; 17 18 import javax.swing.JPanel; 19 import javax.swing.JTextArea; 18 20 19 21 import org.openstreetmap.josm.Main; … … 39 41 private UrlLabel lblUser; 40 42 private UrlLabel lblChangeset; 43 private JTextArea lblChangesetComment; 41 44 42 45 protected void build() { … … 55 58 pnlUserAndChangeset.add(lblChangeset); 56 59 60 lblChangesetComment = new JTextArea(); 61 lblChangesetComment.setLineWrap(true); 62 lblChangesetComment.setEditable(false); 63 lblChangesetComment.setBackground(new Color(0, 0, 0, 0)); 64 57 65 setLayout(new GridBagLayout()); 58 66 GridBagConstraints gc = new GridBagConstraints(); … … 65 73 gc.weighty = 0.0; 66 74 add(pnlUserAndChangeset, gc); 75 gc.gridy = 2; 76 add(lblChangesetComment, gc); 67 77 } 68 78 … … 132 142 lblChangeset.setUrl(url); 133 143 lblChangeset.setDescription(Long.toString(getPrimitive().getChangesetId())); 144 final String comment = getPrimitive().getChangeset() != null ? getPrimitive().getChangeset().get("comment") : null; 145 lblChangesetComment.setText(comment); 146 lblChangesetComment.setToolTipText(tr("Changeset comment")); 134 147 135 148 try { -
trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java
r6258 r6440 10 10 import java.text.ParseException; 11 11 import java.text.SimpleDateFormat; 12 import java.util.Arrays; 13 import java.util.Collection; 14 import java.util.Collections; 12 15 import java.util.Date; 13 16 import java.util.HashMap; 17 import java.util.HashSet; 14 18 import java.util.Map; 15 19 import java.util.Map.Entry; … … 18 22 import org.openstreetmap.josm.data.coor.LatLon; 19 23 import org.openstreetmap.josm.tools.CheckParameterUtil; 24 import org.openstreetmap.josm.tools.Utils; 20 25 21 26 public class ChangesetQuery { … … 47 52 /** indicates whether only closed changesets are queried. null, if no restrictions regarding open changesets apply */ 48 53 private Boolean closed = null; 54 /** a collection of changeset ids to query for */ 55 private Collection<Long> changesetIds = null; 49 56 50 57 public ChangesetQuery() {} … … 227 234 228 235 /** 236 * Restricts the query to the given changeset ids (which are added to previously added ones). 237 * 238 * @param changesetIds the changeset ids 239 * @return the query object with the applied restriction 240 * @throws IllegalArgumentException thrown if changesetIds is null. 241 */ 242 public ChangesetQuery forChangesetIds(Collection<Long> changesetIds) { 243 CheckParameterUtil.ensureParameterNotNull(changesetIds, "changesetIds"); 244 this.changesetIds = changesetIds; 245 return this; 246 } 247 248 /** 229 249 * Replies the query string to be used in a query URL for the OSM API. 230 250 * … … 273 293 } 274 294 sb.append("closed=").append(Boolean.toString(closed)); 295 } else if (changesetIds != null) { 296 // since 2013-12-05, see https://github.com/openstreetmap/openstreetmap-website/commit/1d1f194d598e54a5d6fb4f38fb569d4138af0dc8 297 if (sb.length() > 0) { 298 sb.append("&"); 299 } 300 sb.append("changesets=").append(Utils.join(",", changesetIds)); 275 301 } 276 302 return sb.toString(); … … 366 392 } 367 393 368 protected ChangesetQuery crateFromMap(Map<String,String> queryParams) throws ChangesetQueryUrlException { 394 protected Collection<Long> parseLongs(String value) { 395 return value == null || value.isEmpty() 396 ? Collections.<Long>emptySet() : 397 new HashSet<Long>(Utils.transform(Arrays.asList(value.split(",")), new Utils.Function<String, Long>() { 398 @Override 399 public Long apply(String x) { 400 return Long.valueOf(x); 401 } 402 })); 403 } 404 405 protected ChangesetQuery createFromMap(Map<String, String> queryParams) throws ChangesetQueryUrlException { 369 406 ChangesetQuery csQuery = new ChangesetQuery(); 370 407 … … 401 438 throw new ChangesetQueryUrlException(e); 402 439 } 440 } else if (k.equals("changesets")) { 441 try { 442 csQuery.forChangesetIds(parseLongs(entry.getValue())); 443 } catch (NumberFormatException e) { 444 throw new ChangesetQueryUrlException(e); 445 } 403 446 } else 404 447 throw new ChangesetQueryUrlException(tr("Unsupported parameter ''{0}'' in changeset query string", k)); … … 412 455 for (String keyValuePair: keyValuePairs) { 413 456 String[] kv = keyValuePair.split("="); 414 queryParams.put(kv[0], kv [1]);457 queryParams.put(kv[0], kv.length > 1 ? kv[1] : ""); 415 458 } 416 459 return queryParams; … … 441 484 return new ChangesetQuery(); 442 485 Map<String,String> queryParams = createMapFromQueryString(query); 443 return cr ateFromMap(queryParams);486 return createFromMap(queryParams); 444 487 } 445 488 } -
trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.groovy
r2915 r6440 189 189 } 190 190 } 191 192 @Test 193 public void test_changeset_ids() { 194 ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser(); 195 def ChangesetQuery q 196 197 // OK 198 q = parser.parse("changesets=1,2,3") 199 assert q != null 200 assert q.@changesetIds.containsAll(Arrays.asList(1L, 2L, 3L)) 201 assert q.@changesetIds.size() == 3 202 203 // OK 204 q = parser.parse("changesets=1,2,3,4,1") 205 assert q != null 206 assert q.@changesetIds.containsAll(Arrays.asList(1L, 2L, 3L, 4L)) 207 assert q.@changesetIds.size() == 4 208 209 // OK 210 q = parser.parse("changesets=") 211 assert q != null 212 assert q.@changesetIds.size() == 0 213 214 // should fail 215 shouldFail(ChangesetQueryUrlException) { 216 q = parser.parse("changesets=foo") 217 } 218 } 191 219 }
Note:
See TracChangeset
for help on using the changeset viewer.