org.openstreetmap.josm.gui.dialogs.changeset
Class ChangesetContentDownloadTask

java.lang.Object
  extended by org.openstreetmap.josm.gui.PleaseWaitRunnable
      extended by org.openstreetmap.josm.gui.dialogs.changeset.ChangesetContentDownloadTask
All Implemented Interfaces:
java.lang.Runnable, ChangesetDownloadTask, ProgressMonitor.CancelListener

public class ChangesetContentDownloadTask
extends PleaseWaitRunnable
implements ChangesetDownloadTask

This is an asynchronous task for downloading the changeset content of a collection of changesets.


Field Summary
private  boolean canceled
          true if the task was canceled
private  java.util.Set<Changeset> downloadedChangesets
          the set of downloaded changesets
private  java.lang.Exception lastException
          keeps the last exception thrown in the task, if any
private  OsmServerChangesetReader reader
          the reader object used to read changesets from the API
private  java.util.List<java.lang.Integer> toDownload
          the list of changeset ids to download
 
Fields inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
progressMonitor
 
Constructor Summary
ChangesetContentDownloadTask(java.util.Collection<java.lang.Integer> changesetIds)
          Creates a download task for a collection of changesets.
ChangesetContentDownloadTask(java.awt.Component parent, java.util.Collection<java.lang.Integer> changesetIds)
          Creates a download task for a collection of changesets.
ChangesetContentDownloadTask(java.awt.Component parent, int changesetId)
          Creates a download task for a single changeset
ChangesetContentDownloadTask(int changesetId)
          Creates a download task for a single changeset
 
Method Summary
protected  void cancel()
          User pressed cancel button.
protected  void downloadChangeset(int changesetId)
          Downloads the changeset with id changesetId (only "header" information, no content)
protected  void finish()
          Finish up the data work.
 java.util.Set<Changeset> getDownloadedChangesets()
           
protected  void init(java.util.Collection<java.lang.Integer> ids)
          Initialize the task with a collection of changeset ids to download
protected  boolean isAvailableLocally(int changesetId)
          Replies true if the local ChangesetCache already includes the changeset with id changesetId.
 boolean isCanceled()
           
 boolean isFailed()
           
protected  void realRun()
          Called in the worker thread to do the actual work.
 
Methods inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
afterFinish, canRunInBackground, getProgressMonitor, operationCanceled, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

toDownload

private final java.util.List<java.lang.Integer> toDownload
the list of changeset ids to download


canceled

private boolean canceled
true if the task was canceled


lastException

private java.lang.Exception lastException
keeps the last exception thrown in the task, if any


reader

private OsmServerChangesetReader reader
the reader object used to read changesets from the API


downloadedChangesets

private java.util.Set<Changeset> downloadedChangesets
the set of downloaded changesets

Constructor Detail

ChangesetContentDownloadTask

public ChangesetContentDownloadTask(int changesetId)
                             throws java.lang.IllegalArgumentException
Creates a download task for a single changeset

Parameters:
changesetId - the changeset id. >0 required.
Throws:
java.lang.IllegalArgumentException - thrown if changesetId <= 0

ChangesetContentDownloadTask

public ChangesetContentDownloadTask(java.util.Collection<java.lang.Integer> changesetIds)
Creates a download task for a collection of changesets. null values and id <=0 in the collection are sillently discarded.

Parameters:
changesetIds - the changeset ids. Empty collection assumed, if null.

ChangesetContentDownloadTask

public ChangesetContentDownloadTask(java.awt.Component parent,
                                    int changesetId)
                             throws java.lang.IllegalArgumentException
Creates a download task for a single changeset

Parameters:
parent - the parent component for the PleaseWaitDialog. Must not be null.
changesetId - the changeset id. >0 required.
Throws:
java.lang.IllegalArgumentException - thrown if changesetId <= 0
java.lang.IllegalArgumentException - thrown if parent is null

ChangesetContentDownloadTask

public ChangesetContentDownloadTask(java.awt.Component parent,
                                    java.util.Collection<java.lang.Integer> changesetIds)
                             throws java.lang.IllegalArgumentException
Creates a download task for a collection of changesets. null values and id <=0 in the collection are sillently discarded.

Parameters:
parent - the parent component for the PleaseWaitDialog. Must not be null.
changesetIds - the changeset ids. Empty collection assumed, if null.
Throws:
java.lang.IllegalArgumentException - thrown if parent is null
Method Detail

init

protected void init(java.util.Collection<java.lang.Integer> ids)
Initialize the task with a collection of changeset ids to download

Parameters:
ids - the collection of ids. May be null.

isAvailableLocally

protected boolean isAvailableLocally(int changesetId)
Replies true if the local ChangesetCache already includes the changeset with id changesetId.

Parameters:
changesetId - the changeset id
Returns:
true if the local ChangesetCache already includes the changeset with id changesetId

downloadChangeset

protected void downloadChangeset(int changesetId)
                          throws OsmTransferException
Downloads the changeset with id changesetId (only "header" information, no content)

Parameters:
changesetId - the changeset id
Throws:
OsmTransferException - thrown if something went wrong

cancel

protected void cancel()
Description copied from class: PleaseWaitRunnable
User pressed cancel button.

Specified by:
cancel in class PleaseWaitRunnable

finish

protected void finish()
Description copied from class: PleaseWaitRunnable
Finish up the data work. Is guaranteed to be called if realRun is called. Finish is called in the gui thread just after the dialog disappeared.

Specified by:
finish in class PleaseWaitRunnable

realRun

protected void realRun()
                throws org.xml.sax.SAXException,
                       java.io.IOException,
                       OsmTransferException
Description copied from class: PleaseWaitRunnable
Called in the worker thread to do the actual work. When any of the exception is thrown, a message box will be displayed and closeDialog is called. finish() is called in any case.

Specified by:
realRun in class PleaseWaitRunnable
Throws:
org.xml.sax.SAXException
java.io.IOException
OsmTransferException

getDownloadedChangesets

public java.util.Set<Changeset> getDownloadedChangesets()
Specified by:
getDownloadedChangesets in interface ChangesetDownloadTask

isCanceled

public boolean isCanceled()
Specified by:
isCanceled in interface ChangesetDownloadTask

isFailed

public boolean isFailed()
Specified by:
isFailed in interface ChangesetDownloadTask


JOSM