Changeset 7358 in josm
- Timestamp:
- 2014-08-01T23:03:40+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r7335 r7358 77 77 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 78 78 import org.openstreetmap.josm.gui.layer.Layer; 79 import org.openstreetmap.josm.gui.layer.ModifiableLayer; 79 80 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 80 81 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; … … 890 891 891 892 /** 892 * Asks user to perform "save layer" operations (save .osmon disk and/or uploadosmdata to server) for all {@linkOsmDataLayer} before JOSM exits.893 * Asks user to perform "save layer" operations (save on disk and/or upload data to server) for all {@link ModifiableLayer} before JOSM exits. 893 894 * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations. {@code false} if the user cancels. 894 895 * @since 2025 … … 896 897 public static boolean saveUnsavedModifications() { 897 898 if (!isDisplayingMapView()) return true; 898 return saveUnsavedModifications(map.mapView.getLayersOfType( OsmDataLayer.class), true);899 } 900 901 /** 902 * Asks user to perform "save layer" operations (save .osmon disk and/or uploadosmdata to server) beforeosmlayers deletion.903 * 904 * @param selectedLayers The layers to check. Only instances of {@link OsmDataLayer} are considered.899 return saveUnsavedModifications(map.mapView.getLayersOfType(ModifiableLayer.class), true); 900 } 901 902 /** 903 * Asks user to perform "save layer" operations (save on disk and/or upload data to server) before data layers deletion. 904 * 905 * @param selectedLayers The layers to check. Only instances of {@link ModifiableLayer} are considered. 905 906 * @param exit {@code true} if JOSM is exiting, {@code false} otherwise. 906 907 * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations. {@code false} if the user cancels. … … 909 910 public static boolean saveUnsavedModifications(Iterable<? extends Layer> selectedLayers, boolean exit) { 910 911 SaveLayersDialog dialog = new SaveLayersDialog(parent); 911 List< OsmDataLayer> layersWithUnmodifiedChanges = new ArrayList<>();912 List<ModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>(); 912 913 for (Layer l: selectedLayers) { 913 if (!(l instanceof OsmDataLayer)) {914 if (!(l instanceof ModifiableLayer)) { 914 915 continue; 915 916 } 916 OsmDataLayer odl = (OsmDataLayer)l;917 if ((odl.requiresSaveToFile() || (odl.requiresUploadToServer() && !odl.isUploadDiscouraged())) && odl. data.isModified()) {917 ModifiableLayer odl = (ModifiableLayer)l; 918 if ((odl.requiresSaveToFile() || (odl.requiresUploadToServer() && !odl.isUploadDiscouraged())) && odl.isModified()) { 918 919 layersWithUnmodifiedChanges.add(odl); 919 920 } -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r7005 r7358 27 27 import org.openstreetmap.josm.gui.io.UploadDialog; 28 28 import org.openstreetmap.josm.gui.io.UploadPrimitivesTask; 29 import org.openstreetmap.josm.gui.layer.ModifiableLayer; 29 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 31 import org.openstreetmap.josm.gui.util.GuiHelper; … … 142 143 } 143 144 144 public boolean checkPreUploadConditions(OsmDataLayer layer) { 145 return checkPreUploadConditions(layer, new APIDataSet(layer.data)); 145 public static boolean checkPreUploadConditions(ModifiableLayer layer) { 146 return checkPreUploadConditions(layer, 147 layer instanceof OsmDataLayer ? new APIDataSet(((OsmDataLayer)layer).data) : null); 146 148 } 147 149 … … 162 164 * want to continue 163 165 */ 164 public static boolean warnUploadDiscouraged( OsmDataLayer layer) {166 public static boolean warnUploadDiscouraged(ModifiableLayer layer) { 165 167 return GuiHelper.warnUser(tr("Upload discouraged"), 166 168 "<html>" + … … 182 184 * @return true, if the preconditions are met; false, otherwise 183 185 */ 184 public boolean checkPreUploadConditions( OsmDataLayer layer, APIDataSet apiData) {186 public static boolean checkPreUploadConditions(ModifiableLayer layer, APIDataSet apiData) { 185 187 if (layer.isUploadDiscouraged()) { 186 188 if (warnUploadDiscouraged(layer)) { … … 188 190 } 189 191 } 190 ConflictCollection conflicts = layer.getConflicts(); 191 if (apiData.participatesInConflict(conflicts)) { 192 alertUnresolvedConflicts(layer); 193 return false; 192 if (layer instanceof OsmDataLayer) { 193 OsmDataLayer osmLayer = (OsmDataLayer) layer; 194 ConflictCollection conflicts = osmLayer.getConflicts(); 195 if (apiData.participatesInConflict(conflicts)) { 196 alertUnresolvedConflicts(osmLayer); 197 return false; 198 } 194 199 } 195 200 // Call all upload hooks in sequence. 196 201 // FIXME: this should become an asynchronous task 197 202 // 198 for (UploadHook hook : uploadHooks) { 199 if (!hook.checkUpload(apiData)) 200 return false; 203 if (apiData != null) { 204 for (UploadHook hook : uploadHooks) { 205 if (!hook.checkUpload(apiData)) 206 return false; 207 } 201 208 } 202 209 -
trunk/src/org/openstreetmap/josm/gui/io/AbstractIOTask.java
r6084 r7358 15 15 private Exception lastException; 16 16 17 /** 18 * Contructs a new {@code AbstractIOTask}. 19 */ 17 20 public AbstractIOTask() { 18 21 canceled = false; -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayerInfo.java
r7204 r7358 4 4 import java.io.File; 5 5 6 import org.openstreetmap.josm.gui.layer. OsmDataLayer;6 import org.openstreetmap.josm.gui.layer.ModifiableLayer; 7 7 import org.openstreetmap.josm.tools.CheckParameterUtil; 8 8 … … 10 10 * SaveLayerInfo represents the information, user preferences and save/upload states of 11 11 * a layer which might be uploaded/saved. 12 * 12 * @since 2025 13 13 */ 14 14 class SaveLayerInfo implements Comparable<SaveLayerInfo> { 15 15 16 /** the osm datalayer */17 private OsmDataLayer layer;16 /** the modifiable layer */ 17 private ModifiableLayer layer; 18 18 private boolean doCheckSaveConditions; 19 19 private boolean doSaveToFile; … … 28 28 * @throws IllegalArgumentException thrown if layer is null 29 29 */ 30 public SaveLayerInfo( OsmDataLayer layer) {30 public SaveLayerInfo(ModifiableLayer layer) { 31 31 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 32 32 this.layer = layer; … … 42 42 * @return the layer this info objects holds information for 43 43 */ 44 public OsmDataLayer getLayer() {44 public ModifiableLayer getLayer() { 45 45 return layer; 46 46 } -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayerTask.java
r7204 r7358 11 11 12 12 /** 13 * SaveLayerTask saves the data managed by an {@link org.openstreetmap.josm.gui.layer. OsmDataLayer} to the14 * {@link org.openstreetmap.josm.gui.layer. OsmDataLayer#getAssociatedFile()}.13 * SaveLayerTask saves the data managed by an {@link org.openstreetmap.josm.gui.layer.ModifiableLayer} to the 14 * {@link org.openstreetmap.josm.gui.layer.Layer#getAssociatedFile()}. 15 15 * 16 16 * <pre> … … 26 26 * </pre> 27 27 */ 28 class SaveLayerTask extends AbstractIOTask { 28 public class SaveLayerTask extends AbstractIOTask { 29 29 private SaveLayerInfo layerInfo; 30 30 private ProgressMonitor parentMonitor; -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r7204 r7358 44 44 import org.openstreetmap.josm.Main; 45 45 import org.openstreetmap.josm.actions.UploadAction; 46 import org.openstreetmap.josm.data.APIDataSet;47 46 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 48 47 import org.openstreetmap.josm.gui.io.SaveLayersModel.Mode; 48 import org.openstreetmap.josm.gui.layer.ModifiableLayer; 49 49 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 50 50 import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor; … … 449 449 protected void uploadLayers(List<SaveLayerInfo> toUpload) { 450 450 for (final SaveLayerInfo layerInfo: toUpload) { 451 ModifiableLayer layer = layerInfo.getLayer(); 451 452 if (canceled) { 452 model.setUploadState(layer Info.getLayer(), UploadOrSaveState.CANCELED);453 model.setUploadState(layer, UploadOrSaveState.CANCELED); 453 454 continue; 454 455 } 455 456 monitor.subTask(tr("Preparing layer ''{0}'' for upload ...", layerInfo.getName())); 456 457 457 if (! newUploadAction().checkPreUploadConditions(layerInfo.getLayer())) {458 model.setUploadState(layer Info.getLayer(), UploadOrSaveState.FAILED);458 if (!UploadAction.checkPreUploadConditions(layer)) { 459 model.setUploadState(layer, UploadOrSaveState.FAILED); 459 460 continue; 460 461 } 461 final UploadDialog dialog = UploadDialog.getUploadDialog(); 462 dialog.setUploadedPrimitives(new APIDataSet(layerInfo.getLayer().data)); 463 dialog.setVisible(true); 464 if (dialog.isCanceled()) { 465 model.setUploadState(layerInfo.getLayer(), UploadOrSaveState.CANCELED); 462 463 AbstractUploadDialog dialog = layer.getUploadDialog(); 464 if (dialog != null) { 465 dialog.setVisible(true); 466 if (dialog.isCanceled()) { 467 model.setUploadState(layer, UploadOrSaveState.CANCELED); 468 continue; 469 } 470 dialog.rememberUserInput(); 471 } 472 473 currentTask = layer.createUploadTask(monitor); 474 if (currentTask == null) { 475 model.setUploadState(layer, UploadOrSaveState.FAILED); 466 476 continue; 467 477 } 468 dialog.rememberUserInput();469 470 currentTask = new UploadLayerTask(471 UploadDialog.getUploadDialog().getUploadStrategySpecification(),472 layerInfo.getLayer(),473 monitor,474 UploadDialog.getUploadDialog().getChangeset()475 );476 478 currentFuture = worker.submit(currentTask); 477 479 try { … … 480 482 currentFuture.get(); 481 483 } catch(CancellationException e) { 482 model.setUploadState(layer Info.getLayer(), UploadOrSaveState.CANCELED);484 model.setUploadState(layer, UploadOrSaveState.CANCELED); 483 485 } catch(Exception e) { 484 486 Main.error(e); 485 model.setUploadState(layer Info.getLayer(), UploadOrSaveState.FAILED);487 model.setUploadState(layer, UploadOrSaveState.FAILED); 486 488 ExceptionDialogUtil.explainException(e); 487 489 } 488 490 if (currentTask.isCanceled()) { 489 model.setUploadState(layer Info.getLayer(), UploadOrSaveState.CANCELED);491 model.setUploadState(layer, UploadOrSaveState.CANCELED); 490 492 } else if (currentTask.isFailed()) { 491 493 Main.error(currentTask.getLastException()); 492 494 ExceptionDialogUtil.explainException(currentTask.getLastException()); 493 model.setUploadState(layer Info.getLayer(), UploadOrSaveState.FAILED);495 model.setUploadState(layer, UploadOrSaveState.FAILED); 494 496 } else { 495 model.setUploadState(layer Info.getLayer(), UploadOrSaveState.OK);497 model.setUploadState(layer, UploadOrSaveState.OK); 496 498 } 497 499 currentTask = null; -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersModel.java
r7005 r7358 12 12 import javax.swing.table.DefaultTableModel; 13 13 14 import org.openstreetmap.josm.gui.layer.ModifiableLayer; 14 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 15 16 … … 59 60 } 60 61 61 public void populate(List<OsmDataLayer> layers) { 62 /** 63 * Populates the model with given modifiable layers. 64 * @param layers The layers to use to populate this model 65 * @since 7358 66 */ 67 public void populate(List<? extends ModifiableLayer> layers) { 62 68 layerInfo = new ArrayList<>(); 63 69 if (layers == null) return; 64 for ( OsmDataLayer layer: layers) {70 for (ModifiableLayer layer: layers) { 65 71 layerInfo.add(new SaveLayerInfo(layer)); 66 72 } … … 135 141 136 142 public List<SaveLayerInfo> getLayersWithConflictsAndUploadRequest() { 137 List<SaveLayerInfo> ret =new ArrayList<>(); 138 for (SaveLayerInfo info: layerInfo) { 139 if (info.isDoUploadToServer() && !info.getLayer().getConflicts().isEmpty()) { 143 List<SaveLayerInfo> ret = new ArrayList<>(); 144 for (SaveLayerInfo info: layerInfo) { 145 ModifiableLayer l = info.getLayer(); 146 if (info.isDoUploadToServer() && l instanceof OsmDataLayer && !((OsmDataLayer)l).getConflicts().isEmpty()) { 140 147 ret.add(info); 141 148 } … … 145 152 146 153 public List<SaveLayerInfo> getLayersToUpload() { 147 List<SaveLayerInfo> ret =new ArrayList<>(); 154 List<SaveLayerInfo> ret = new ArrayList<>(); 148 155 for (SaveLayerInfo info: layerInfo) { 149 156 if (info.isDoUploadToServer()) { … … 155 162 156 163 public List<SaveLayerInfo> getLayersToSave() { 157 List<SaveLayerInfo> ret =new ArrayList<>(); 164 List<SaveLayerInfo> ret = new ArrayList<>(); 158 165 for (SaveLayerInfo info: layerInfo) { 159 166 if (info.isDoSaveToFile()) { … … 164 171 } 165 172 166 public void setUploadState( OsmDataLayer layer, UploadOrSaveState state) {173 public void setUploadState(ModifiableLayer layer, UploadOrSaveState state) { 167 174 SaveLayerInfo info = getSaveLayerInfo(layer); 168 175 if (info != null) { … … 172 179 } 173 180 174 public void setSaveState( OsmDataLayer layer, UploadOrSaveState state) {181 public void setSaveState(ModifiableLayer layer, UploadOrSaveState state) { 175 182 SaveLayerInfo info = getSaveLayerInfo(layer); 176 183 if (info != null) { … … 180 187 } 181 188 182 public SaveLayerInfo getSaveLayerInfo( OsmDataLayer layer) {189 public SaveLayerInfo getSaveLayerInfo(ModifiableLayer layer) { 183 190 for (SaveLayerInfo info: this.layerInfo) { 184 191 if (info.getLayer() == layer) -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r7190 r7358 31 31 import javax.swing.JButton; 32 32 import javax.swing.JComponent; 33 import javax.swing.JDialog;34 33 import javax.swing.JOptionPane; 35 34 import javax.swing.JPanel; … … 59 58 * This is a dialog for entering upload options like the parameters for 60 59 * the upload changeset and the strategy for opening/closing a changeset. 61 * 60 * @since 2025 62 61 */ 63 public class UploadDialog extends JDialog implements PropertyChangeListener, PreferenceChangedListener{62 public class UploadDialog extends AbstractUploadDialog implements PropertyChangeListener, PreferenceChangedListener { 64 63 /** the unique instance of the upload dialog */ 65 64 private static UploadDialog uploadDialog; … … 97 96 /** the upload button */ 98 97 private JButton btnUpload; 99 private boolean canceled = false;100 98 101 99 /** the changeset comment model keeping the state of the changeset comment */ … … 267 265 } 268 266 269 /** 270 * Remembers the user input in the preference settings 271 */ 267 @Override 272 268 public void rememberUserInput() { 273 269 pnlBasicUploadSettings.rememberUserInput(); … … 345 341 protected String getUploadSource() { 346 342 return changesetSourceModel.getComment(); 347 }348 349 /**350 * Returns true if the dialog was canceled351 *352 * @return true if the dialog was canceled353 */354 public boolean isCanceled() {355 return canceled;356 }357 358 /**359 * Sets whether the dialog was canceled360 *361 * @param canceled true if the dialog is canceled362 */363 protected void setCanceled(boolean canceled) {364 this.canceled = canceled;365 343 } 366 344 -
trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java
r7005 r7358 40 40 * </pre> 41 41 */ 42 class UploadLayerTask extends AbstractIOTask implements Runnable { 42 public class UploadLayerTask extends AbstractIOTask implements Runnable { 43 43 private OsmServerWriter writer; 44 44 private OsmDataLayer layer; -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r6890 r7358 119 119 /** 120 120 * Create the layer and fill in the necessary components. 121 * @param name Layer name 121 122 */ 122 123 public Layer(String name) { -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r7299 r7358 44 44 import org.openstreetmap.josm.actions.SaveActionBase; 45 45 import org.openstreetmap.josm.actions.ToggleUploadDiscouragedLayerAction; 46 import org.openstreetmap.josm.data.APIDataSet; 46 47 import org.openstreetmap.josm.data.Bounds; 47 48 import org.openstreetmap.josm.data.SelectionChangedListener; … … 76 77 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 77 78 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 79 import org.openstreetmap.josm.gui.io.AbstractIOTask; 80 import org.openstreetmap.josm.gui.io.AbstractUploadDialog; 81 import org.openstreetmap.josm.gui.io.UploadDialog; 82 import org.openstreetmap.josm.gui.io.UploadLayerTask; 78 83 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 79 84 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 91 96 * @author imi 92 97 */ 93 public class OsmDataLayer extends Layer implements Listener, SelectionChangedListener { 98 public class OsmDataLayer extends ModifiableLayer implements Listener, SelectionChangedListener { 94 99 public static final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk"; 95 100 public static final String REQUIRES_UPLOAD_TO_SERVER_PROP = OsmDataLayer.class.getName() + ".requiresUploadToServer"; … … 622 627 } 623 628 624 /** 625 * Replies true if the data managed by this layer needs to be uploaded to 626 * the server because it contains at least one modified primitive. 627 * 628 * @return true if the data managed by this layer needs to be uploaded to 629 * the server because it contains at least one modified primitive; false, 630 * otherwise 631 */ 629 @Override 632 630 public boolean requiresUploadToServer() { 633 631 return requiresUploadToServer; 634 632 } 635 633 636 /** 637 * Replies true if the data managed by this layer needs to be saved to 638 * a file. Only replies true if a file is assigned to this layer and 639 * if the data managed by this layer has been modified since the last 640 * save operation to the file. 641 * 642 * @return true if the data managed by this layer needs to be saved to 643 * a file 644 */ 634 @Override 645 635 public boolean requiresSaveToFile() { 646 636 return getAssociatedFile() != null && requiresSaveToFile; … … 650 640 public void onPostLoadFromFile() { 651 641 setRequiresSaveToFile(false); 652 setRequiresUploadToServer( data.isModified());642 setRequiresUploadToServer(isModified()); 653 643 } 654 644 655 645 public void onPostDownloadFromServer() { 656 646 setRequiresSaveToFile(true); 657 setRequiresUploadToServer( data.isModified());647 setRequiresUploadToServer(isModified()); 658 648 } 659 649 … … 663 653 } 664 654 665 /** 666 * Initializes the layer after a successful save of OSM data to a file 667 * 668 */ 655 @Override 669 656 public void onPostSaveToFile() { 670 657 setRequiresSaveToFile(false); 671 setRequiresUploadToServer(data.isModified()); 672 } 673 674 /** 675 * Initializes the layer after a successful upload to the server 676 * 677 */ 658 setRequiresUploadToServer(isModified()); 659 } 660 661 @Override 678 662 public void onPostUploadToServer() { 679 setRequiresUploadToServer( data.isModified());663 setRequiresUploadToServer(isModified()); 680 664 // keep requiresSaveToDisk unchanged 681 665 } … … 730 714 } 731 715 716 @Override 732 717 public final boolean isUploadDiscouraged() { 733 718 return data.isUploadDiscouraged(); … … 741 726 } 742 727 } 728 } 729 730 @Override 731 public final boolean isModified() { 732 return data.isModified(); 743 733 } 744 734 … … 810 800 return SaveActionBase.createAndOpenSaveFileChooser(tr("Save OSM file"), "osm"); 811 801 } 802 803 @Override 804 public AbstractIOTask createUploadTask(final ProgressMonitor monitor) { 805 UploadDialog dialog = UploadDialog.getUploadDialog(); 806 return new UploadLayerTask( 807 dialog.getUploadStrategySpecification(), 808 this, 809 monitor, 810 dialog.getChangeset()); 811 } 812 813 @Override 814 public AbstractUploadDialog getUploadDialog() { 815 UploadDialog dialog = UploadDialog.getUploadDialog(); 816 dialog.setUploadedPrimitives(new APIDataSet(data)); 817 return dialog; 818 } 812 819 }
Note:
See TracChangeset
for help on using the changeset viewer.