Changeset 32552 in osm for applications/editors/josm
- Timestamp:
- 2016-07-04T09:32:09+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/undelete
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/undelete/.project
r32286 r32552 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/undelete/src/org/openstreetmap/josm/plugins/undelete/Undelete.java
r29474 r32552 1 // License: GPL. See LICENSE file for details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.undelete; 3 3 -
applications/editors/josm/plugins/undelete/src/org/openstreetmap/josm/plugins/undelete/UndeleteAction.java
r32512 r32552 1 // License: GPL. See LICENSE file for details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.undelete; 3 3 … … 40 40 public class UndeleteAction extends JosmAction { 41 41 42 private final class Worker implements Runnable { 43 private final OsmPrimitive parent; 44 45 private final OsmDataLayer layer; 46 47 private final List<PrimitiveId> ids; 48 49 private Worker(OsmPrimitive parent, OsmDataLayer layer, List<PrimitiveId> ids) { 50 this.parent = parent; 51 this.layer = layer; 52 this.ids = ids; 53 } 54 55 @Override 56 public void run() { 57 List<Node> nodes = new ArrayList<>(); 58 for (PrimitiveId pid : ids) { 59 OsmPrimitive primitive = layer.data.getPrimitiveById(pid); 60 if (primitive == null) { 61 try { 62 final Long id = pid.getUniqueId(); 63 final OsmPrimitiveType type = pid.getType(); 64 65 History h = HistoryDataSet.getInstance().getHistory(id, type); 66 67 HistoryOsmPrimitive hPrimitive1 = h.getLatest(); 68 HistoryOsmPrimitive hPrimitive2; 69 70 boolean visible = hPrimitive1.isVisible(); 71 72 if (visible) { 73 // If the object is not deleted we get the real object 74 DownloadPrimitivesTask download = new DownloadPrimitivesTask(layer, Collections.singletonList(pid), true); 75 download.run(); 76 77 primitive = layer.data.getPrimitiveById(id, type); 78 } else { 79 if (type.equals(OsmPrimitiveType.NODE)) { 80 // We get version and user from the latest version, 81 // coordinates and tags from n-1 version 82 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 83 84 Node node = new Node(id, (int) hPrimitive1.getVersion()); 85 86 HistoryNode hNode = (HistoryNode) hPrimitive2; 87 if (hNode != null) { 88 node.setCoor(hNode.getCoords()); 89 } 90 91 primitive = node; 92 } else if (type.equals(OsmPrimitiveType.WAY)) { 93 // We get version and user from the latest version, 94 // nodes and tags from n-1 version 95 hPrimitive1 = h.getLatest(); 96 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 97 98 Way way = new Way(id, (int) hPrimitive1.getVersion()); 99 100 HistoryWay hWay = (HistoryWay) hPrimitive2; 101 // System.out.println(tr("Primitive {0} version {1}: {2} nodes", 102 // hPrimitive2.getId(), hPrimitive2.getVersion(), 103 // hWay.getNumNodes())); 104 List<PrimitiveId> nodeIds = new ArrayList<>(); 105 if (hWay != null) { 106 for (Long i : hWay.getNodes()) { 107 nodeIds.add(new SimplePrimitiveId(i, OsmPrimitiveType.NODE)); 108 } 109 } 110 undelete(false, nodeIds, way); 111 112 primitive = way; 113 } else { 114 primitive = new Relation(); 115 hPrimitive1 = h.getLatest(); 116 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 117 118 Relation rel = new Relation(id, (int) hPrimitive1.getVersion()); 119 120 HistoryRelation hRel = (HistoryRelation) hPrimitive2; 121 122 if (hRel != null) { 123 List<RelationMember> members = new ArrayList<>(hRel.getNumMembers()); 124 for (RelationMemberData m : hRel.getMembers()) { 125 OsmPrimitive p = layer.data.getPrimitiveById(m.getMemberId(), m.getMemberType()); 126 if (p == null) { 127 switch (m.getMemberType()) { 128 case NODE: 129 p = new Node(m.getMemberId()); 130 break; 131 case CLOSEDWAY: 132 case WAY: 133 p = new Way(m.getMemberId()); 134 break; 135 case MULTIPOLYGON: 136 case RELATION: 137 p = new Relation(m.getMemberId()); 138 break; 139 } 140 layer.data.addPrimitive(p); 141 } 142 members.add(new RelationMember(m.getRole(), p)); 143 } 144 145 rel.setMembers(members); 146 } 147 148 primitive = rel; 149 } 150 151 if (hPrimitive2 != null) { 152 primitive.setChangesetId((int) hPrimitive1.getChangesetId()); 153 primitive.setTimestamp(hPrimitive1.getTimestamp()); 154 primitive.setUser(hPrimitive1.getUser()); 155 primitive.setVisible(hPrimitive1.isVisible()); 156 primitive.setKeys(hPrimitive2.getTags()); 157 primitive.setModified(true); 158 159 layer.data.addPrimitive(primitive); 160 } else { 161 final String msg = OsmPrimitiveType.NODE.equals(type) 162 ? tr("Unable to undelete node {0}. Object has likely been redacted", id) 163 : OsmPrimitiveType.WAY.equals(type) 164 ? tr("Unable to undelete way {0}. Object has likely been redacted", id) 165 : OsmPrimitiveType.RELATION.equals(type) 166 ? tr("Unable to undelete relation {0}. Object has likely been redacted", id) 167 : null; 168 GuiHelper.runInEDT(new Runnable() { 169 @Override 170 public void run() { 171 new Notification(msg).setIcon(JOptionPane.WARNING_MESSAGE).show(); 172 } 173 }); 174 Main.warn(msg); 175 } 176 } 177 } catch (Exception t) { 178 Main.error(t); 179 } 180 } 181 if (parent != null && primitive instanceof Node) { 182 nodes.add((Node) primitive); 183 } 184 } 185 if (parent instanceof Way && !nodes.isEmpty()) { 186 ((Way) parent).setNodes(nodes); 187 Main.map.repaint(); 188 } 189 GuiHelper.runInEDT(new Runnable() { 190 @Override 191 public void run() { 192 AutoScaleAction.zoomTo(layer.data.allNonDeletedPrimitives()); 193 } 194 }); 195 } 196 } 197 42 198 public UndeleteAction() { 43 super(tr("Undelete object..."), "undelete", tr("Undelete object by id"), 199 super(tr("Undelete object..."), "undelete", tr("Undelete object by id"), 44 200 Shortcut.registerShortcut("tools:undelete", tr("File: {0}", tr("Undelete object...")), KeyEvent.VK_U, Shortcut.ALT_SHIFT), true); 45 201 } … … 54 210 undelete(dialog.isNewLayerSelected(), dialog.getOsmIds(), null); 55 211 } 56 212 57 213 /** 58 214 * // TODO: undelete relation members if necessary 59 215 */ 60 216 public void undelete(boolean newLayer, final List<PrimitiveId> ids, final OsmPrimitive parent) { 61 62 Main.info("Undeleting "+ids+(parent ==null?"":" with parent "+parent));63 217 218 Main.info("Undeleting "+ids+(parent == null ? "" : " with parent "+parent)); 219 64 220 OsmDataLayer tmpLayer = Main.getLayerManager().getEditLayer(); 65 221 if ((tmpLayer == null) || newLayer) { … … 76 232 77 233 Main.worker.execute(task); 78 79 Runnable r = new Runnable() { 80 @Override 81 public void run() { 82 List<Node> nodes = new ArrayList<>(); 83 for (PrimitiveId pid : ids) { 84 OsmPrimitive primitive = layer.data.getPrimitiveById(pid); 85 if (primitive == null) { 86 try { 87 final Long id = pid.getUniqueId(); 88 final OsmPrimitiveType type = pid.getType(); 89 90 History h = HistoryDataSet.getInstance().getHistory(id, type); 91 92 HistoryOsmPrimitive hPrimitive1 = h.getLatest(); 93 HistoryOsmPrimitive hPrimitive2; 94 95 boolean visible = hPrimitive1.isVisible(); 96 97 if (visible) { 98 // If the object is not deleted we get the real object 99 DownloadPrimitivesTask download = new DownloadPrimitivesTask(layer, Collections.singletonList(pid), true); 100 download.run(); 101 102 primitive = layer.data.getPrimitiveById(id, type); 103 } else { 104 if (type.equals(OsmPrimitiveType.NODE)) { 105 // We get version and user from the latest version, 106 // coordinates and tags from n-1 version 107 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 108 109 Node node = new Node(id, (int) hPrimitive1.getVersion()); 110 111 HistoryNode hNode = (HistoryNode) hPrimitive2; 112 if (hNode != null) { 113 node.setCoor(hNode.getCoords()); 114 } 115 116 primitive = node; 117 } else if (type.equals(OsmPrimitiveType.WAY)) { 118 // We get version and user from the latest version, 119 // nodes and tags from n-1 version 120 hPrimitive1 = h.getLatest(); 121 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 122 123 Way way = new Way(id, (int) hPrimitive1.getVersion()); 124 125 HistoryWay hWay = (HistoryWay) hPrimitive2; 126 // System.out.println(tr("Primitive {0} version {1}: {2} nodes", 127 // hPrimitive2.getId(), hPrimitive2.getVersion(), 128 // hWay.getNumNodes())); 129 List<PrimitiveId> nodeIds = new ArrayList<>(); 130 if (hWay != null) { 131 for (Long i : hWay.getNodes()) { 132 nodeIds.add(new SimplePrimitiveId(i, OsmPrimitiveType.NODE)); 133 } 134 } 135 undelete(false, nodeIds, way); 136 137 primitive = way; 138 } else { 139 primitive = new Relation(); 140 hPrimitive1 = h.getLatest(); 141 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 142 143 Relation rel = new Relation(id,(int) hPrimitive1.getVersion()); 144 145 HistoryRelation hRel = (HistoryRelation) hPrimitive2; 146 147 if (hRel != null) { 148 List<RelationMember> members = new ArrayList<>(hRel.getNumMembers()); 149 for (RelationMemberData m : hRel.getMembers()) { 150 OsmPrimitive p = layer.data.getPrimitiveById(m.getMemberId(), m.getMemberType()); 151 if (p == null) { 152 switch (m.getMemberType()) { 153 case NODE: 154 p = new Node(m.getMemberId()); 155 break; 156 case CLOSEDWAY: 157 case WAY: 158 p = new Way(m.getMemberId()); 159 break; 160 case MULTIPOLYGON: 161 case RELATION: 162 p = new Relation(m.getMemberId()); 163 break; 164 } 165 layer.data.addPrimitive(p); 166 } 167 members.add(new RelationMember(m.getRole(), p)); 168 } 169 170 rel.setMembers(members); 171 } 172 173 primitive = rel; 174 } 175 176 if (hPrimitive2 != null) { 177 primitive.setChangesetId((int) hPrimitive1.getChangesetId()); 178 primitive.setTimestamp(hPrimitive1.getTimestamp()); 179 primitive.setUser(hPrimitive1.getUser()); 180 primitive.setVisible(hPrimitive1.isVisible()); 181 primitive.setKeys(hPrimitive2.getTags()); 182 primitive.setModified(true); 183 184 layer.data.addPrimitive(primitive); 185 } else { 186 final String msg = OsmPrimitiveType.NODE.equals(type) 187 ? tr("Unable to undelete node {0}. Object has likely been redacted", id) 188 : OsmPrimitiveType.WAY.equals(type) 189 ? tr("Unable to undelete way {0}. Object has likely been redacted", id) 190 : OsmPrimitiveType.RELATION.equals(type) 191 ? tr("Unable to undelete relation {0}. Object has likely been redacted", id) 192 : null; 193 GuiHelper.runInEDT(new Runnable() { 194 @Override 195 public void run() { 196 new Notification(msg).setIcon(JOptionPane.WARNING_MESSAGE).show(); 197 } 198 }); 199 Main.warn(msg); 200 } 201 } 202 } catch (Exception t) { 203 Main.error(t); 204 } 205 } 206 if (parent != null && primitive instanceof Node) { 207 nodes.add((Node) primitive); 208 } 209 } 210 if (parent instanceof Way && !nodes.isEmpty()) { 211 ((Way) parent).setNodes(nodes); 212 Main.map.repaint(); 213 } 214 GuiHelper.runInEDT(new Runnable() { 215 @Override 216 public void run() { 217 AutoScaleAction.zoomTo(layer.data.allNonDeletedPrimitives()); 218 } 219 }); 220 } 221 }; 222 Main.worker.submit(r); 234 Main.worker.submit(new Worker(parent, layer, ids)); 223 235 } 224 236 } -
applications/editors/josm/plugins/undelete/src/org/openstreetmap/josm/plugins/undelete/UndeleteDialog.java
r29474 r32552 1 // License: GPL. See LICENSE file for details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.undelete; 3 3 … … 24 24 private final JCheckBox layer = new JCheckBox(tr("Separate Layer")); 25 25 private final OsmIdTextField tfId = new OsmIdTextField(); 26 26 27 27 public UndeleteDialog(Component parent) { 28 28 super(parent, tr("Undelete Object"), new String[] {tr("Undelete object"), tr("Cancel")}); 29 29 30 30 JPanel all = new JPanel(new GridBagLayout()); 31 31 GridBagConstraints gc = new GridBagConstraints(); … … 35 35 gc.weightx = 0; 36 36 all.add(new JLabel(tr("Object ID:")), gc); 37 37 38 38 tfId.setText(Main.pref.get("undelete.osmid")); 39 39 tfId.setToolTipText(tr("Enter the type and ID of the objects that should be undeleted, e.g., ''n1 w2''")); … … 52 52 all.add(layer, gc); 53 53 setContent(all, false); 54 setButtonIcons(new String[] { "undelete.png", "cancel.png"});55 setToolTipTexts(new String[] { tr("Start undeleting"), tr("Close dialog and cancel")});54 setButtonIcons(new String[] {"undelete.png", "cancel.png"}); 55 setToolTipTexts(new String[] {tr("Start undeleting"), tr("Close dialog and cancel")}); 56 56 setDefaultButton(1); 57 57 } 58 58 59 59 public final boolean isNewLayerSelected() { 60 60 return layer.isSelected(); 61 61 } 62 62 63 63 public final String getOsmIdsString() { 64 64 return tfId.getText(); 65 65 } 66 66 67 67 public final List<PrimitiveId> getOsmIds() { 68 68 return tfId.getIds();
Note:
See TracChangeset
for help on using the changeset viewer.