Ignore:
Timestamp:
2013-03-01T20:09:10+01:00 (12 years ago)
Author:
donvip
Message:

[josm_reverter] fix #josm8475 - Allow to revert in a new data layer + fix some warnings

Location:
applications/editors/josm/plugins/reverter/src/reverter
Files:
4 edited

Legend:

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

    r23192 r29296  
    99
    1010import javax.swing.ButtonGroup;
     11import javax.swing.JCheckBox;
    1112import javax.swing.JFormattedTextField;
    1213import javax.swing.JLabel;
     
    2122@SuppressWarnings("serial")
    2223public class ChangesetIdQuery extends ExtendedDialog {
    23     private JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getInstance());
    24     private ButtonGroup bgRevertType = new ButtonGroup();
    25     private JRadioButton rbFull = new JRadioButton(tr("Revert changeset fully"));
    26     private JRadioButton rbSelection = new JRadioButton(tr("Revert selection only"));
    27     private JRadioButton rbSelectionUndelete =
    28         new JRadioButton(tr("Revert selection and restore deleted objects"));
     24    private final JFormattedTextField tcid = new JFormattedTextField(NumberFormat.getInstance());
     25    private final ButtonGroup bgRevertType = new ButtonGroup();
     26    private final JRadioButton rbFull = new JRadioButton(tr("Revert changeset fully"));
     27    private final JRadioButton rbSelection = new JRadioButton(tr("Revert selection only"));
     28    private final JRadioButton rbSelectionUndelete = new JRadioButton(tr("Revert selection and restore deleted objects"));
     29    private final JCheckBox cbNewLayer = new JCheckBox(tr("Download as new layer"));
    2930
    3031    public int getChangesetId() {
    3132        try {
    32           return NumberFormat.getInstance().parse(tcid.getText()).intValue();
     33            return NumberFormat.getInstance().parse(tcid.getText()).intValue();
    3334        } catch (ParseException e) {
    34           return 0;
     35            return 0;
    3536        }
     37    }
     38   
     39    /**
     40     * Replies true if the user requires to download into a new layer
     41     *
     42     * @return true if the user requires to download into a new layer
     43     */
     44    public boolean isNewLayerRequired() {
     45        return cbNewLayer.isSelected();
    3646    }
    3747
     
    6070        panel.add(rbSelectionUndelete, GBC.eol().fill(GBC.HORIZONTAL));
    6171
     72        cbNewLayer.setToolTipText(tr("<html>Select to download data into a new data layer.<br>"
     73                +"Unselect to download into the currently active data layer.</html>"));
     74        panel.add(cbNewLayer, GBC.eol().fill(GBC.HORIZONTAL));
     75
    6276        setContent(panel);
    6377        setupDialog();
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r28535 r29296  
    119119     * @throws OsmTransferException
    120120     */
    121     public ChangesetReverter(int changesetId, RevertType revertType, ProgressMonitor monitor)
     121    public ChangesetReverter(int changesetId, RevertType revertType, boolean newLayer, ProgressMonitor monitor)
    122122            throws OsmTransferException {
    123123        this.changesetId = changesetId;
    124         this.layer = Main.main.getEditLayer();
    125         this.ds = layer.data;
     124        if (newLayer) {
     125            this.ds = new DataSet();
     126            this.layer = new OsmDataLayer(this.ds, tr("Reverted changeset") + tr(" [id: {0}]", changesetId), null);
     127        } else {
     128            this.layer = Main.main.getEditLayer();
     129            this.ds = layer.data;
     130        }
    126131        this.revertType = revertType;
    127132
     
    133138        } finally {
    134139            monitor.finishTask();
     140            if (newLayer) {
     141                Main.main.addLayer(layer);
     142            }
    135143        }
    136144
     
    186194                        switch (p.getType()) {
    187195                        case NODE: ds.addPrimitive(new Node(p.getUniqueId())); break;
     196                        case CLOSEDWAY:
    188197                        case WAY: ds.addPrimitive(new Way(p.getUniqueId())); break;
     198                        case MULTIPOLYGON:
    189199                        case RELATION: ds.addPrimitive(new Relation(p.getUniqueId())); break;
     200                        default: throw new AssertionError();
    190201                        }
    191202                    }
     
    205216                rdr.append(new Node(id.getUniqueId()));
    206217                break;
     218            case CLOSEDWAY:
    207219            case WAY:
    208220                rdr.append(new Way(id.getUniqueId()));
    209221                break;
     222            case MULTIPOLYGON:
    210223            case RELATION:
    211224                rdr.append(new Relation(id.getUniqueId()));
     
    229242        case NODE:
    230243            return new Conflict<Node>((Node)p,new Node((Node)p), isMyDeleted);
     244        case CLOSEDWAY:
    231245        case WAY:
    232246            return new Conflict<Way>((Way)p,new Way((Way)p), isMyDeleted);
     247        case MULTIPOLYGON:
    233248        case RELATION:
    234249            return new Conflict<Relation>((Relation)p,new Relation((Relation)p), isMyDeleted);
     
    244259            LatLon historyCoor = ((HistoryNode)history).getCoords();
    245260            return currentCoor == historyCoor || (currentCoor != null && historyCoor != null && currentCoor.equals(historyCoor));
     261        case CLOSEDWAY:
    246262        case WAY:
    247263            List<Node> currentNodes = ((Way)current).getNodes();
     
    252268            }
    253269            return true;
     270        case MULTIPOLYGON:
    254271        case RELATION:
    255272            List<org.openstreetmap.josm.data.osm.RelationMember> currentMembers =
     
    367384        return cmds;
    368385    }
     386   
    369387    public boolean hasMissingObjects() {
    370388        return !missing.isEmpty();
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetAction.java

    r27852 r29296  
    3939        if (revertType == null) return;
    4040
    41         Main.worker.submit(new RevertChangesetTask(changesetId, revertType));
     41        boolean newLayer = dlg.isNewLayerRequired();
     42        Main.worker.submit(new RevertChangesetTask(changesetId, revertType, newLayer, newLayer));
    4243    }
    4344}
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java

    r27245 r29296  
    1919    private final int changesetId;
    2020    private final RevertType revertType;
     21    private final boolean newLayer;
    2122
    2223    private ChangesetReverter rev;
    23     private boolean downloadConfirmed = false;
     24    private boolean downloadConfirmed;
    2425
    25     public RevertChangesetTask(int changesetId, RevertType revertType)
    26     {
     26    public RevertChangesetTask(int changesetId, RevertType revertType) {
     27        this(changesetId, revertType, false);
     28    }
     29   
     30    public RevertChangesetTask(int changesetId, RevertType revertType, boolean autoConfirmDownload) {
     31        this(changesetId, revertType, autoConfirmDownload, false);
     32    }
     33   
     34    public RevertChangesetTask(int changesetId, RevertType revertType, boolean autoConfirmDownload, boolean newLayer) {
    2735        super(tr("Reverting..."));
    2836        this.changesetId = changesetId;
    2937        this.revertType = revertType;
    30     }
    31     public RevertChangesetTask(int changesetId, RevertType revertType, boolean autoConfirmDownload)
    32     {
    33         this(changesetId, revertType);
    34         downloadConfirmed = autoConfirmDownload;
     38        this.downloadConfirmed = autoConfirmDownload;
     39        this.newLayer = newLayer;
    3540    }
    3641
     
    5762    protected void realRun() throws OsmTransferException {
    5863        progressMonitor.indeterminateSubTask(tr("Downloading changeset"));
    59         rev = new ChangesetReverter(changesetId, revertType,
     64        rev = new ChangesetReverter(changesetId, revertType, newLayer,
    6065                progressMonitor.createSubTaskMonitor(0, true));
    6166        if (progressMonitor.isCanceled()) return;
Note: See TracChangeset for help on using the changeset viewer.