Changeset 2035 in josm
- Timestamp:
- 2009-09-03T13:02:19+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java
r2025 r2035 15 15 import org.openstreetmap.josm.data.osm.Way; 16 16 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 17 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 17 18 import org.openstreetmap.josm.io.OsmApi; 18 19 import org.openstreetmap.josm.io.OsmApiInitializationException; … … 24 25 OsmApi api = OsmApi.getOsmApi(); 25 26 try { 26 api.initialize( );27 api.initialize(NullProgressMonitor.INSTANCE); 27 28 long maxNodes = 0; 28 29 if (api.getCapabilities().isDefined("waynodes", "maximum")) { -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r2031 r2035 40 40 import org.openstreetmap.josm.io.OsmApiException; 41 41 import org.openstreetmap.josm.io.OsmApiInitializationException; 42 import org.openstreetmap.josm.io.OsmChangesetCloseException; 42 43 import org.openstreetmap.josm.io.OsmServerWriter; 43 44 import org.openstreetmap.josm.tools.GBC; … … 343 344 } 344 345 346 if (e instanceof OsmChangesetCloseException) { 347 ExceptionDialogUtil.explainOsmChangesetCloseException((OsmChangesetCloseException)e); 348 return; 349 } 345 350 if (e instanceof OsmApiException) { 346 351 OsmApiException ex = (OsmApiException)e; … … 493 498 ); 494 499 dialog.setButtonIcons(new String[] {"upload.png", "cancel.png"}); 495 dialog.setContent(p );500 dialog.setContent(p, false /* no scroll pane */); 496 501 dialog.showDialog(); 497 502 int result = dialog.getValue(); -
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r2002 r2035 17 17 import org.openstreetmap.josm.io.OsmApiException; 18 18 import org.openstreetmap.josm.io.OsmApiInitializationException; 19 import org.openstreetmap.josm.io.OsmChangesetCloseException; 19 20 import org.openstreetmap.josm.io.OsmTransferException; 20 21 … … 39 40 JOptionPane.showMessageDialog( 40 41 Main.parent, 41 tr( "Failed to initialize communication with the OSM server {0}.\n" 42 + "Check the server URL in your preferences and your internet connection.", 42 tr( "<html>Failed to initialize communication with the OSM server {0}.<br>" 43 + "Check the server URL in your preferences and your internet connection.</html>", 44 Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api") 45 ), 46 tr("Error"), 47 JOptionPane.ERROR_MESSAGE 48 ); 49 } 50 51 /** 52 * handles an exception caught during OSM API initialization 53 * 54 * @param e the exception 55 */ 56 public static void explainOsmChangesetCloseException(OsmChangesetCloseException e) { 57 e.printStackTrace(); 58 String changsetId = e.getChangeset() == null ? tr("unknown") : Long.toString(e.getChangeset().getId()); 59 JOptionPane.showMessageDialog( 60 Main.parent, 61 tr( "<html>Failed to close changeset ''{0}'' on the OSM server ''{1}''.<br>" 62 + "The changeset will automatically be closed by the server after a timeout.</html>", 63 changsetId, 43 64 Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api") 44 65 ), … … 275 296 return; 276 297 } 298 if (e instanceof OsmChangesetCloseException){ 299 explainOsmChangesetCloseException((OsmChangesetCloseException)e); 300 return; 301 } 302 277 303 if (e instanceof OsmApiException) { 278 304 OsmApiException oae = (OsmApiException)e; -
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r2031 r2035 4 4 5 5 import java.awt.Component; 6 import java.awt.Container; 6 7 import java.awt.Dimension; 7 8 import java.awt.Frame; … … 40 41 private final String[] bTexts; 41 42 private String[] bIcons; 43 /** 44 * set to true if the content of the extended dialog should 45 * be placed in a {@see JScrollPane} 46 */ 47 private boolean placeContentInScrollPane; 42 48 43 49 // For easy access when inherited … … 136 142 */ 137 143 public void setContent(Component content) { 144 setContent(content, true); 145 } 146 147 /** 148 * Sets the content that will be displayed in the message dialog. 149 * 150 * Note that depending on your other settings more UI elements may appear. 151 * The content is played on top of the other elements though. 152 * 153 * @param content Any element that can be displayed in the message dialog 154 * @param placeContentInScrollPane if true, places the content in a JScrollPane 155 * 156 */ 157 public void setContent(Component content, boolean placeContentInScrollPane) { 138 158 this.content = content; 159 this.placeContentInScrollPane = placeContentInScrollPane; 139 160 } 140 161 … … 149 170 */ 150 171 public void setContent(String message) { 151 setContent(string2label(message)); 152 } 153 154 172 setContent(string2label(message), true); 173 } 155 174 156 175 /** … … 222 241 223 242 cp.add(buttonsPanel, GBC.eol().anchor(GBC.CENTER).insets(5,5,5,5)); 224 225 JScrollPane pane = new JScrollPane(cp); 226 pane.setBorder(null); 227 setContentPane(pane); 228 243 if (placeContentInScrollPane) { 244 JScrollPane pane = new JScrollPane(cp); 245 pane.setBorder(null); 246 setContentPane(pane); 247 } else { 248 setContentPane(cp); 249 } 229 250 pack(); 230 251 -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2025 r2035 157 157 * @exception OsmApiInitializationException thrown, if an exception occurs 158 158 */ 159 public void initialize( ) throws OsmApiInitializationException {159 public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException { 160 160 if (initialized) 161 161 return; 162 162 initAuthentication(); 163 163 try { 164 String s = sendRequest("GET", "capabilities", null );164 String s = sendRequest("GET", "capabilities", null,monitor); 165 165 InputSource inputSource = new InputSource(new StringReader(s)); 166 166 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser()); … … 227 227 * @throws OsmTransferException if something goes wrong 228 228 */ 229 public void createPrimitive(OsmPrimitive osm ) throws OsmTransferException {230 initialize( );229 public void createPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 230 initialize(monitor); 231 231 String ret = ""; 232 232 try { 233 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true) );233 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true),monitor); 234 234 osm.id = Long.parseLong(ret.trim()); 235 235 osm.version = 1; … … 247 247 * @throws OsmTransferException if something goes wrong 248 248 */ 249 public void modifyPrimitive(OsmPrimitive osm ) throws OsmTransferException {250 initialize( );249 public void modifyPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 250 initialize(monitor); 251 251 if (version.equals("0.5")) { 252 252 // legacy mode does not return the new object version. 253 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true) );253 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true),monitor); 254 254 } else { 255 255 String ret = null; 256 256 // normal mode (0.6 and up) returns new object version. 257 257 try { 258 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true) );258 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor); 259 259 osm.version = Integer.parseInt(ret.trim()); 260 260 } catch(NumberFormatException e) { … … 270 270 */ 271 271 public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 272 initialize( );272 initialize(monitor); 273 273 // can't use a the individual DELETE method in the 0.6 API. Java doesn't allow 274 274 // submitting a DELETE request with content, the 0.6 API requires it, however. Falling back … … 291 291 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 292 292 changeset.put("comment", comment); 293 createPrimitive(changeset );293 createPrimitive(changeset, progressMonitor); 294 294 } finally { 295 295 progressMonitor.finishTask(); … … 305 305 progressMonitor.beginTask(tr("Closing changeset {0}...", changeset.getId())); 306 306 try { 307 initialize( );308 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null );307 initialize(progressMonitor); 308 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor); 309 309 changeset = null; 310 310 } finally { … … 327 327 throw new OsmTransferException(tr("No changeset present for diff upload")); 328 328 329 initialize( );329 initialize(progressMonitor); 330 330 final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>(); 331 331 … … 341 341 String diff = duv.getDocument(); 342 342 try { 343 String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff );343 String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff,progressMonitor); 344 344 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), 345 345 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); … … 358 358 359 359 360 private void sleepAndListen( ) throws OsmTransferCancelledException {360 private void sleepAndListen(int retry, ProgressMonitor monitor) throws OsmTransferCancelledException { 361 361 System.out.print(tr("Waiting 10 seconds ... ")); 362 362 for(int i=0; i < 10; i++) { 363 if (monitor != null) { 364 monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry,getMaxRetries(), 10-i)); 365 } 363 366 if (cancel || isAuthCancelled()) 364 367 throw new OsmTransferCancelledException(); … … 395 398 * been exhausted), or rewrapping a Java exception. 396 399 */ 397 private String sendRequest(String requestMethod, String urlSuffix, 398 String requestBody) throws OsmTransferException { 400 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException { 399 401 400 402 StringBuffer responseBody = new StringBuffer(); … … 436 438 if (retCode >= 500) { 437 439 if (retries-- > 0) { 438 sleepAndListen(); 439 int maxRetries = getMaxRetries(); 440 System.out.println(tr("Starting retry {0} of {1}.", maxRetries - retries,maxRetries)); 440 sleepAndListen(retries, monitor); 441 System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries,getMaxRetries())); 441 442 continue; 442 443 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r1875 r2035 40 40 protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 41 41 try { 42 api.initialize( );42 api.initialize(progressMonitor); 43 43 urlStr = api.getBaseUrl() + urlStr; 44 44 return getInputStreamRaw(urlStr, progressMonitor); -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r2025 r2035 125 125 } 126 126 } catch(Exception e) { 127 Changeset changeset = api.getCurrentChangeset(); 128 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.getId())); 129 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}", 130 changesetId, e.toString())); 127 OsmChangesetCloseException closeException = new OsmChangesetCloseException(e); 128 closeException.setChangeset(api.getCurrentChangeset()); 129 throw closeException; 131 130 } 132 131 } … … 154 153 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 155 154 } catch (Exception ee) { 156 Changeset changeset = api.getCurrentChangeset(); 157 String changesetId = (changeset == null ? tr("unknown") : Long.toString(changeset.getId())); 158 logger.warning(tr("Failed to close changeset {0}, will be closed by server after timeout. Exception was: {1}", 159 changesetId, ee.toString())); 155 OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee); 156 closeException.setChangeset(api.getCurrentChangeset()); 157 throw closeException; 160 158 } 161 159 } … … 171 169 processed = new LinkedList<OsmPrimitive>(); 172 170 173 api.initialize( );171 api.initialize(progressMonitor); 174 172 175 173 try { … … 199 197 api.deletePrimitive(osm, progressMonitor); 200 198 } else if (osm.getId() == 0) { 201 api.createPrimitive(osm );199 api.createPrimitive(osm, progressMonitor); 202 200 } else { 203 api.modifyPrimitive(osm );201 api.modifyPrimitive(osm,progressMonitor); 204 202 } 205 203 }
Note:
See TracChangeset
for help on using the changeset viewer.