source: josm/trunk/src/org/openstreetmap/josm/gui/io/CloseChangesetTask.java@ 2613

Last change on this file since 2613 was 2613, checked in by Gubaer, 14 years ago

new: global in-memory cache for downloaded changesets
new: toggle dialog for changesets
new: downloading of changesets (currently without changeset content, will follow later)

File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7import java.util.ArrayList;
8import java.util.Collection;
9
10import javax.swing.SwingUtilities;
11
12import org.openstreetmap.josm.data.osm.Changeset;
13import org.openstreetmap.josm.data.osm.ChangesetCache;
14import org.openstreetmap.josm.gui.ExceptionDialogUtil;
15import org.openstreetmap.josm.gui.PleaseWaitRunnable;
16import org.openstreetmap.josm.io.OsmApi;
17import org.openstreetmap.josm.io.OsmTransferException;
18import org.xml.sax.SAXException;
19
20/**
21 * A task for closing a collection of changesets.
22 *
23 */
24public class CloseChangesetTask extends PleaseWaitRunnable {
25 private boolean cancelled;
26 private Exception lastException;
27 private Collection<Changeset> changesets;
28 private ArrayList<Changeset> closedChangesets;
29
30 /**
31 * Closes all changesets in <code>changesets</code> if they are not null, if they
32 * are still open and if they have an id > 0. Other changesets in the collection
33 * are ignored.
34 *
35 * @param changesets the collection of changesets. Empty collection assumes, if null.
36 */
37 public CloseChangesetTask(Collection<Changeset> changesets) {
38 super(tr("Closing changeset"), false /* don't ignore exceptions */);
39 if (changesets == null) {
40 changesets = new ArrayList<Changeset>();
41 }
42 this.changesets = changesets;
43 this.closedChangesets = new ArrayList<Changeset>();
44 }
45
46 @Override
47 protected void cancel() {
48 this.cancelled = true;
49 OsmApi.getOsmApi().cancel();
50 }
51
52 @Override
53 protected void finish() {
54 if (cancelled)
55 return;
56 if (lastException != null) {
57 ExceptionDialogUtil.explainException(lastException);
58 }
59 SwingUtilities.invokeLater(
60 new Runnable() {
61 public void run() {
62 ChangesetCache.getInstance().update(closedChangesets);
63 }
64 }
65 );
66 }
67
68 @Override
69 protected void realRun() throws SAXException, IOException, OsmTransferException {
70 try {
71 for (Changeset cs: changesets) {
72 if (cancelled) return;
73 if (cs == null || cs.getId() <= 0 || ! cs.isOpen()) {
74 continue;
75 }
76 getProgressMonitor().subTask(tr("Closing changeset {0}", cs.getId()));
77 OsmApi.getOsmApi().closeChangeset(cs, getProgressMonitor().createSubTaskMonitor(1, false));
78 closedChangesets.add(cs);
79 }
80 } catch(Exception e) {
81 if (cancelled)
82 return;
83 lastException = e;
84 }
85 }
86}
Note: See TracBrowser for help on using the repository browser.