Index: applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
===================================================================
--- applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java	(revision 21237)
+++ applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java	(revision 21625)
@@ -2,8 +2,10 @@
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.openstreetmap.josm.Main;
@@ -15,4 +17,5 @@
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.data.osm.PrimitiveId;
 import org.openstreetmap.josm.data.osm.Relation;
@@ -22,14 +25,23 @@
 import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
-import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.data.osm.history.HistoryRelation;
+import org.openstreetmap.josm.data.osm.history.HistoryWay;
+import org.openstreetmap.josm.data.osm.history.RelationMember;
 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
+import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
 import org.openstreetmap.josm.io.OsmServerChangesetReader;
 import org.openstreetmap.josm.io.OsmTransferException;
 
 public class ChangesetReverter {
-    private int changesetId;
-    private Changeset changeset;
-    private ChangesetDataSet osmchange;
+    public final int changesetId;
+    public final Changeset changeset;
+
+    private final DataSet ds;
+    private final ChangesetDataSet osmchange;
+
+    private final HashSet<PrimitiveId> missing = new HashSet<PrimitiveId>();
+    private LinkedList<Command> cmds;
+
     static class MyCsDataset {
         public HashMap<PrimitiveId,Integer> created = new HashMap<PrimitiveId,Integer>();
@@ -65,19 +77,47 @@
     }
     
-    public ChangesetReverter(int changesetId) {
+    private void AddIfMissing(PrimitiveId id) {
+        if (ds.getPrimitiveById(id) == null) {
+            missing.add(id);
+        }
+    }
+    private void AddMissingIds(Set<HistoryOsmPrimitive> primitives) {
+        for (HistoryOsmPrimitive p : primitives) {
+            AddIfMissing(new SimplePrimitiveId(p.getId(),p.getType()));
+            if (p.getType() == OsmPrimitiveType.WAY) {
+                for (long nd : ((HistoryWay)p).getNodes()) {
+                    AddIfMissing(new SimplePrimitiveId(nd,OsmPrimitiveType.NODE));
+                }
+            }
+            if (p.getType() == OsmPrimitiveType.RELATION) {
+                for (RelationMember member : ((HistoryRelation)p).getMembers()) {
+                    AddIfMissing(new SimplePrimitiveId(member.getPrimitiveId(),
+                            member.getPrimitiveType()));
+                }
+            }
+        }
+    }
+    private void CheckMissing() {
+        /* Create list of objects that created or modified my the changeset but
+         * doesn't present in the current dataset. 
+         */
+        missing.clear();
+        AddMissingIds(osmchange.
+                getPrimitivesByModificationType(ChangesetModificationType.CREATED));
+        AddMissingIds(osmchange.
+                getPrimitivesByModificationType(ChangesetModificationType.UPDATED));
+    }
+    
+    public ChangesetReverter(int changesetId) throws OsmTransferException {
         this.changesetId = changesetId;
-        try {
-            OsmServerChangesetReader csr = new OsmServerChangesetReader();
-            changeset = csr.readChangeset(changesetId, NullProgressMonitor.INSTANCE);
-            osmchange = csr.downloadChangeset(changesetId, NullProgressMonitor.INSTANCE);
-        } catch (OsmTransferException e) {
-            e.printStackTrace();
-        }
-    }
-    LinkedList<Command> cmds;
+        this.ds = Main.main.getCurrentDataSet();
+
+        OsmServerChangesetReader csr = new OsmServerChangesetReader();
+        changeset = csr.readChangeset(changesetId, NullProgressMonitor.INSTANCE);
+        osmchange = csr.downloadChangeset(changesetId, NullProgressMonitor.INSTANCE);
+        CheckMissing();
+    }
 
     public void RevertChangeset(ProgressMonitor progressMonitor) throws OsmTransferException {
-        final OsmDataLayer layer = Main.main.getEditLayer();
-        final DataSet ds = layer.data;
         final MyCsDataset cds = new MyCsDataset(osmchange);
         final OsmServerMultiObjectReader rdr = new OsmServerMultiObjectReader();
@@ -90,8 +130,10 @@
                 rdr.ReadObject(entry.getKey().getUniqueId(), entry.getValue()-1, entry.getKey().getType(),
                         progressMonitor.createSubTaskMonitor(1, true));
+                if (progressMonitor.isCancelled()) return;
             }
             for (Map.Entry<PrimitiveId,Integer> entry : cds.deleted.entrySet()) {
                 rdr.ReadObject(entry.getKey().getUniqueId(), entry.getValue()-1, entry.getKey().getType(),
                         progressMonitor.createSubTaskMonitor(1, true));
+                if (progressMonitor.isCancelled()) return;
             }
             final DataSet nds = rdr.parseOsm(progressMonitor.createSubTaskMonitor(1, true));
@@ -126,6 +168,52 @@
         }
     }
+    
+    public void DownloadMissingPrimitives(ProgressMonitor monitor) throws OsmTransferException {
+        MultiFetchServerObjectReader rdr = new MultiFetchServerObjectReader();
+        for (PrimitiveId id : missing) {
+            switch (id.getType()) {
+            case NODE:
+                rdr.append(new Node(id.getUniqueId()));
+                break;
+            case WAY:
+                rdr.append(new Way(id.getUniqueId()));
+                break;
+            case RELATION:
+                rdr.append(new Relation(id.getUniqueId()));
+                break;
+            default: throw new AssertionError();
+            }
+        }
+        DataSet from = rdr.parseOsm(monitor);
+        for (Node n : from.getNodes()) {
+            if (ds.getPrimitiveById(n) == null) {
+                ds.addPrimitive(new Node(n));
+            }
+        }
+        for (Way w : from.getWays()) {
+            if (ds.getPrimitiveById(w) == null) {
+                Way nw = new Way(w.getId());
+                ds.addPrimitive(nw);
+                nw.load(w.save());
+            }
+        }
+        final LinkedList<Relation> rels = new LinkedList<Relation>();
+        for (Relation r : from.getRelations()) {
+            if (ds.getPrimitiveById(r) == null) {
+                ds.addPrimitive(new Relation(r.getId()));
+                rels.add(r);
+            }
+        }
+        for (Relation r : rels) {
+            ((Relation)ds.getPrimitiveById(r)).load(r.save());
+        }
+        missing.clear();
+    }
+    
     public List<Command> getCommands() {
         return cmds;
     }
+    public Set<PrimitiveId> getMissingObjects() {
+        return missing;
+    }
 }
Index: applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
===================================================================
--- applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java	(revision 21237)
+++ applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java	(revision 21625)
@@ -7,4 +7,6 @@
 import java.util.List;
 
+import javax.swing.JOptionPane;
+
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
@@ -12,4 +14,5 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.io.OsmTransferException;
@@ -33,5 +36,5 @@
         setEnabled(getCurrentDataSet() != null);
     }
-    
+
     public void actionPerformed(ActionEvent arg0) {
         if (getCurrentDataSet() == null)
@@ -44,15 +47,28 @@
         Main.worker.submit(new PleaseWaitRunnable(tr("Reverting...")) {
             @Override
-            protected void realRun() {
-                try {
-                    ChangesetReverter rev = new ChangesetReverter(changesetId);
-                    rev.RevertChangeset(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, true));
-                    List<Command> cmds = rev.getCommands();
-                    Command cmd = new SequenceCommand(tr("Revert changeset #{0}",changesetId),cmds);
-                    Main.main.undoRedo.add(cmd);
-                } catch (OsmTransferException e) {
-                    e.printStackTrace();
-                } finally {
+            protected void realRun() throws OsmTransferException {
+                ChangesetReverter rev = new ChangesetReverter(changesetId);
+                if (!rev.getMissingObjects().isEmpty())
+                {
+                    if (JOptionPane.showConfirmDialog(Main.parent,
+                            tr("This changeset have objects outside the downloaded area.\n" + 
+                                    "It is needed to download them before reverting. Do you want to continue?"),
+                            tr("Confirm"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
+                        final PleaseWaitProgressMonitor monitor = 
+                            new PleaseWaitProgressMonitor(tr("Fetching missing primitives"));
+                        try {
+                            rev.DownloadMissingPrimitives(monitor);
+                        } finally {
+                            monitor.close();
+                        }
+                    } else {
+                        return;
+                    }
                 }
+                rev.RevertChangeset(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, true));
+                if (progressMonitor.isCancelled()) return;
+                List<Command> cmds = rev.getCommands();
+                Command cmd = new SequenceCommand(tr("Revert changeset #{0}",changesetId),cmds);
+                Main.main.undoRedo.add(cmd);
             }
 
