Changeset 13133 in josm
- Timestamp:
- 2017-11-19T22:52:24+01:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r13123 r13133 10 10 import java.util.List; 11 11 import java.util.Map; 12 import java.util.Optional; 12 13 13 14 import javax.swing.JOptionPane; … … 25 26 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 26 27 import org.openstreetmap.josm.gui.MainApplication; 28 import org.openstreetmap.josm.gui.io.AsynchronousUploadPrimitivesTask; 27 29 import org.openstreetmap.josm.gui.io.UploadDialog; 28 30 import org.openstreetmap.josm.gui.io.UploadPrimitivesTask; … … 30 32 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 31 33 import org.openstreetmap.josm.gui.util.GuiHelper; 34 import org.openstreetmap.josm.spi.preferences.Config; 32 35 import org.openstreetmap.josm.tools.ImageProvider; 33 36 import org.openstreetmap.josm.tools.Shortcut; … … 58 61 private static final List<UploadHook> LATE_UPLOAD_HOOKS = new LinkedList<>(); 59 62 63 private static final String IS_ASYNC_UPLOAD_ENABLED = "asynchronous.upload"; 64 60 65 static { 61 66 /** … … 260 265 } 261 266 262 MainApplication.worker.execute( 263 new UploadPrimitivesTask( 264 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 265 layer, 266 apiData, 267 cs 268 ) 269 ); 267 if (Config.getPref().getBoolean(IS_ASYNC_UPLOAD_ENABLED, true)) { 268 Optional<AsynchronousUploadPrimitivesTask> asyncUploadTask = AsynchronousUploadPrimitivesTask.createAsynchronousUploadTask( 269 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 270 layer, 271 apiData, 272 cs); 273 274 if (asyncUploadTask.isPresent()) { 275 MainApplication.worker.execute(asyncUploadTask.get()); 276 } 277 } else { 278 MainApplication.worker.execute( 279 new UploadPrimitivesTask( 280 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 281 layer, 282 apiData, 283 cs)); 284 } 270 285 } 271 286 -
trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java
r11774 r13133 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.layer; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.util.ArrayList; … … 8 10 import java.util.concurrent.CopyOnWriteArrayList; 9 11 12 import javax.swing.JOptionPane; 13 10 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.gui.MainApplication; 11 16 import org.openstreetmap.josm.gui.util.GuiHelper; 12 17 … … 206 211 207 212 /** 208 * Set the active layer. If the layer is an OsmDataLayer, the edit layer is also changed. 213 * Set the active layer, unless the layer is read-only. 214 * If the layer is an OsmDataLayer, the edit layer is also changed. 209 215 * @param layer The active layer. 210 216 */ … … 212 218 // we force this on to the EDT Thread to make events fire from there. 213 219 // The synchronization lock needs to be held by the EDT. 214 GuiHelper.runInEDTAndWaitWithException(() -> realSetActiveLayer(layer)); 220 if (layer instanceof OsmDataLayer && ((OsmDataLayer) layer).isReadOnly()) { 221 GuiHelper.runInEDT(() -> 222 JOptionPane.showMessageDialog( 223 MainApplication.parent, 224 tr("Trying to set a read only data layer as edit layer"), 225 tr("Warning"), 226 JOptionPane.WARNING_MESSAGE)); 227 } else { 228 GuiHelper.runInEDTAndWaitWithException(() -> realSetActiveLayer(layer)); 229 } 215 230 } 216 231 … … 310 325 */ 311 326 public synchronized Layer getActiveLayer() { 312 return activeLayer; 313 } 314 315 /** 316 * Replies the current edit layer, if any 327 if (activeLayer instanceof OsmDataLayer) { 328 if (!((OsmDataLayer) activeLayer).isReadOnly()) { 329 return activeLayer; 330 } else { 331 return null; 332 } 333 } else { 334 return activeLayer; 335 } 336 } 337 338 /** 339 * Replies the current edit layer, if present and not readOnly 317 340 * 318 341 * @return the current edit layer. May be null. 319 342 */ 320 343 public synchronized OsmDataLayer getEditLayer() { 321 return editLayer; 344 if (editLayer != null && !editLayer.isReadOnly()) 345 return editLayer; 346 else 347 return null; 322 348 } 323 349 … … 379 405 layerAvailabilityListeners.clear(); 380 406 } 407 408 /** 409 * Prepares an OsmDataLayer for upload. The layer to be uploaded is locked and 410 * if the layer to be uploaded is the current editLayer then editLayer is reset 411 * to null for disallowing any changes to the layer. An ActiveLayerChangeEvent 412 * is fired to notify the listeners 413 * 414 * @param layer The OsmDataLayer to be uploaded 415 */ 416 public void prepareLayerForUpload(OsmDataLayer layer) { 417 418 GuiHelper.assertCallFromEdt(); 419 layer.setReadOnly(); 420 421 // Reset only the edit layer as empty 422 if (editLayer == layer) { 423 ActiveLayerChangeEvent activeLayerChangeEvent = new ActiveLayerChangeEvent(this, editLayer, activeLayer); 424 editLayer = null; 425 fireActiveLayerChange(activeLayerChangeEvent); 426 } 427 } 428 429 /** 430 * Post upload processing of the OsmDataLayer. 431 * If the current edit layer is empty this function sets the layer uploaded as the 432 * current editLayer. An ActiveLayerChangeEvent is fired to notify the listeners 433 * 434 * @param layer The OsmDataLayer uploaded 435 */ 436 public void processLayerAfterUpload(OsmDataLayer layer) { 437 GuiHelper.assertCallFromEdt(); 438 layer.unsetReadOnly(); 439 440 // Set the layer as edit layer if the edit layer is empty. 441 if (editLayer == null) { 442 ActiveLayerChangeEvent layerChangeEvent = new ActiveLayerChangeEvent(this, editLayer, activeLayer); 443 editLayer = layer; 444 fireActiveLayerChange(layerChangeEvent); 445 } 446 } 381 447 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r13130 r13133 32 32 import java.util.Set; 33 33 import java.util.concurrent.CopyOnWriteArrayList; 34 import java.util.concurrent.atomic.AtomicBoolean; 34 35 import java.util.concurrent.atomic.AtomicInteger; 35 36 import java.util.regex.Pattern; … … 130 131 private boolean requiresSaveToFile; 131 132 private boolean requiresUploadToServer; 133 /** Flag used to know if the layer should not be editable */ 134 private final AtomicBoolean isReadOnly = new AtomicBoolean(false); 132 135 133 136 /** … … 421 424 base.addOverlay(new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0)); 422 425 } 426 427 if (isReadOnly()) { 428 // If the layer is read only then change the default icon to a clock 429 base = new ImageProvider("clock").setMaxSize(ImageSizes.LAYER); 430 } 423 431 return base.get(); 424 432 } … … 1144 1152 super.setName(name); 1145 1153 } 1154 1155 /** 1156 * Sets the isReadOnly flag for the OsmDataLayer as true 1157 */ 1158 public void setReadOnly() { 1159 if (!isReadOnly.compareAndSet(false, true)) { 1160 Logging.warn("Trying to set readOnly flag on a readOnly layer ", this.getName()); 1161 } 1162 } 1163 1164 /** 1165 * Sets the isReadOnly flag for the OsmDataLayer as false 1166 */ 1167 public void unsetReadOnly() { 1168 if (!isReadOnly.compareAndSet(true, false)) { 1169 Logging.warn("Trying to unset readOnly flag on a non-readOnly layer ", this.getName()); 1170 } 1171 } 1172 1173 /** 1174 * Returns the value of the isReadOnly flag for the OsmDataLayer 1175 * @return isReadOnly 1176 */ 1177 public boolean isReadOnly() { 1178 return isReadOnly.get(); 1179 } 1146 1180 }
Note:
See TracChangeset
for help on using the changeset viewer.