source: josm/trunk/src/org/openstreetmap/josm/gui/io/SaveLayerTask.java@ 13181

Last change on this file since 13181 was 12620, checked in by Don-vip, 7 years ago

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

  • Property svn:eol-style set to native
File size: 2.4 KB
RevLine 
[2512]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
[11553]6import java.util.Optional;
7
[2512]8import org.openstreetmap.josm.actions.SaveAction;
9import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
10import org.openstreetmap.josm.gui.progress.ProgressMonitor;
[2848]11import org.openstreetmap.josm.tools.CheckParameterUtil;
[11746]12import org.openstreetmap.josm.tools.JosmRuntimeException;
[12620]13import org.openstreetmap.josm.tools.Logging;
[2512]14
15/**
[7402]16 * SaveLayerTask saves the data managed by an {@link org.openstreetmap.josm.gui.layer.AbstractModifiableLayer} to the
[7358]17 * {@link org.openstreetmap.josm.gui.layer.Layer#getAssociatedFile()}.
[2512]18 *
19 * <pre>
20 * ExecutorService executorService = ...
21 * SaveLayerTask task = new SaveLayerTask(layer, monitor);
[8734]22 * Future&lt;?&gt; taskFuture = executorService.submit(task)
[2512]23 * try {
24 * // wait for the task to complete
25 * taskFuture.get();
[8510]26 * } catch (Exception e) {
[8734]27 * e.printStackTrace();
[2512]28 * }
29 * </pre>
30 */
[7358]31public class SaveLayerTask extends AbstractIOTask {
[9078]32 private final SaveLayerInfo layerInfo;
33 private final ProgressMonitor parentMonitor;
[2512]34
35 /**
36 *
37 * @param layerInfo information about the layer to be saved to save. Must not be null.
[5266]38 * @param monitor the monitor. Set to {@link NullProgressMonitor#INSTANCE} if null
[8291]39 * @throws IllegalArgumentException if layer is null
[2512]40 */
41 protected SaveLayerTask(SaveLayerInfo layerInfo, ProgressMonitor monitor) {
[2848]42 CheckParameterUtil.ensureParameterNotNull(layerInfo, "layerInfo");
[10378]43 this.layerInfo = layerInfo;
[11553]44 this.parentMonitor = Optional.ofNullable(monitor).orElse(NullProgressMonitor.INSTANCE);
[2512]45 }
46
47 @Override
48 public void run() {
49 try {
50 parentMonitor.subTask(tr("Saving layer to ''{0}'' ...", layerInfo.getFile().toString()));
[7204]51 if (!SaveAction.doSave(layerInfo.getLayer(), layerInfo.getFile(), layerInfo.isDoCheckSaveConditions())) {
[2512]52 setFailed(true);
53 return;
54 }
[4310]55 if (!isCanceled()) {
[2512]56 layerInfo.getLayer().onPostSaveToFile();
57 }
[11746]58 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
[12620]59 Logging.error(e);
[2512]60 setLastException(e);
61 }
62 }
63
64 @Override
65 public void cancel() {
[4310]66 setCanceled(true);
[2512]67 }
68}
Note: See TracBrowser for help on using the repository browser.