Changeset 21700 in osm for applications/editors/josm/plugins/reverter
- Timestamp:
- 2010-06-14T15:21:03+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/reverter/src/reverter
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdQuery.java
r21634 r21700 7 7 import java.text.ParseException; 8 8 9 import javax.swing.ButtonGroup; 9 10 import javax.swing.JFormattedTextField; 10 11 import javax.swing.JLabel; 11 12 import javax.swing.JPanel; 13 import javax.swing.JRadioButton; 12 14 13 15 import org.openstreetmap.josm.Main; 14 16 import org.openstreetmap.josm.gui.ExtendedDialog; 15 17 import org.openstreetmap.josm.tools.GBC; 18 import reverter.ChangesetReverter.RevertType; 16 19 17 20 @SuppressWarnings("serial") 18 21 public class ChangesetIdQuery extends ExtendedDialog { 19 22 private JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getInstance()); 23 private ButtonGroup bgRevertType = new ButtonGroup(); 24 private JRadioButton rbFull = new JRadioButton(tr("Revert changeset fully")); 25 private JRadioButton rbSelection = new JRadioButton(tr("Revert selection only")); 26 private JRadioButton rbSelectionUndelete = 27 new JRadioButton(tr("Revert selection and restore deleted objects")); 20 28 21 public int ChangesetId() {29 public int getChangesetId() { 22 30 try { 23 31 return NumberFormat.getInstance().parse(tcid.getText()).intValue(); … … 26 34 } 27 35 } 36 37 public RevertType getRevertType() { 38 if (rbFull.isSelected()) return RevertType.FULL; 39 if (rbSelection.isSelected()) return RevertType.SELECTION; 40 if (rbSelectionUndelete.isSelected()) return RevertType.SELECTION_WITH_UNDELETE; 41 return null; 42 } 43 28 44 public ChangesetIdQuery() { 29 super(Main.parent, tr(" Objects history"), new String[] {tr("Revert"),tr("Cancel")}, true);45 super(Main.parent, tr("Revert changeset"), new String[] {tr("Revert"),tr("Cancel")}, true); 30 46 contentConstraints = GBC.eol().fill().insets(10,10,10,5); 31 47 setButtonIcons(new String[] {"ok.png", "cancel.png" }); … … 33 49 panel.add(new JLabel(tr("Changeset id:"))); 34 50 panel.add(tcid, GBC.eol().fill(GBC.HORIZONTAL)); 51 52 bgRevertType.add(rbFull); 53 bgRevertType.add(rbSelection); 54 bgRevertType.add(rbSelectionUndelete); 55 56 rbFull.setSelected(true); 57 panel.add(rbFull, GBC.eol().insets(0,10,0,0).fill(GBC.HORIZONTAL)); 58 panel.add(rbSelection, GBC.eol().fill(GBC.HORIZONTAL)); 59 panel.add(rbSelectionUndelete, GBC.eol().fill(GBC.HORIZONTAL)); 60 35 61 setContent(panel); 36 62 setupDialog(); -
applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
r21691 r21700 52 52 public final int changesetId; 53 53 public final Changeset changeset; 54 public final RevertType revertType; 54 55 55 56 private final OsmDataLayer layer; // data layer associated with reverter … … 107 108 108 109 /** 110 * Checks if {@see ChangesetDataSetEntry} conforms to current RevertType 111 * @param entry entry to be checked 112 * @return <code>true</code> if {@see ChangesetDataSetEntry} conforms to current RevertType 113 */ 114 private boolean CheckOsmChangeEntry(ChangesetDataSetEntry entry) { 115 if (revertType == RevertType.FULL) return true; 116 if (revertType == RevertType.SELECTION_WITH_UNDELETE && 117 entry.getModificationType() == ChangesetModificationType.DELETED) { 118 return true; 119 } 120 OsmPrimitive p = ds.getPrimitiveById(entry.getPrimitive().getPrimitiveId()); 121 if (p == null) return false; 122 return p.isSelected(); 123 } 124 125 /** 109 126 * creates a reverter for specific changeset and fetches initial data 110 127 * @param changesetId … … 112 129 * @throws OsmTransferException 113 130 */ 114 public ChangesetReverter(int changesetId, ProgressMonitor monitor) throws OsmTransferException { 131 public ChangesetReverter(int changesetId, RevertType revertType, ProgressMonitor monitor) 132 throws OsmTransferException { 115 133 this.changesetId = changesetId; 116 134 this.layer = Main.main.getEditLayer(); 117 135 this.ds = layer.data; 136 this.revertType = revertType; 118 137 119 138 OsmServerChangesetReader csr = new OsmServerChangesetReader(); … … 129 148 for (Iterator<ChangesetDataSetEntry> it = cds.iterator();it.hasNext();) { 130 149 ChangesetDataSetEntry entry = it.next(); 150 if (!CheckOsmChangeEntry(entry)) continue; 131 151 if (entry.getModificationType() == ChangesetModificationType.CREATED) { 132 152 created.add(entry.getPrimitive()); … … 290 310 for (Iterator<ChangesetDataSetEntry> it = cds.iterator();it.hasNext();) { 291 311 ChangesetDataSetEntry entry = it.next(); 312 if (!CheckOsmChangeEntry(entry)) continue; 292 313 HistoryOsmPrimitive hp = entry.getPrimitive(); 293 314 OsmPrimitive dp = ds.getPrimitiveById(hp.getPrimitiveId()); … … 323 344 if (nds.getPrimitiveById(referrer) != null) 324 345 continue; /* object is going to be modified so it cannot refer to 325 * objects created in same changeset346 * objects created in changeset to be reverted 326 347 */ 327 348 if (!conflicted.contains(p)) { -
applications/editors/josm/plugins/reverter/src/reverter/PrimitiveIdVersion.java
r21691 r21700 2 2 3 3 import org.openstreetmap.josm.data.osm.PrimitiveId; 4 import org.openstreetmap.josm.data.osm.SimplePrimitiveId;5 4 import org.openstreetmap.josm.tools.CheckParameterUtil; 6 5 -
applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java
r21691 r21700 14 14 import org.openstreetmap.josm.command.SequenceCommand; 15 15 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 16 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;17 16 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 18 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 19 18 import org.openstreetmap.josm.io.OsmTransferException; 20 19 import org.openstreetmap.josm.tools.Shortcut; 20 import reverter.ChangesetReverter.RevertType; 21 21 22 22 @SuppressWarnings("serial") … … 40 40 if (getCurrentDataSet() == null) 41 41 return; 42 ChangesetIdQuery dlg = new ChangesetIdQuery();42 final ChangesetIdQuery dlg = new ChangesetIdQuery(); 43 43 dlg.setVisible(true); 44 44 if (dlg.getValue() != 1) return; 45 final int changesetId = dlg.ChangesetId(); 45 final int changesetId = dlg.getChangesetId(); 46 final RevertType revertType = dlg.getRevertType(); 46 47 if (changesetId == 0) return; 48 if (revertType == null) return; 49 47 50 Main.worker.submit(new PleaseWaitRunnable(tr("Reverting...")) { 48 51 private ChangesetReverter rev; 49 52 private boolean downloadConfirmed = false; 50 53 51 private boolean check Missing() throws OsmTransferException {54 private boolean checkAndDownloadMissing() throws OsmTransferException { 52 55 if (!rev.hasMissingObjects()) return true; 53 56 if (!downloadConfirmed) { … … 65 68 monitor.close(); 66 69 } 67 return true;70 return !monitor.isCancelled(); 68 71 } 69 72 70 73 @Override 71 74 protected void realRun() throws OsmTransferException { 72 progressMonitor.indeterminateSubTask("Downloading changeset"); 73 rev = new ChangesetReverter(changesetId, NullProgressMonitor.INSTANCE); 75 progressMonitor.indeterminateSubTask(tr("Downloading changeset")); 76 rev = new ChangesetReverter(changesetId, revertType, 77 progressMonitor.createSubTaskMonitor(0, true)); 74 78 if (progressMonitor.isCancelled()) return; 75 rev.checkMissingDeleted(); 76 // Don't ask user to download primitives going to be undeleted 77 rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor(0, false)); 78 if (progressMonitor.isCancelled()) return; 79 80 // Check missing objects 79 81 rev.checkMissingCreated(); 80 82 rev.checkMissingUpdated(); 81 if (!checkMissing()) return; 83 if (rev.hasMissingObjects()) { 84 // If missing created or updated objects, ask user 85 rev.checkMissingDeleted(); 86 if (!checkAndDownloadMissing()) return; 87 } else { 88 // Don't ask user to download primitives going to be undeleted 89 rev.checkMissingDeleted(); 90 rev.downloadMissingPrimitives(progressMonitor.createSubTaskMonitor(0, false)); 91 } 92 93 if (progressMonitor.isCancelled()) return; 82 94 rev.downloadObjectsHistory(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 83 95 if (progressMonitor.isCancelled()) return; 84 if (!check Missing()) return;96 if (!checkAndDownloadMissing()) return; 85 97 List<Command> cmds = rev.getCommands(); 86 Command cmd = new SequenceCommand(tr("Revert changeset #{0}",changesetId),cmds); 98 Command cmd = new SequenceCommand(tr(revertType == RevertType.FULL ? "Revert changeset #{0}" : 99 "Partially revert changeset #{0}",changesetId),cmds); 87 100 Main.main.undoRedo.add(cmd); 88 101 } -
applications/editors/josm/plugins/reverter/src/reverter/ReverterUploadHook.java
r21695 r21700 6 6 import java.util.Collections; 7 7 import java.util.Comparator; 8 import java.util.HashMap;9 import java.util.HashSet;10 import java.util.LinkedList;11 import java.util.List;12 import java.util.Map.Entry;13 8 14 9 import javax.swing.JOptionPane;
Note:
See TracChangeset
for help on using the changeset viewer.