Changeset 5476 in josm
- Timestamp:
- 2012-08-25T16:06:22+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r5345 r5476 1 1 package org.openstreetmap.josm.actions.downloadtasks; 2 2 3 import java.util.ArrayList;4 3 import java.util.Date; 5 import java.util.Hash Set;4 import java.util.HashMap; 6 5 import java.util.Iterator; 7 6 import java.util.List; 8 import java.util. Set;7 import java.util.Map; 9 8 import java.util.concurrent.Future; 10 9 … … 12 11 import org.openstreetmap.josm.data.Bounds; 13 12 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.data.osm.Node; 14 14 import org.openstreetmap.josm.data.osm.NodeData; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 17 import org.openstreetmap.josm.data.osm.PrimitiveData; 17 18 import org.openstreetmap.josm.data.osm.PrimitiveId; 18 19 import org.openstreetmap.josm.data.osm.RelationData; 20 import org.openstreetmap.josm.data.osm.RelationMemberData; 19 21 import org.openstreetmap.josm.data.osm.WayData; 20 22 import org.openstreetmap.josm.data.osm.history.History; … … 30 32 import org.openstreetmap.josm.io.OsmServerReader; 31 33 import org.openstreetmap.josm.io.OsmTransferException; 32 import org.openstreetmap.josm.tools.Pair;33 34 34 35 public class DownloadOsmChangeTask extends DownloadOsmTask { … … 89 90 return; // user canceled download or error occurred 90 91 try { 91 // A changeset does not contain all referred primitives, this is the list of incomplete ones 92 Set<OsmPrimitive> toLoad = new HashSet<OsmPrimitive>(); 92 // A changeset does not contain all referred primitives, this is the map of incomplete ones 93 93 // For each incomplete primitive, we'll have to get its state at date it was referred 94 List<Pair<OsmPrimitive, Date>> toMonitor = new ArrayList<Pair<OsmPrimitive, Date>>();94 Map<OsmPrimitive, Date> toLoad = new HashMap<OsmPrimitive, Date>(); 95 95 for (OsmPrimitive p : downloadedData.allNonDeletedPrimitives()) { 96 96 if (p.isIncomplete()) { … … 102 102 } 103 103 } 104 if (toLoad.add(p)) { 105 toMonitor.add(new Pair<OsmPrimitive, Date>(p, timestamp)); 106 } 104 toLoad.put(p, timestamp); 107 105 } 108 106 } 109 107 if (isCanceled()) return; 110 // Updating process is asynchronous and done after each history request111 HistoryDataSet.getInstance().addHistoryDataSetListener(new HistoryListener(toMonitor));112 108 // Let's load all required history 113 Main.worker.submit(new HistoryLoad Task().add(toLoad));109 Main.worker.submit(new HistoryLoaderAndListener(toLoad)); 114 110 } catch (Exception e) { 115 111 rememberException(e); … … 118 114 } 119 115 } 116 120 117 /** 121 * Asynchroneous updater of incomplete primitives. 122 * 118 * Loads history and updates incomplete primitives. 123 119 */ 124 private static class HistoryListener implements HistoryDataSetListener { 125 126 private final List<Pair<OsmPrimitive, Date>> toMonitor; 127 128 public HistoryListener(List<Pair<OsmPrimitive, Date>> toMonitor) { 129 this.toMonitor = toMonitor; 120 private static class HistoryLoaderAndListener extends HistoryLoadTask implements HistoryDataSetListener { 121 122 private final Map<OsmPrimitive, Date> toLoad; 123 124 public HistoryLoaderAndListener(Map<OsmPrimitive, Date> toLoad) { 125 this.toLoad = toLoad; 126 add(toLoad.keySet()); 127 // Updating process is done after all history requests have been made 128 HistoryDataSet.getInstance().addHistoryDataSetListener(this); 130 129 } 131 130 132 131 @Override 133 132 public void historyUpdated(HistoryDataSet source, PrimitiveId id) { 134 for (Iterator<Pair<OsmPrimitive, Date>> it = toMonitor.iterator(); it.hasNext();) { 135 Pair<OsmPrimitive, Date> pair = it.next(); 136 History history = source.getHistory(pair.a.getPrimitiveId()); 133 Map<OsmPrimitive, Date> toLoadNext = new HashMap<OsmPrimitive, Date>(); 134 for (Iterator<OsmPrimitive> it = toLoad.keySet().iterator(); it.hasNext();) { 135 OsmPrimitive p = it.next(); 136 History history = source.getHistory(p.getPrimitiveId()); 137 Date date = toLoad.get(p); 137 138 // If the history has been loaded and a timestamp is known 138 if (history != null && pair.b!= null) {139 if (history != null && date != null) { 139 140 // Lookup for the primitive version at the specified timestamp 140 HistoryOsmPrimitive hp = history.getByDate( pair.b);141 HistoryOsmPrimitive hp = history.getByDate(date); 141 142 if (hp != null) { 142 143 PrimitiveData data = null; 143 144 144 switch (p air.a.getType()) {145 switch (p.getType()) { 145 146 case NODE: 146 147 data = new NodeData(); … … 149 150 case WAY: 150 151 data = new WayData(); 151 ((WayData)data).setNodes(((HistoryWay)hp).getNodes()); 152 List<Long> nodeIds = ((HistoryWay)hp).getNodes(); 153 ((WayData)data).setNodes(nodeIds); 154 // Find incomplete nodes to load at next run 155 for (Long nodeId : nodeIds) { 156 if (p.getDataSet().getPrimitiveById(nodeId, OsmPrimitiveType.NODE) == null) { 157 Node n = new Node(nodeId); 158 p.getDataSet().addPrimitive(n); 159 toLoadNext.put(n, date); 160 } 161 } 152 162 break; 153 163 case RELATION: 154 164 data = new RelationData(); 155 ((RelationData)data).setMembers(((HistoryRelation)hp).getMembers()); 165 List<RelationMemberData> members = ((HistoryRelation)hp).getMembers(); 166 ((RelationData)data).setMembers(members); 156 167 break; 157 default: throw new AssertionError( );168 default: throw new AssertionError("Unknown primitive type"); 158 169 } 159 170 … … 162 173 data.setVisible(hp.isVisible()); 163 174 } catch (IllegalStateException e) { 164 System.err.println("Cannot change visibility for "+p air.a+": "+e.getMessage());175 System.err.println("Cannot change visibility for "+p+": "+e.getMessage()); 165 176 } 166 177 data.setTimestamp(hp.getTimestamp()); … … 169 180 170 181 // Load the history data 171 pair.a.load(data); 172 // Forget this primitive 173 it.remove(); 182 try { 183 p.load(data); 184 // Forget this primitive 185 it.remove(); 186 } catch (AssertionError e) { 187 System.err.println("Cannot load "+p + ": " + e.getMessage()); 188 } 174 189 } 175 190 } 176 191 } 177 if (toMonitor.isEmpty()) { 192 source.removeHistoryDataSetListener(this); 193 if (toLoadNext.isEmpty()) { 178 194 // No more primitive to update. Processing is finished 179 source.removeHistoryDataSetListener(this);180 195 // Be sure all updated primitives are correctly drawn 181 196 Main.map.repaint(); 197 } else { 198 // Some primitives still need to be loaded 199 // Let's load all required history 200 Main.worker.submit(new HistoryLoaderAndListener(toLoadNext)); 182 201 } 183 202 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java
r5266 r5476 178 178 loadedData = new HistoryDataSet(); 179 179 try { 180 progressMonitor.setTicksCount(toLoad.size()); 180 181 for(PrimitiveId pid: toLoad) { 181 182 if (canceled) {
Note:
See TracChangeset
for help on using the changeset viewer.