Changeset 1881 in josm
- Timestamp:
- 2009-08-02T18:02:44+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r1872 r1881 10 10 import java.util.List; 11 11 12 import javax.swing.JOptionPane;13 14 import org.openstreetmap.josm.Main;15 12 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList; 16 13 import org.openstreetmap.josm.data.osm.DataSource; 17 import org.openstreetmap.josm.gui.OptionPaneUtil;18 14 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 19 15 import org.openstreetmap.josm.tools.Shortcut; … … 43 39 if (! isEnabled()) 44 40 return; 41 if (getEditLayer() == null) 42 return; 43 45 44 int bboxCount = 0; 46 45 List<Area> areas = new ArrayList<Area>(); 47 for(DataSource ds : Main.map.mapView.getEditLayer().data.dataSources) {46 for(DataSource ds : getEditLayer().data.dataSources) { 48 47 areas.add(new Area(ds.bounds.asRect())); 49 48 } … … 73 72 74 73 if(bboxCount == 0) { 75 OptionPaneUtil.showMessageDialog( 76 Main.parent, 77 tr("No data to update found. Have you already opened or downloaded a data layer?"), 78 tr("No data"), 79 JOptionPane.WARNING_MESSAGE 80 ); 81 return; 74 // no bounds defined in the dataset? we update all primitives in the data set 75 // using a series of multi fetch requests 76 // 77 new UpdateSelectionAction().updatePrimitives(getEditLayer().data.allPrimitives()); 78 } else { 79 // bounds defined? => use the bbox downloader 80 // 81 new DownloadOsmTaskList().download(false, areas, new PleaseWaitProgressMonitor()); 82 82 } 83 84 new DownloadOsmTaskList().download(false, areas, new PleaseWaitProgressMonitor());85 83 } 86 84 } -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1865 r1881 8 8 import java.io.IOException; 9 9 import java.util.Collection; 10 import java.util.HashSet; 11 import java.util.Set; 10 import java.util.Collections; 12 11 13 12 import javax.swing.JOptionPane; … … 15 14 import org.openstreetmap.josm.Main; 16 15 import org.openstreetmap.josm.data.osm.DataSet; 16 import org.openstreetmap.josm.data.osm.Node; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.data.osm.Relation; 19 import org.openstreetmap.josm.data.osm.Way; 20 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 21 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 18 22 import org.openstreetmap.josm.gui.OptionPaneUtil; 19 23 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 21 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 22 26 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 23 import org.openstreetmap.josm.io.OsmApi;24 27 import org.openstreetmap.josm.io.OsmTransferException; 25 28 import org.openstreetmap.josm.tools.Shortcut; … … 28 31 /** 29 32 * This action synchronizes a set of primitives with their state on the server. 30 *31 33 * 32 34 */ … … 45 47 ds = reader.parseOsm(NullProgressMonitor.INSTANCE); 46 48 } catch(Exception e) { 47 handleUpdateException(e); 48 return; 49 ExceptionDialogUtil.explainException(e); 49 50 } 50 51 Main.map.mapView.getEditLayer().mergeFrom(ds); 51 }52 53 54 /**55 * handle an exception thrown during updating a primitive56 *57 * @param id the id of the primitive58 * @param e the exception59 */60 protected void handleUpdateException(Exception e) {61 e.printStackTrace();62 OptionPaneUtil.showMessageDialog(63 Main.parent,64 tr("Failed to update the selected primitives."),65 tr("Update failed"),66 JOptionPane.ERROR_MESSAGE67 );68 }69 70 /**71 * handles an exception case: primitive with id <code>id</code> is not in the current72 * data set73 *74 * @param id the primitive id75 */76 protected void handleMissingPrimitive(long id) {77 OptionPaneUtil.showMessageDialog(78 Main.parent,79 tr("Could not find primitive with id {0} in the current dataset", new Long(id).toString()),80 tr("Missing primitive"),81 JOptionPane.ERROR_MESSAGE82 );83 52 } 84 53 … … 91 60 */ 92 61 public void updatePrimitives(final Collection<OsmPrimitive> selection) { 93 94 /** 95 * The asynchronous task for updating the data using multi fetch. 96 * 97 */ 98 class UpdatePrimitiveTask extends PleaseWaitRunnable { 99 private DataSet ds; 100 private boolean cancelled; 101 Exception lastException; 102 103 public UpdatePrimitiveTask() { 104 super("Update primitives", false /* don't ignore exception*/); 105 cancelled = false; 106 } 107 108 protected void showLastException() { 109 String msg = lastException.getMessage(); 110 if (msg == null) { 111 msg = lastException.toString(); 112 } 113 OptionPaneUtil.showMessageDialog( 114 Main.map, 115 msg, 116 tr("Error"), 117 JOptionPane.ERROR_MESSAGE 118 ); 119 } 120 121 @Override 122 protected void cancel() { 123 cancelled = true; 124 OsmApi.getOsmApi().cancel(); 125 } 126 127 @Override 128 protected void finish() { 129 if (cancelled) 130 return; 131 if (lastException != null) { 132 showLastException(); 133 return; 134 } 135 if (ds != null) { 136 Main.map.mapView.getEditLayer().mergeFrom(ds); 137 } 138 } 139 140 @Override 141 protected void realRun() throws SAXException, IOException, OsmTransferException { 142 progressMonitor.indeterminateSubTask(""); 143 try { 144 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 145 reader.append(selection); 146 ds = reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 147 } catch(Exception e) { 148 if (cancelled) 149 return; 150 lastException = e; 151 } 152 } 153 } 154 155 Main.worker.submit(new UpdatePrimitiveTask()); 62 UpdatePrimitivesTask task = new UpdatePrimitivesTask(selection); 63 Main.worker.submit(task); 156 64 } 157 65 … … 161 69 * 162 70 * @param id the id of a primitive in the {@see DataSet} of the current edit layser 163 * 164 */ 165 public void updatePrimitive(long id) { 166 OsmPrimitive primitive = Main.map.mapView.getEditLayer().data.getPrimitiveById(id); 167 Set<OsmPrimitive> s = new HashSet<OsmPrimitive>(); 168 s.add(primitive); 169 updatePrimitives(s); 71 * @exception IllegalStateException thrown if there is no primitive with <code>id</code> in 72 * the current dataset 73 * @exception IllegalStateException thrown if there is no current dataset 74 * 75 */ 76 public void updatePrimitive(long id) throws IllegalStateException{ 77 if (getEditLayer() == null) 78 throw new IllegalStateException(tr("No current dataset found")); 79 OsmPrimitive primitive = getEditLayer().data.getPrimitiveById(id); 80 if (primitive == null) 81 throw new IllegalStateException(tr("Didn't find a primitive with id {0} in the current dataset", id)); 82 updatePrimitives(Collections.singleton(primitive)); 170 83 } 171 84 … … 213 126 updatePrimitives(selection); 214 127 } 128 129 /** 130 * The asynchronous task for updating the data using multi fetch. 131 * 132 */ 133 class UpdatePrimitivesTask extends PleaseWaitRunnable { 134 private DataSet ds; 135 private boolean canceled; 136 private Exception lastException; 137 private Collection<? extends OsmPrimitive> toUpdate; 138 private MultiFetchServerObjectReader reader; 139 140 public UpdatePrimitivesTask(Collection<? extends OsmPrimitive> toUpdate) { 141 super("Update primitives", false /* don't ignore exception*/); 142 canceled = false; 143 this.toUpdate = toUpdate; 144 } 145 146 @Override 147 protected void cancel() { 148 canceled = true; 149 if (reader != null) { 150 reader.cancel(); 151 } 152 } 153 154 @Override 155 protected void finish() { 156 if (canceled) 157 return; 158 if (lastException != null) { 159 ExceptionDialogUtil.explainException(lastException); 160 return; 161 } 162 if (ds != null) { 163 Main.map.mapView.getEditLayer().mergeFrom(ds); 164 } 165 } 166 167 protected void initMultiFetchReaderWithNodes(MultiFetchServerObjectReader reader) { 168 for (OsmPrimitive primitive : toUpdate) { 169 if (primitive instanceof Node && primitive.id > 0) { 170 reader.append((Node)primitive); 171 } else if (primitive instanceof Way) { 172 Way way = (Way)primitive; 173 for (Node node: way.nodes) { 174 reader.append(node); 175 } 176 } 177 } 178 } 179 180 protected void initMultiFetchReaderWithWays(MultiFetchServerObjectReader reader) { 181 for (OsmPrimitive primitive : toUpdate) { 182 if (primitive instanceof Way && primitive.id > 0) { 183 reader.append((Way)primitive); 184 } 185 } 186 } 187 188 protected void initMultiFetchReaderWithRelations(MultiFetchServerObjectReader reader) { 189 for (OsmPrimitive primitive : toUpdate) { 190 if (primitive instanceof Relation && primitive.id > 0) { 191 reader.append((Relation)primitive); 192 } 193 } 194 } 195 196 @Override 197 protected void realRun() throws SAXException, IOException, OsmTransferException { 198 progressMonitor.indeterminateSubTask(""); 199 this.ds = new DataSet(); 200 DataSet theirDataSet; 201 try { 202 reader = new MultiFetchServerObjectReader(); 203 initMultiFetchReaderWithNodes(reader); 204 initMultiFetchReaderWithWays(reader); 205 initMultiFetchReaderWithRelations(reader); 206 theirDataSet = reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 207 MergeVisitor merger = new MergeVisitor(ds, theirDataSet); 208 merger.merge(); 209 } catch(Exception e) { 210 if (canceled) 211 return; 212 lastException = e; 213 } 214 } 215 } 215 216 } -
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r1811 r1881 63 63 private DataSet outputDataSet; 64 64 65 private boolean cancelled = false; 66 65 67 /** 66 68 * constructor … … 230 232 * 231 233 */ 232 public MultiFetchServerObjectReader append(Collection< OsmPrimitive> primitives) {234 public MultiFetchServerObjectReader append(Collection<? extends OsmPrimitive> primitives) { 233 235 if (primitives == null) return this; 234 236 for (OsmPrimitive primitive : primitives) { … … 363 365 for (long id : pkg) { 364 366 try { 367 progressMonitor.setCustomText(tr("Fetching {0} with id {1} from ''{2}''", type.getLocalizedDisplayNameSingular(), id, OsmApi.getOsmApi().getBaseUrl())); 365 368 singleGetId(type, id, progressMonitor); 366 369 } catch(OsmApiException e) { … … 394 397 */ 395 398 protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException{ 399 progressMonitor.setCustomText(tr("Fetching a package of {0} from ''{1}''", type.getLocalizedDisplayNameSingular(), OsmApi.getOsmApi().getBaseUrl())); 396 400 Set<Long> toFetch = new HashSet<Long>(ids); 397 401 toFetch.addAll(ids); 398 while(! toFetch.isEmpty() ) {402 while(! toFetch.isEmpty() && !isCanceled()) { 399 403 Set<Long> pkg = extractIdPackage(toFetch); 400 404 try { … … 435 439 try { 436 440 missingPrimitives = new HashSet<Long>(); 437 441 if (isCanceled())return null; 438 442 fetchPrimitives(nodes,OsmPrimitiveType.NODE, progressMonitor); 443 if (isCanceled())return null; 439 444 fetchPrimitives(ways,OsmPrimitiveType.WAY, progressMonitor); 445 if (isCanceled())return null; 440 446 fetchPrimitives(relations,OsmPrimitiveType.RELATION, progressMonitor); 441 447 return outputDataSet; -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r1811 r1881 145 145 con.addRequestProperty("Authorization", "Basic "+Base64.encode(bytes)); 146 146 } 147 148 /** 149 * Replies true if this connection is canceled 150 * 151 * @return true if this connection is canceled 152 * @return 153 */ 154 public boolean isCanceled() { 155 return cancel; 156 } 147 157 } -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r1814 r1881 329 329 for (Entry<OsmPrimitiveData, Collection<Long>> e : ways.entrySet()) { 330 330 Way w = new Way(e.getKey().id); 331 boolean failed= false;331 boolean incomplete = false; 332 332 for (long id : e.getValue()) { 333 333 Node n = findNode(id); 334 334 if (n == null) { 335 failed = true; 336 break; 335 n = new Node(id); 336 n.incomplete = true; 337 incomplete = true; 337 338 } 338 339 w.nodes.add(n); 339 340 } 340 if ( failed) {341 logger.warning(tr("marked way {0} incomplete because referred nodes are missing in the loaded data", e.getKey().id));341 if (incomplete) { 342 logger.warning(tr("marked way {0} with {1} nodes incomplete because at least one node was missing in the loaded data and is therefore incomplete too", e.getKey().id, w.nodes.size())); 342 343 e.getKey().copyTo(w); 343 344 w.incomplete = true; 344 w.nodes.clear();345 345 ds.addPrimitive(w); 346 346 } else {
Note:
See TracChangeset
for help on using the changeset viewer.