org.openstreetmap.josm.gui.dialogs.relation
Class ParentRelationLoadingTask

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

public class ParentRelationLoadingTask
extends PleaseWaitRunnable

This is an asynchronous task for loading the parents of a given relation. Typical usage:

  final ParentRelationLoadingTask task = new ParentRelationLoadingTask(
                   child,   // the child relation
                   Main.main.getEditLayer(), // the edit layer
                   true,  // load fully
                   new PleaseWaitProgressMonitor()  // a progress monitor
   );
   task.setContinuation(
       new Runnable() {
          public void run() {
              if (task.isCanceled() || task.hasError())
                  return;
              List parents = task.getParents();
              // do something with the parent relations
       }
   );

   // start the task
   Main.worker.submit(task);
 


Field Summary
private  boolean canceled
           
private  Relation child
           
private  java.lang.Runnable continuation
           
private  boolean full
           
private  java.lang.Exception lastException
           
private  OsmDataLayer layer
           
private  java.util.ArrayList<Relation> parents
           
private  DataSet referrers
           
 
Fields inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
progressMonitor
 
Constructor Summary
ParentRelationLoadingTask(Relation child, OsmDataLayer layer, boolean full, PleaseWaitProgressMonitor monitor)
          Creates a new task for asynchronously downloading the parents of a child relation.
 
Method Summary
protected  void cancel()
          User pressed cancel button.
protected  void finish()
          Finish up the data work.
protected  OsmDataLayer getLayer()
           
 java.util.List<Relation> getParents()
           
 boolean hasError()
          Replies true if an exception has been caught during the execution of this task.
 boolean isCanceled()
          Replies true if this has been canceled by the user.
protected  void realRun()
          Called in the worker thread to do the actual work.
 void setContinuation(java.lang.Runnable continuation)
          Set a continuation which is called upon the job finished.
protected  void showLastException()
           
 
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
 

Field Detail

canceled

private boolean canceled

lastException

private java.lang.Exception lastException

referrers

private DataSet referrers

full

private boolean full

layer

private OsmDataLayer layer

child

private Relation child

parents

private java.util.ArrayList<Relation> parents

continuation

private java.lang.Runnable continuation
Constructor Detail

ParentRelationLoadingTask

public ParentRelationLoadingTask(Relation child,
                                 OsmDataLayer layer,
                                 boolean full,
                                 PleaseWaitProgressMonitor monitor)
Creates a new task for asynchronously downloading the parents of a child relation.

Parameters:
child - the child relation. Must not be null. Must have an id > 0.
layer - the OSM data layer. Must not be null.
full - if true, parent relations are fully downloaded (i.e. with their members)
monitor - the progress monitor to be used
Throws:
java.lang.IllegalArgumentException - thrown if child is null
java.lang.IllegalArgumentException - thrown if layer is null
java.lang.IllegalArgumentException - thrown if child.getId() == 0
Method Detail

setContinuation

public void setContinuation(java.lang.Runnable continuation)
Set a continuation which is called upon the job finished.

Parameters:
continuation - the continuation

isCanceled

public boolean isCanceled()
Replies true if this has been canceled by the user.

Returns:
true if this has been canceled by the user.

hasError

public boolean hasError()
Replies true if an exception has been caught during the execution of this task.

Returns:
true if an exception has been caught during the execution of this task.

getLayer

protected OsmDataLayer getLayer()

getParents

public java.util.List<Relation> getParents()

cancel

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

Specified by:
cancel in class PleaseWaitRunnable

showLastException

protected void showLastException()

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


JOSM