Changeset 21125 in osm for applications
- Timestamp:
- 2010-05-05T02:17:18+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/undelete/src/org/openstreetmap/josm/plugins/undelete/Undelete.java
r21124 r21125 131 131 */ 132 132 public void undelete(boolean newLayer, final OsmPrimitiveType type, final List<Long> ids, final long parent) { 133 OsmDataLayer layer = Main.main.getEditLayer();134 if (( layer == null) || newLayer) {135 layer = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null);136 Main.main.addLayer( layer);133 OsmDataLayer tmpLayer = Main.main.getEditLayer(); 134 if ((tmpLayer == null) || newLayer) { 135 tmpLayer = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null); 136 Main.main.addLayer(tmpLayer); 137 137 } 138 138 139 final DataSet datas = layer.data; 139 final DataSet datas = tmpLayer.data; 140 final OsmDataLayer layer=tmpLayer; 140 141 141 142 HistoryLoadTask task = new HistoryLoadTask(); … … 158 159 159 160 OsmPrimitive primitive; 160 HistoryOsmPrimitive hPrimitive1 ;161 HistoryOsmPrimitive hPrimitive1=h.getLatest(); 161 162 HistoryOsmPrimitive hPrimitive2; 162 163 163 if (type.equals(OsmPrimitiveType.NODE)) 164 boolean visible=hPrimitive1.isVisible(); 165 166 if (visible) 164 167 { 165 // We get all info from the latest version 166 hPrimitive1=h.getLatest(); 167 hPrimitive2=hPrimitive1; 168 169 Node node = new Node(id, (int) hPrimitive1.getVersion()); 170 171 HistoryNode hNode = (HistoryNode) hPrimitive1; 172 node.setCoor(hNode.getCoords()); 173 174 primitive=node; 175 if (parent>0) 168 // If the object is not deleted we get the real object 169 DownloadPrimitiveTask download=new DownloadPrimitiveTask(new SimplePrimitiveId(id, type), layer); 170 System.out.println(tr("Will get {0}", id)); 171 download.run(); 172 173 174 System.out.println(tr("Looking for {0}", id)); 175 primitive=datas.getPrimitiveById(id, type); 176 System.out.println(tr("Found {0}", primitive.getId())); 177 if (parent>0 && type.equals(OsmPrimitiveType.NODE)) 176 178 { 177 nodes.add(node); 178 } 179 } 180 else if (type.equals(OsmPrimitiveType.WAY)) 181 { 182 // We get version and user from the latest version, nodes and tags from n-1 version 183 hPrimitive1 = h.getLatest(); 184 hPrimitive2 = h.getByVersion(h.getNumVersions()-1); 185 186 187 188 Way way = new Way(id, (int) hPrimitive1.getVersion()); 189 190 HistoryWay hWay = (HistoryWay) hPrimitive2; 191 //System.out.println(tr("Primitive {0} version {1}: {2} nodes", hPrimitive2.getId(), hPrimitive2.getVersion(), hWay.getNumNodes())); 192 List<Long> nodeIds = hWay.getNodes(); 193 undelete(false, OsmPrimitiveType.NODE, nodeIds, id); 194 195 primitive=way; 196 179 nodes.add((Node)primitive); 180 } 197 181 } 198 182 else 199 { 200 primitive=new Node(); 201 hPrimitive1=h.getLatest(); 202 hPrimitive2=h.getLatest(); 183 { 184 if (type.equals(OsmPrimitiveType.NODE)) 185 { 186 // We get all info from the latest version 187 hPrimitive2=hPrimitive1; 188 189 Node node = new Node(id, (int) hPrimitive1.getVersion()); 190 191 HistoryNode hNode = (HistoryNode) hPrimitive1; 192 node.setCoor(hNode.getCoords()); 193 194 primitive=node; 195 if (parent>0) 196 { 197 nodes.add(node); 198 } 199 } 200 else if (type.equals(OsmPrimitiveType.WAY)) 201 { 202 // We get version and user from the latest version, nodes and tags from n-1 version 203 hPrimitive1 = h.getLatest(); 204 hPrimitive2 = h.getByVersion(h.getNumVersions()-1); 205 206 207 208 Way way = new Way(id, (int) hPrimitive1.getVersion()); 209 210 HistoryWay hWay = (HistoryWay) hPrimitive2; 211 //System.out.println(tr("Primitive {0} version {1}: {2} nodes", hPrimitive2.getId(), hPrimitive2.getVersion(), hWay.getNumNodes())); 212 List<Long> nodeIds = hWay.getNodes(); 213 undelete(false, OsmPrimitiveType.NODE, nodeIds, id); 214 215 primitive=way; 216 217 } 218 else 219 { 220 primitive=new Node(); 221 hPrimitive1=h.getLatest(); 222 hPrimitive2=h.getLatest(); 223 } 224 225 User user = User.createOsmUser(hPrimitive1.getUid(), hPrimitive1.getUser()); 226 227 primitive.setUser(user); 228 229 primitive.setKeys(hPrimitive2.getTags()); 230 231 primitive.setModified(true); 232 233 datas.addPrimitive(primitive); 203 234 } 204 205 User user = User.createOsmUser(hPrimitive1.getUid(), hPrimitive1.getUser()); 206 207 primitive.setUser(user); 208 209 primitive.setKeys(hPrimitive2.getTags()); 210 211 primitive.setModified(true); 212 213 datas.addPrimitive(primitive); 235 236 214 237 //HistoryBrowserDialogManager.getInstance().show(h); 215 238 }
Note:
See TracChangeset
for help on using the changeset viewer.