Changeset 21700 in osm for applications/editors/josm


Ignore:
Timestamp:
2010-06-14T15:21:03+02:00 (15 years ago)
Author:
upliner
Message:

reverter: add support for partial reverts

Location:
applications/editors/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetIdQuery.java

    r21634 r21700  
    77import java.text.ParseException;
    88
     9import javax.swing.ButtonGroup;
    910import javax.swing.JFormattedTextField;
    1011import javax.swing.JLabel;
    1112import javax.swing.JPanel;
     13import javax.swing.JRadioButton;
    1214
    1315import org.openstreetmap.josm.Main;
    1416import org.openstreetmap.josm.gui.ExtendedDialog;
    1517import org.openstreetmap.josm.tools.GBC;
     18import reverter.ChangesetReverter.RevertType;
    1619
    1720@SuppressWarnings("serial")
    1821public class ChangesetIdQuery extends ExtendedDialog {
    1922    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"));
    2028
    21     public int ChangesetId() {
     29    public int getChangesetId() {
    2230        try {
    2331          return NumberFormat.getInstance().parse(tcid.getText()).intValue();
     
    2634        }
    2735    }
     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
    2844    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);
    3046        contentConstraints = GBC.eol().fill().insets(10,10,10,5);
    3147        setButtonIcons(new String[] {"ok.png", "cancel.png" });
     
    3349        panel.add(new JLabel(tr("Changeset id:")));
    3450        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       
    3561        setContent(panel);
    3662        setupDialog();       
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r21691 r21700  
    5252    public final int changesetId;
    5353    public final Changeset changeset;
     54    public final RevertType revertType;
    5455
    5556    private final OsmDataLayer layer; // data layer associated with reverter
     
    107108   
    108109    /**
     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    /**
    109126     * creates a reverter for specific changeset and fetches initial data
    110127     * @param changesetId
     
    112129     * @throws OsmTransferException
    113130     */
    114     public ChangesetReverter(int changesetId, ProgressMonitor monitor) throws OsmTransferException {
     131    public ChangesetReverter(int changesetId, RevertType revertType, ProgressMonitor monitor)
     132            throws OsmTransferException {
    115133        this.changesetId = changesetId;
    116134        this.layer = Main.main.getEditLayer();
    117135        this.ds = layer.data;
     136        this.revertType = revertType;
    118137
    119138        OsmServerChangesetReader csr = new OsmServerChangesetReader();
     
    129148        for (Iterator<ChangesetDataSetEntry> it = cds.iterator();it.hasNext();) {
    130149            ChangesetDataSetEntry entry = it.next();
     150            if (!CheckOsmChangeEntry(entry)) continue;
    131151            if (entry.getModificationType() == ChangesetModificationType.CREATED) {
    132152                created.add(entry.getPrimitive());
     
    290310        for (Iterator<ChangesetDataSetEntry> it = cds.iterator();it.hasNext();) {
    291311            ChangesetDataSetEntry entry = it.next();
     312            if (!CheckOsmChangeEntry(entry)) continue;
    292313            HistoryOsmPrimitive hp = entry.getPrimitive();
    293314            OsmPrimitive dp = ds.getPrimitiveById(hp.getPrimitiveId());
     
    323344                if (nds.getPrimitiveById(referrer) != null)
    324345                    continue; /* object is going to be modified so it cannot refer to
    325                                * objects created in same changeset
     346                               * objects created in changeset to be reverted
    326347                               */
    327348                if (!conflicted.contains(p)) {
  • applications/editors/josm/plugins/reverter/src/reverter/PrimitiveIdVersion.java

    r21691 r21700  
    22
    33import org.openstreetmap.josm.data.osm.PrimitiveId;
    4 import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
    54import org.openstreetmap.josm.tools.CheckParameterUtil;
    65
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java

    r21691 r21700  
    1414import org.openstreetmap.josm.command.SequenceCommand;
    1515import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    16 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1716import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    1817import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1918import org.openstreetmap.josm.io.OsmTransferException;
    2019import org.openstreetmap.josm.tools.Shortcut;
     20import reverter.ChangesetReverter.RevertType;
    2121
    2222@SuppressWarnings("serial")
     
    4040        if (getCurrentDataSet() == null)
    4141            return;
    42         ChangesetIdQuery dlg = new ChangesetIdQuery();
     42        final ChangesetIdQuery dlg = new ChangesetIdQuery();
    4343        dlg.setVisible(true);
    4444        if (dlg.getValue() != 1) return;
    45         final int changesetId = dlg.ChangesetId();
     45        final int changesetId = dlg.getChangesetId();
     46        final RevertType revertType = dlg.getRevertType();
    4647        if (changesetId == 0) return;
     48        if (revertType == null) return;
     49       
    4750        Main.worker.submit(new PleaseWaitRunnable(tr("Reverting...")) {
    4851            private ChangesetReverter rev;
    4952            private boolean downloadConfirmed = false;
    5053           
    51             private boolean checkMissing() throws OsmTransferException {
     54            private boolean checkAndDownloadMissing() throws OsmTransferException {
    5255                if (!rev.hasMissingObjects()) return true;
    5356                if (!downloadConfirmed) {
     
    6568                    monitor.close();
    6669                }
    67                 return true;
     70                return !monitor.isCancelled();
    6871            }
    6972           
    7073            @Override
    7174            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));
    7478                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
    7981                rev.checkMissingCreated();
    8082                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;
    8294                rev.downloadObjectsHistory(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
    8395                if (progressMonitor.isCancelled()) return;
    84                 if (!checkMissing()) return;
     96                if (!checkAndDownloadMissing()) return;
    8597                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);
    87100                Main.main.undoRedo.add(cmd);
    88101            }
  • applications/editors/josm/plugins/reverter/src/reverter/ReverterUploadHook.java

    r21695 r21700  
    66import java.util.Collections;
    77import 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;
    138
    149import javax.swing.JOptionPane;
Note: See TracChangeset for help on using the changeset viewer.