Changeset 7204 in josm
- Timestamp:
- 2014-06-01T14:07:18+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r7026 r7204 56 56 } 57 57 58 public static boolean doSave(Layer layer, File file) { 59 if(!layer.checkSaveConditions()) 58 /** 59 * Saves a layer to a given file. 60 * @param layer The layer to save 61 * @param file The destination file 62 * @param checkSaveConditions if {@code true}, checks preconditions before saving. Set it to {@code false} to skip it 63 * if preconditions have already been checked (as this check can prompt UI dialog in EDT it may be best in some cases 64 * to do it earlier). 65 * @return {@code true} if the layer has been successfully saved, {@code false} otherwise 66 * @since 7204 67 */ 68 public static boolean doSave(Layer layer, File file, boolean checkSaveConditions) { 69 if (checkSaveConditions && !layer.checkSaveConditions()) 60 70 return false; 61 71 return doInternalSave(layer, file); -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayerInfo.java
r6084 r7204 16 16 /** the osm data layer */ 17 17 private OsmDataLayer layer; 18 private boolean doCheckSaveConditions; 18 19 private boolean doSaveToFile; 19 20 private boolean doUploadToServer; … … 23 24 24 25 /** 25 * 26 * Constructs a new {@code SaveLayerInfo}. 26 27 * @param layer the layer. Must not be null. 27 28 * @throws IllegalArgumentException thrown if layer is null … … 30 31 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 31 32 this.layer = layer; 33 this.doCheckSaveConditions = true; 32 34 this.doSaveToFile = layer.requiresSaveToFile(); 33 35 this.doUploadToServer = layer.requiresUploadToServer() && !layer.isUploadDiscouraged(); … … 42 44 public OsmDataLayer getLayer() { 43 45 return layer; 46 } 47 48 /** 49 * Replies true if preconditions should be checked before saving; false, otherwise 50 * 51 * @return true if preconditions should be checked before saving; false, otherwise 52 * @since 7204 53 */ 54 public boolean isDoCheckSaveConditions() { 55 return doCheckSaveConditions; 56 } 57 58 /** 59 * Sets whether preconditions should be checked before saving 60 * 61 * @param doCheckSaveConditions true to check save preconditions; false, to skip checking 62 * @since 7204 63 */ 64 public void setDoCheckSaveConditions(boolean doCheckSaveConditions) { 65 this.doCheckSaveConditions = doCheckSaveConditions; 44 66 } 45 67 -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayerTask.java
r6830 r7204 49 49 try { 50 50 parentMonitor.subTask(tr("Saving layer to ''{0}'' ...", layerInfo.getFile().toString())); 51 if (!SaveAction.doSave(layerInfo.getLayer(), layerInfo.getFile() )) {51 if (!SaveAction.doSave(layerInfo.getLayer(), layerInfo.getFile(), layerInfo.isDoCheckSaveConditions())) { 52 52 setFailed(true); 53 53 return; -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r7029 r7204 506 506 continue; 507 507 } 508 currentTask= new SaveLayerTask(layerInfo, monitor); 508 // Check save preconditions earlier to avoid a blocking reentring call to EDT (see #10086) 509 if (layerInfo.isDoCheckSaveConditions()) { 510 if (!layerInfo.getLayer().checkSaveConditions()) { 511 continue; 512 } 513 layerInfo.setDoCheckSaveConditions(false); 514 } 515 currentTask = new SaveLayerTask(layerInfo, monitor); 509 516 currentFuture = worker.submit(currentTask); 510 517 -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r7026 r7204 1 1 // License: GPL. See LICENSE file for details. 2 3 2 package org.openstreetmap.josm.gui.layer; 4 3 … … 28 27 import java.util.List; 29 28 import java.util.Map; 29 import java.util.concurrent.Callable; 30 30 import java.util.concurrent.CopyOnWriteArrayList; 31 31 … … 78 78 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 79 79 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 80 import org.openstreetmap.josm.gui.util.GuiHelper; 80 81 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 81 82 import org.openstreetmap.josm.tools.DateUtils; … … 750 751 public boolean checkSaveConditions() { 751 752 if (isDataSetEmpty()) { 752 ExtendedDialog dialog = new ExtendedDialog( 753 Main.parent, 754 tr("Empty document"), 755 new String[] {tr("Save anyway"), tr("Cancel")} 756 ); 757 dialog.setContent(tr("The document contains no data.")); 758 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"}); 759 dialog.showDialog(); 760 if (dialog.getValue() != 1) return false; 753 if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 754 @Override 755 public Integer call() { 756 ExtendedDialog dialog = new ExtendedDialog( 757 Main.parent, 758 tr("Empty document"), 759 new String[] {tr("Save anyway"), tr("Cancel")} 760 ); 761 dialog.setContent(tr("The document contains no data.")); 762 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"}); 763 return dialog.showDialog().getValue(); 764 } 765 })) { 766 return false; 767 } 761 768 } 762 769 763 770 ConflictCollection conflicts = getConflicts(); 764 771 if (conflicts != null && !conflicts.isEmpty()) { 765 ExtendedDialog dialog = new ExtendedDialog( 766 Main.parent, 767 /* I18N: Display title of the window showing conflicts */ 768 tr("Conflicts"), 769 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")} 770 ); 771 dialog.setContent(tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?")); 772 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"}); 773 dialog.showDialog(); 774 if (dialog.getValue() != 1) return false; 772 if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 773 @Override 774 public Integer call() { 775 ExtendedDialog dialog = new ExtendedDialog( 776 Main.parent, 777 /* I18N: Display title of the window showing conflicts */ 778 tr("Conflicts"), 779 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")} 780 ); 781 dialog.setContent(tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?")); 782 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"}); 783 return dialog.showDialog().getValue(); 784 } 785 })) { 786 return false; 787 } 775 788 } 776 789 return true; -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r7004 r7204 22 22 import java.util.Arrays; 23 23 import java.util.List; 24 import java.util.concurrent.Callable; 25 import java.util.concurrent.ExecutionException; 26 import java.util.concurrent.FutureTask; 24 27 25 28 import javax.swing.GrayFilter; … … 68 71 } 69 72 73 /** 74 * Executes asynchronously a runnable in 75 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html">Event Dispatch Thread</a>. 76 * @param task The runnable to execute 77 * @see SwingUtilities#invokeLater 78 */ 70 79 public static void runInEDT(Runnable task) { 71 80 if (SwingUtilities.isEventDispatchThread()) { … … 76 85 } 77 86 87 /** 88 * Executes synchronously a runnable in 89 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html">Event Dispatch Thread</a>. 90 * @param task The runnable to execute 91 * @see SwingUtilities#invokeAndWait 92 */ 78 93 public static void runInEDTAndWait(Runnable task) { 79 94 if (SwingUtilities.isEventDispatchThread()) { … … 84 99 } catch (InterruptedException | InvocationTargetException e) { 85 100 Main.error(e); 101 } 102 } 103 } 104 105 /** 106 * Executes synchronously a callable in 107 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html">Event Dispatch Thread</a> 108 * and return a value. 109 * @param callable The callable to execute 110 * @return The computed result 111 * @since 7204 112 */ 113 public static <V> V runInEDTAndWaitAndReturn(Callable<V> callable) { 114 if (SwingUtilities.isEventDispatchThread()) { 115 try { 116 return callable.call(); 117 } catch (Exception e) { 118 Main.error(e); 119 return null; 120 } 121 } else { 122 FutureTask<V> task = new FutureTask<V>(callable); 123 SwingUtilities.invokeLater(task); 124 try { 125 return task.get(); 126 } catch (InterruptedException | ExecutionException e) { 127 Main.error(e); 128 return null; 86 129 } 87 130 }
Note:
See TracChangeset
for help on using the changeset viewer.