Ticket #4043: patch1.diff
| File patch1.diff, 23.0 KB (added by , 14 years ago) |
|---|
-
core/src/org/openstreetmap/josm/Main.java
587 587 SaveLayersDialog dialog = new SaveLayersDialog(Main.parent); 588 588 List<OsmDataLayer> layersWithUnmodifiedChanges = new ArrayList<OsmDataLayer>(); 589 589 for (OsmDataLayer l: Main.map.mapView.getLayersOfType(OsmDataLayer.class)) { 590 if (l.requiresSaveToFile() || l.requiresUploadToServer()) {590 if (l.requiresSaveToFile() || (l.isUploadAllowed() && l.requiresUploadToServer())) { 591 591 layersWithUnmodifiedChanges.add(l); 592 592 } 593 593 } -
core/src/org/openstreetmap/josm/actions/UploadAction.java
21 21 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 22 22 import org.openstreetmap.josm.gui.help.HelpUtil; 23 23 import org.openstreetmap.josm.gui.io.UploadDialog; 24 import org.openstreetmap.josm.gui.io.UploadForbiddenException; 24 25 import org.openstreetmap.josm.gui.io.UploadPrimitivesTask; 25 26 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 26 27 import org.openstreetmap.josm.tools.Shortcut; … … 103 104 return checkPreUploadConditions(layer, new APIDataSet(layer.data)); 104 105 } 105 106 106 protected void alertUnresolvedConflicts(OsmDataLayer layer) { 107 protected static void alertForbiddenUpload(OsmDataLayer layer) { 108 JOptionPane.showMessageDialog( 109 Main.parent, 110 tr("Upload is forbidden for layer ''{0}''", layer.getName()), 111 tr("Warning"), 112 JOptionPane.INFORMATION_MESSAGE 113 ); 114 } 115 116 protected static void alertUnresolvedConflicts(OsmDataLayer layer) { 107 117 HelpAwareOptionPane.showOptionDialog( 108 118 Main.parent, 109 119 tr("<html>The data to be uploaded participates in unresolved conflicts of layer ''{0}''.<br>" … … 117 127 118 128 /** 119 129 * Check whether the preconditions are met to upload data in <code>apiData</code>. 120 * Makes sure primitives in <code>apiData</code> don't participate in conflicts and130 * Makes sure upload is allowed, primitives in <code>apiData</code> don't participate in conflicts and 121 131 * runs the installed {@see UploadHook}s. 122 132 * 123 133 * @param layer the source layer of the data to be uploaded … … 125 135 * @return true, if the preconditions are met; false, otherwise 126 136 */ 127 137 public boolean checkPreUploadConditions(OsmDataLayer layer, APIDataSet apiData) { 138 if (!layer.isUploadAllowed()) { 139 alertForbiddenUpload(layer); 140 return false; 141 } 128 142 ConflictCollection conflicts = layer.getConflicts(); 129 143 if (apiData.participatesInConflict(conflicts)) { 130 144 alertUnresolvedConflicts(layer); … … 177 191 return; 178 192 dialog.rememberUserInput(); 179 193 180 Main.worker.execute( 181 new UploadPrimitivesTask( 182 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 183 layer, 184 apiData, 185 UploadDialog.getUploadDialog().getChangeset() 186 ) 187 ); 194 try { 195 Main.worker.execute( 196 new UploadPrimitivesTask( 197 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 198 layer, 199 apiData, 200 UploadDialog.getUploadDialog().getChangeset() 201 ) 202 ); 203 } catch (UploadForbiddenException ex) { 204 // This should not happen 205 System.err.println(ex.getMessage()); 206 } 188 207 } 189 208 190 209 public void actionPerformed(ActionEvent e) { -
core/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
25 25 import org.openstreetmap.josm.data.osm.visitor.Visitor; 26 26 import org.openstreetmap.josm.gui.DefaultNameFormatter; 27 27 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 28 import org.openstreetmap.josm.gui.io.UploadForbiddenException; 28 29 import org.openstreetmap.josm.gui.io.UploadSelectionDialog; 29 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 31 import org.openstreetmap.josm.io.OsmServerBackreferenceReader; … … 87 88 public void actionPerformed(ActionEvent e) { 88 89 if (!isEnabled()) 89 90 return; 91 if (!getEditLayer().isUploadAllowed()) { 92 JOptionPane.showMessageDialog( 93 Main.parent, 94 tr("Upload is forbidden for layer ''{0}''", getEditLayer().getName()), 95 tr("Warning"), 96 JOptionPane.INFORMATION_MESSAGE 97 ); 98 return; 99 } 90 100 UploadHullBuilder builder = new UploadHullBuilder(); 91 101 UploadSelectionDialog dialog = new UploadSelectionDialog(); 92 102 Collection<OsmPrimitive> modifiedCandidates = getModifiedPrimitives(getEditLayer().data.getSelected()); … … 117 127 ); 118 128 return; 119 129 } 120 uploadPrimitives(getEditLayer(), toUpload); 130 try { 131 uploadPrimitives(getEditLayer(), toUpload); 132 } catch (UploadForbiddenException ex) { 133 // This should not happen as it has been previously checked 134 System.err.println(ex.getMessage()); 135 } 121 136 } 122 137 123 138 /** … … 144 159 * 145 160 * @param layer the data layer from which we upload a subset of primitives 146 161 * @param toUpload the primitives to upload. If null or empty returns immediatelly 162 * @throws UploadForbiddenException if upload is not allowed for layer 147 163 */ 148 public void uploadPrimitives(OsmDataLayer layer, Collection<OsmPrimitive> toUpload) {164 public void uploadPrimitives(OsmDataLayer layer, Collection<OsmPrimitive> toUpload) throws UploadForbiddenException { 149 165 if (toUpload == null || toUpload.isEmpty()) return; 150 166 UploadHullBuilder builder = new UploadHullBuilder(); 151 167 toUpload = builder.build(toUpload); -
core/src/org/openstreetmap/josm/data/osm/DataSet.java
124 124 private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<AbstractDatasetChangedEvent>(); 125 125 126 126 private int highlightUpdateCount; 127 128 private boolean uploadAllowed = true; 127 129 128 130 private final ReadWriteLock lock = new ReentrantReadWriteLock(); 129 131 private final Object selectionLock = new Object(); … … 206 208 this.version = version; 207 209 } 208 210 211 public final boolean isUploadAllowed() { 212 return uploadAllowed; 213 } 214 215 public final void setUploadAllowed(boolean uploadAllowed) { 216 this.uploadAllowed = uploadAllowed; 217 } 218 209 219 /* 210 220 * Holding bin for changeset tag information, to be applied when or if this is ever uploaded. 211 221 */ -
core/src/org/openstreetmap/josm/gui/MapView.java
824 824 } 825 825 826 826 protected void refreshTitle() { 827 boolean dirty = editLayer != null && (editLayer.requiresSaveToFile() || editLayer.requiresUploadToServer());827 boolean dirty = editLayer != null && (editLayer.requiresSaveToFile() || (editLayer.isUploadAllowed() && editLayer.requiresUploadToServer())); 828 828 if (dirty) { 829 829 JOptionPane.getFrameForComponent(Main.parent).setTitle("* " + tr("Java OpenStreetMap Editor")); 830 830 } else { -
core/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
376 376 continue; 377 377 } 378 378 OsmDataLayer odl = (OsmDataLayer)l; 379 if ((odl.requiresSaveToFile() || odl.requiresUploadToServer()) && odl.data.isModified()) {379 if ((odl.requiresSaveToFile() || (odl.isUploadAllowed() && odl.requiresUploadToServer())) && odl.data.isModified()) { 380 380 layersWithUnmodifiedChanges.add(odl); 381 381 } 382 382 } -
core/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
427 427 } 428 428 dialog.rememberUserInput(); 429 429 430 currentTask = new UploadLayerTask(431 UploadDialog.getUploadDialog().getUploadStrategySpecification(),432 layerInfo.getLayer(),433 monitor,434 UploadDialog.getUploadDialog().getChangeset()435 );436 currentFuture = worker.submit(currentTask);437 430 try { 438 // wait for the asynchronous task to complete 439 // 440 currentFuture.get(); 441 } catch(CancellationException e) { 442 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.CANCELED); 443 } catch(Exception e) { 444 e.printStackTrace(); 445 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.FAILED); 446 ExceptionDialogUtil.explainException(e); 447 } 448 if (currentTask.isCanceled()) { 449 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.CANCELED); 450 } else if (currentTask.isFailed()) { 451 currentTask.getLastException().printStackTrace(); 452 ExceptionDialogUtil.explainException(currentTask.getLastException()); 453 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.FAILED); 454 } else { 455 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.OK); 431 currentTask = new UploadLayerTask( 432 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 433 layerInfo.getLayer(), 434 monitor, 435 UploadDialog.getUploadDialog().getChangeset() 436 ); 437 currentFuture = worker.submit(currentTask); 438 try { 439 // wait for the asynchronous task to complete 440 // 441 currentFuture.get(); 442 } catch(CancellationException e) { 443 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.CANCELED); 444 } catch(Exception e) { 445 e.printStackTrace(); 446 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.FAILED); 447 ExceptionDialogUtil.explainException(e); 448 } 449 if (currentTask.isCanceled()) { 450 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.CANCELED); 451 } else if (currentTask.isFailed()) { 452 currentTask.getLastException().printStackTrace(); 453 ExceptionDialogUtil.explainException(currentTask.getLastException()); 454 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.FAILED); 455 } else { 456 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.OK); 457 } 458 } catch (UploadForbiddenException ex) { 459 // This should not happen has it has been previously checked in checkPreUploadConditions() 460 System.err.println(ex.getMessage()); 456 461 } 457 462 currentTask = null; 458 463 currentFuture = null; -
core/src/org/openstreetmap/josm/gui/io/UploadForbiddenException.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 7 8 public class UploadForbiddenException extends Exception { 9 10 public UploadForbiddenException(OsmDataLayer layer) { 11 super(tr("Upload is forbidden for layer ''{0}''", layer.getName())); 12 } 13 } -
core/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java
53 53 * @param layer the layer. Must not be null. 54 54 * @param monitor a progress monitor. If monitor is null, uses {@see NullProgressMonitor#INSTANCE} 55 55 * @param changeset the changeset to be used 56 * @throws IllegalArgumentException thrown, if layer is null 56 * @throws UploadForbiddenException thrown if upload is not allowed for layer 57 * @throws IllegalArgumentException thrown if layer is null 57 58 * @throws IllegalArgumentException thrown if strategy is null 58 59 */ 59 public UploadLayerTask(UploadStrategySpecification strategy, OsmDataLayer layer, ProgressMonitor monitor, Changeset changeset) {60 public UploadLayerTask(UploadStrategySpecification strategy, OsmDataLayer layer, ProgressMonitor monitor, Changeset changeset) throws UploadForbiddenException { 60 61 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 61 62 CheckParameterUtil.ensureParameterNotNull(strategy, "strategy"); 63 if (!layer.isUploadAllowed()) { 64 throw new UploadForbiddenException(layer); 65 } 62 66 if (monitor == null) { 63 67 monitor = NullProgressMonitor.INSTANCE; 64 68 } -
core/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java
55 55 * @param toUpload the collection of primitives to upload. Set to the empty collection if null. 56 56 * @param changeset the changeset to use for uploading. Must not be null. changeset.getId() 57 57 * can be 0 in which case the upload task creates a new changeset 58 * @throws UploadForbiddenException thrown if upload is not allowed for layer 58 59 * @throws IllegalArgumentException thrown if layer is null 59 60 * @throws IllegalArgumentException thrown if toUpload is null 60 61 * @throws IllegalArgumentException thrown if strategy is null 61 62 * @throws IllegalArgumentException thrown if changeset is null 62 63 */ 63 public UploadPrimitivesTask(UploadStrategySpecification strategy, OsmDataLayer layer, APIDataSet toUpload, Changeset changeset) {64 public UploadPrimitivesTask(UploadStrategySpecification strategy, OsmDataLayer layer, APIDataSet toUpload, Changeset changeset) throws UploadForbiddenException { 64 65 super(tr("Uploading data for layer ''{0}''", layer.getName()),false /* don't ignore exceptions */); 65 66 ensureParameterNotNull(layer,"layer"); 66 67 ensureParameterNotNull(strategy, "strategy"); 67 68 ensureParameterNotNull(changeset, "changeset"); 69 if (!layer.isUploadAllowed()) { 70 throw new UploadForbiddenException(layer); 71 } 68 72 this.toUpload = toUpload; 69 73 this.layer = layer; 70 74 this.changeset = changeset; -
core/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
394 394 395 395 396 396 @Override public boolean isMergable(final Layer other) { 397 return other instanceof OsmDataLayer ;397 return other instanceof OsmDataLayer && (isUploadAllowed() == ((OsmDataLayer)other).isUploadAllowed()); 398 398 } 399 399 400 400 @Override public void visitBoundingBox(final BoundingXYVisitor v) { … … 456 456 p.add(new JLabel(nodeText, ImageProvider.get("data", "node"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 457 457 p.add(new JLabel(wayText, ImageProvider.get("data", "way"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 458 458 p.add(new JLabel(relationText, ImageProvider.get("data", "relation"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 459 p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset")))); 459 p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))), GBC.eop().insets(15,0,0,0)); 460 p.add(new JLabel(tr("Upload allowed: {0}", isUploadAllowed() ? tr("yes") : tr("no"))), GBC.eop().insets(15,0,0,0)); 460 461 461 462 return p; 462 463 } … … 701 702 * change listener and already got notified. 702 703 */ 703 704 } 705 706 public final boolean isUploadAllowed() { 707 return data.isUploadAllowed(); 708 } 709 710 public final void setUploadAllowed(boolean uploadAllowed) { 711 data.setUploadAllowed(uploadAllowed); 712 } 704 713 } -
core/src/org/openstreetmap/josm/io/OsmApi.java
260 260 } 261 261 262 262 /** 263 * Makes an XML string from an OSM primitive. Uses the OsmWriter class. 264 * @param o the OSM primitive 265 * @param addBody true to generate the full XML, false to only generate the encapsulating tag 263 * Makes an XML string from an OSM changeset. Uses the OsmWriter class. 264 * @param s the OSM changeset 266 265 * @return XML string 267 266 */ 268 267 private String toXml(Changeset s) { -
core/src/org/openstreetmap/josm/io/OsmExporter.java
73 73 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion()); 74 74 layer.data.getReadLock().lock(); 75 75 try { 76 w.header(); 77 w.writeDataSources(layer.data); 78 w.writeContent(layer.data); 79 w.footer(); 76 w.writeLayer(layer); 80 77 w.close(); 81 78 } finally { 82 79 layer.data.getReadLock().unlock(); -
core/src/org/openstreetmap/josm/io/OsmReader.java
116 116 throwException(tr("Unsupported version: {0}", v)); 117 117 } 118 118 ds.setVersion(v); 119 String upload = parser.getAttributeValue(null, "upload"); 120 if (upload != null) { 121 ds.setUploadAllowed(Boolean.parseBoolean(upload)); 122 } 119 123 String generator = parser.getAttributeValue(null, "generator"); 120 124 Long uploadChangesetId = null; 121 125 if (parser.getAttributeValue(null, "upload-changeset") != null) { -
core/src/org/openstreetmap/josm/io/OsmWriter.java
25 25 import org.openstreetmap.josm.data.osm.Tagged; 26 26 import org.openstreetmap.josm.data.osm.Way; 27 27 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 29 import org.openstreetmap.josm.tools.DateUtils; 29 30 30 31 /** … … 53 54 public void setWithBody(boolean wb) { 54 55 this.withBody = wb; 55 56 } 57 56 58 public void setChangeset(Changeset cs) { 57 59 this.changeset = cs; 58 60 } 61 59 62 public void setVersion(String v) { 60 63 this.version = v; 61 64 } 62 65 63 66 public void header() { 67 header(null); 68 } 69 70 public void header(Boolean upload) { 64 71 out.println("<?xml version='1.0' encoding='UTF-8'?>"); 65 72 out.print("<osm version='"); 66 73 out.print(version); 74 if (upload != null) { 75 out.print("' upload='"); 76 out.print(upload); 77 } 67 78 out.println("' generator='JOSM'>"); 68 79 } 80 69 81 public void footer() { 70 82 out.println("</osm>"); 71 83 } … … 82 94 Collections.sort(result, byIdComparator); 83 95 return result; 84 96 } 97 98 public void writeLayer(OsmDataLayer layer) { 99 header(layer.isUploadAllowed()); 100 writeDataSources(layer.data); 101 writeContent(layer.data); 102 footer(); 103 } 85 104 86 105 public void writeContent(DataSet ds) { 87 106 for (OsmPrimitive n : sortById(ds.getNodes())) { -
core/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
221 221 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion()); 222 222 layer.data.getReadLock().lock(); 223 223 try { 224 w.header(); 225 w.writeDataSources(layer.data); 226 w.writeContent(layer.data); 227 w.footer(); 224 w.writeLayer(layer); 228 225 w.flush(); 229 226 } finally { 230 227 layer.data.getReadLock().unlock();
