- Timestamp:
- 2019-10-02T23:11:24+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r14690 r15404 219 219 // make this action listen to layer change and selection change events 220 220 if (listenToLayerChange()) { 221 layerChangeAdapter = newLayerChangeAdapter();222 activeLayerChangeAdapter = newActiveLayerChangeAdapter();221 layerChangeAdapter = buildLayerChangeAdapter(); 222 activeLayerChangeAdapter = buildActiveLayerChangeAdapter(); 223 223 getLayerManager().addLayerChangeListener(layerChangeAdapter); 224 224 getLayerManager().addActiveLayerChangeListener(activeLayerChangeAdapter); … … 229 229 } 230 230 initEnabledState(); 231 } 232 233 /** 234 * Override this if calling {@link #updateEnabledState()} on layer change events is not enough. 235 * @return the {@link LayerChangeAdapter} that will be called on layer change events 236 * @since 15404 237 */ 238 protected LayerChangeAdapter buildLayerChangeAdapter() { 239 return new LayerChangeAdapter(); 240 } 241 242 /** 243 * Override this if calling {@link #updateEnabledState()} on active layer change event is not enough. 244 * @return the {@link LayerChangeAdapter} that will be called on active layer change event 245 * @since 15404 246 */ 247 protected ActiveLayerChangeAdapter buildActiveLayerChangeAdapter() { 248 return new ActiveLayerChangeAdapter(); 231 249 } 232 250 -
trunk/src/org/openstreetmap/josm/actions/SaveAction.java
r14397 r15404 6 6 7 7 import java.awt.event.KeyEvent; 8 import java.beans.PropertyChangeListener; 8 9 import java.io.File; 9 10 … … 12 13 import org.openstreetmap.josm.gui.layer.GpxLayer; 13 14 import org.openstreetmap.josm.gui.layer.Layer; 15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 import org.openstreetmap.josm.gui.layer.SaveToFile; 14 19 import org.openstreetmap.josm.tools.Shortcut; 15 20 … … 21 26 public final class SaveAction extends SaveActionBase { 22 27 private static SaveAction instance = new SaveAction(); 28 29 private final PropertyChangeListener updateOnRequireSaveChange = evt -> { 30 if (OsmDataLayer.REQUIRES_SAVE_TO_DISK_PROP.equals(evt.getPropertyName())) { 31 updateEnabledState(); 32 } 33 }; 23 34 24 35 /** … … 39 50 } 40 51 41 @Override public File getFile(Layer layer) { 52 @Override 53 protected LayerChangeAdapter buildLayerChangeAdapter() { 54 return new LayerChangeAdapter() { 55 @Override 56 public void layerAdded(LayerAddEvent e) { 57 if (e.getAddedLayer() instanceof OsmDataLayer) { 58 e.getAddedLayer().addPropertyChangeListener(updateOnRequireSaveChange); 59 } 60 super.layerAdded(e); 61 } 62 63 @Override 64 public void layerRemoving(LayerRemoveEvent e) { 65 if (e.getRemovedLayer() instanceof OsmDataLayer) { 66 e.getRemovedLayer().removePropertyChangeListener(updateOnRequireSaveChange); 67 } 68 super.layerRemoving(e); 69 } 70 }; 71 } 72 73 @Override 74 protected void updateEnabledState() { 75 Layer activeLayer = getLayerManager().getActiveLayer(); 76 setEnabled(activeLayer != null && activeLayer.isSavable() 77 && (!(activeLayer.getAssociatedFile() != null 78 && activeLayer instanceof SaveToFile && !((SaveToFile) activeLayer).requiresSaveToFile()))); 79 } 80 81 @Override 82 public File getFile(Layer layer) { 42 83 File f = layer.getAssociatedFile(); 43 84 if (f != null && !f.exists()) { -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r14950 r15404 22 22 import org.openstreetmap.josm.gui.layer.Layer; 23 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 import org.openstreetmap.josm.gui.layer.SaveToFile; 24 25 import org.openstreetmap.josm.gui.util.GuiHelper; 25 26 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; … … 73 74 if (!layer.checkSaveConditions()) 74 75 return false; 75 return doInternalSave(layer, getFile(layer)); 76 final boolean requiresSave = layer instanceof SaveToFile && ((SaveToFile) layer).requiresSaveToFile(); 77 final boolean result = doInternalSave(layer, getFile(layer)); 78 if (!requiresSave) { 79 updateEnabledState(); 80 } 81 return result; 76 82 } 77 83 … … 122 128 ((OsmDataLayer) layer).onPostSaveToFile(); 123 129 } 124 MainApplication.getMainFrame().repaint();125 130 } catch (IOException | InvalidPathException e) { 126 131 showAndLogException(e); … … 133 138 protected abstract File getFile(Layer layer); 134 139 135 /**136 * Refreshes the enabled state137 *138 */139 140 @Override 140 141 protected void updateEnabledState() { -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r14397 r15404 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.beans.PropertyChangeListener; 9 10 import java.util.LinkedList; 10 11 import java.util.List; … … 25 26 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 26 27 import org.openstreetmap.josm.gui.MainApplication; 28 import org.openstreetmap.josm.gui.Notification; 27 29 import org.openstreetmap.josm.gui.io.AsynchronousUploadPrimitivesTask; 28 30 import org.openstreetmap.josm.gui.io.UploadDialog; 29 31 import org.openstreetmap.josm.gui.io.UploadPrimitivesTask; 30 32 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer; 33 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 34 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 31 35 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 32 36 import org.openstreetmap.josm.gui.util.GuiHelper; … … 41 45 * Action that opens a connection to the osm server and uploads all changes. 42 46 * 43 * A ndialog is displayed asking the user to specify a rectangle to grab.47 * A dialog is displayed asking the user to specify a rectangle to grab. 44 48 * The url and account settings from the preferences are used. 45 49 * … … 91 95 } 92 96 97 private final PropertyChangeListener updateOnRequireUploadChange = evt -> { 98 if (OsmDataLayer.REQUIRES_UPLOAD_TO_SERVER_PROP.equals(evt.getPropertyName())) { 99 updateEnabledState(); 100 } 101 }; 102 93 103 /** 94 104 * Registers an upload hook. Adds the hook at the first position of the upload hooks. … … 146 156 147 157 @Override 158 protected LayerChangeAdapter buildLayerChangeAdapter() { 159 return new LayerChangeAdapter() { 160 @Override 161 public void layerAdded(LayerAddEvent e) { 162 if (e.getAddedLayer() instanceof OsmDataLayer) { 163 e.getAddedLayer().addPropertyChangeListener(updateOnRequireUploadChange); 164 } 165 super.layerAdded(e); 166 } 167 168 @Override 169 public void layerRemoving(LayerRemoveEvent e) { 170 if (e.getRemovedLayer() instanceof OsmDataLayer) { 171 e.getRemovedLayer().removePropertyChangeListener(updateOnRequireUploadChange); 172 } 173 super.layerRemoving(e); 174 } 175 }; 176 } 177 178 @Override 148 179 protected void updateEnabledState() { 149 180 OsmDataLayer editLayer = getLayerManager().getEditLayer(); 150 setEnabled(editLayer != null && editLayer. isUploadable());181 setEnabled(editLayer != null && editLayer.requiresUploadToServer()); 151 182 } 152 183 … … 232 263 public void uploadData(final OsmDataLayer layer, APIDataSet apiData) { 233 264 if (apiData.isEmpty()) { 234 JOptionPane.showMessageDialog( 235 MainApplication.getMainFrame(), 236 tr("No changes to upload."), 237 tr("Warning"), 238 JOptionPane.INFORMATION_MESSAGE 239 ); 265 new Notification(tr("No changes to upload.")).show(); 240 266 return; 241 267 } … … 292 318 return; 293 319 if (MainApplication.getMap() == null) { 294 JOptionPane.showMessageDialog( 295 MainApplication.getMainFrame(), 296 tr("Nothing to upload. Get some data first."), 297 tr("Warning"), 298 JOptionPane.WARNING_MESSAGE 299 ); 320 new Notification(tr("Nothing to upload. Get some data first.")).show(); 300 321 return; 301 322 } -
trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
r15152 r15404 14 14 import java.util.stream.Collectors; 15 15 16 import javax.swing.JOptionPane;17 16 import javax.swing.SwingUtilities; 18 17 … … 26 25 import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor; 27 26 import org.openstreetmap.josm.gui.MainApplication; 27 import org.openstreetmap.josm.gui.Notification; 28 28 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 29 29 import org.openstreetmap.josm.gui.io.UploadSelectionDialog; … … 65 65 updateEnabledStateOnModifiableSelection(selection); 66 66 OsmDataLayer editLayer = getLayerManager().getEditLayer(); 67 if (editLayer != null && !editLayer.isUploadable()) { 67 if (isEnabled() && editLayer != null && !editLayer.isUploadable()) { 68 setEnabled(false); 69 } 70 if (isEnabled() && selection.stream().noneMatch(OsmPrimitive::isModified)) { 68 71 setEnabled(false); 69 72 } … … 93 96 Collection<OsmPrimitive> deletedCandidates = getDeletedPrimitives(editLayer.getDataSet()); 94 97 if (modifiedCandidates.isEmpty() && deletedCandidates.isEmpty()) { 95 JOptionPane.showMessageDialog( 96 MainApplication.getMainFrame(), 97 tr("No changes to upload."), 98 tr("Warning"), 99 JOptionPane.INFORMATION_MESSAGE 100 ); 98 new Notification(tr("No changes to upload.")).show(); 101 99 return; 102 100 } … … 111 109 Collection<OsmPrimitive> toUpload = new UploadHullBuilder().build(dialog.getSelectedPrimitives()); 112 110 if (toUpload.isEmpty()) { 113 JOptionPane.showMessageDialog( 114 MainApplication.getMainFrame(), 115 tr("No changes to upload."), 116 tr("Warning"), 117 JOptionPane.INFORMATION_MESSAGE 118 ); 111 new Notification(tr("No changes to upload.")).show(); 119 112 return; 120 113 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r15378 r15404 825 825 @Override 826 826 public boolean isModified() { 827 for (OsmPrimitive p : allPrimitives) { 828 if (p.isModified()) 829 return true; 830 } 831 return false; 827 return allPrimitives.parallelStream().anyMatch(OsmPrimitive::isModified); 832 828 } 833 829 … … 838 834 */ 839 835 public boolean requiresUploadToServer() { 840 for (OsmPrimitive p : allPrimitives) { 841 if (APIOperation.of(p) != null) 842 return true; 843 } 844 return false; 836 return allPrimitives.parallelStream().anyMatch(p -> APIOperation.of(p) != null); 845 837 } 846 838 -
trunk/src/org/openstreetmap/josm/io/session/GenericSessionExporter.java
r14741 r15404 28 28 import org.openstreetmap.josm.gui.layer.Layer; 29 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 import org.openstreetmap.josm.gui.layer.SaveToFile; 30 31 import org.openstreetmap.josm.gui.util.GuiHelper; 31 32 import org.openstreetmap.josm.gui.widgets.JosmTextField; … … 73 74 LayerSaveAction() { 74 75 new ImageProvider("save").getResource().attachImageIcon(this); 75 putValue(SHORT_DESCRIPTION, (( AbstractModifiableLayer) layer).requiresSaveToFile() ?76 putValue(SHORT_DESCRIPTION, ((SaveToFile) layer).requiresSaveToFile() ? 76 77 tr("Layer contains unsaved data - save to file.") : 77 78 tr("Layer does not contain unsaved data.")); … … 86 87 87 88 public final void updateEnabledState() { 88 setEnabled((( AbstractModifiableLayer) layer).requiresSaveToFile());89 setEnabled(((SaveToFile) layer).requiresSaveToFile()); 89 90 } 90 91 }
Note:
See TracChangeset
for help on using the changeset viewer.