Changeset 12719 in josm


Ignore:
Timestamp:
2017-09-04T02:10:29+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #15232 - Allow user to request feedback when uploading by adding the review_requested=yes changeset tag.
Inspired by:

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java

    r12630 r12719  
    1010import java.awt.event.FocusAdapter;
    1111import java.awt.event.FocusEvent;
     12import java.awt.event.ItemEvent;
    1213import java.awt.event.KeyAdapter;
    1314import java.awt.event.KeyEvent;
     
    2021import javax.swing.Action;
    2122import javax.swing.BorderFactory;
     23import javax.swing.JCheckBox;
    2224import javax.swing.JEditorPane;
    2325import javax.swing.JPanel;
     
    6264    /** the panel with a summary of the upload parameters */
    6365    private final UploadParameterSummaryPanel pnlUploadParameterSummary = new UploadParameterSummaryPanel();
     66    /** the checkbox to request feedback from other users */
     67    private final JCheckBox cbRequestReview = new JCheckBox(tr("I would like someone to review my edits."));
    6468    /** the changeset comment model */
    6569    private final transient ChangesetCommentModel changesetCommentModel;
    6670    private final transient ChangesetCommentModel changesetSourceModel;
     71    private final transient ChangesetReviewModel changesetReviewModel;
    6772
    6873    protected JPanel buildUploadCommentPanel() {
     
    118123        add(buildUploadCommentPanel(), BorderLayout.NORTH);
    119124        add(pnlUploadParameterSummary, BorderLayout.CENTER);
     125        add(cbRequestReview, BorderLayout.SOUTH);
     126        cbRequestReview.addItemListener(e -> changesetReviewModel.setReviewRequested(e.getStateChange() == ItemEvent.SELECTED));
    120127    }
    121128
     
    125132     * @param changesetCommentModel the model for the changeset comment. Must not be null
    126133     * @param changesetSourceModel the model for the changeset source. Must not be null.
     134     * @param changesetReviewModel the model for the changeset review. Must not be null.
    127135     * @throws IllegalArgumentException if {@code changesetCommentModel} is null
    128      */
    129     public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel) {
     136     * @since 12719 (signature)
     137     */
     138    public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel,
     139            ChangesetReviewModel changesetReviewModel) {
    130140        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
    131141        CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel");
     142        CheckParameterUtil.ensureParameterNotNull(changesetReviewModel, "changesetReviewModel");
    132143        this.changesetCommentModel = changesetCommentModel;
    133144        this.changesetSourceModel = changesetSourceModel;
     145        this.changesetReviewModel = changesetReviewModel;
    134146        changesetCommentModel.addChangeListener(new ChangesetCommentChangeListener(hcbUploadComment));
    135147        changesetSourceModel.addChangeListener(new ChangesetCommentChangeListener(hcbUploadSource));
     148        changesetReviewModel.addChangeListener(new ChangesetReviewChangeListener());
    136149        build();
    137150    }
     
    250263        }
    251264    }
     265
     266    /**
     267     * Observes the changeset review model and keeps the review checkbox
     268     * in sync with the current changeset review request
     269     */
     270    class ChangesetReviewChangeListener implements ChangeListener {
     271        @Override
     272        public void stateChanged(ChangeEvent e) {
     273            if (!(e.getSource() instanceof ChangesetReviewModel)) return;
     274            boolean newState = ((ChangesetReviewModel) e.getSource()).isReviewRequested();
     275            if (cbRequestReview.isSelected() != newState) {
     276                cbRequestReview.setSelected(newState);
     277            }
     278        }
     279    }
    252280}
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r12636 r12719  
    2929    private final transient ChangesetCommentModel changesetCommentModel;
    3030    private final transient ChangesetCommentModel changesetSourceModel;
     31    private final transient ChangesetReviewModel changesetReviewModel;
    3132
    3233    /**
     
    3536     * @param changesetCommentModel the changeset comment model. Must not be null.
    3637     * @param changesetSourceModel the changeset source model. Must not be null.
     38     * @param changesetReviewModel the model for the changeset review. Must not be null.
    3739     * @throws IllegalArgumentException if {@code changesetCommentModel} is null
     40     * @since 12719 (signature)
    3841     */
    39     public TagSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel) {
     42    public TagSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel,
     43            ChangesetReviewModel changesetReviewModel) {
    4044        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
    4145        CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel");
     46        CheckParameterUtil.ensureParameterNotNull(changesetReviewModel, "changesetReviewModel");
    4247        this.changesetCommentModel = changesetCommentModel;
    4348        this.changesetSourceModel = changesetSourceModel;
    44         this.changesetCommentModel.addChangeListener(new ChangesetCommentChangeListener("comment"));
    45         this.changesetSourceModel.addChangeListener(new ChangesetCommentChangeListener("source"));
     49        this.changesetReviewModel = changesetReviewModel;
     50        changesetCommentModel.addChangeListener(new ChangesetCommentChangeListener("comment"));
     51        changesetSourceModel.addChangeListener(new ChangesetCommentChangeListener("source"));
     52        changesetReviewModel.addChangeListener(new ChangesetReviewChangeListener());
    4653        build();
    4754        pnlTagEditor.getModel().addTableModelListener(this);
     
    109116        changesetCommentModel.setComment(getTagEditorValue("comment"));
    110117        changesetSourceModel.setComment(getTagEditorValue("source"));
     118        changesetReviewModel.setReviewRequested("yes".equals(getTagEditorValue("review_requested")));
    111119    }
    112120
     
    117125        setProperty("comment", changesetCommentModel.getComment());
    118126        setProperty("source", changesetSourceModel.getComment());
     127        setProperty("review_requested", changesetReviewModel.isReviewRequested() ? "yes" : null);
    119128    }
    120129
     
    142151        }
    143152    }
     153
     154    /**
     155     * Observes the changeset review model and keeps the tag editor in sync
     156     * with the current changeset review request
     157     */
     158    class ChangesetReviewChangeListener implements ChangeListener {
     159
     160        private final String key = "review_requested";
     161
     162        @Override
     163        public void stateChanged(ChangeEvent e) {
     164            if (e.getSource() instanceof ChangesetReviewModel) {
     165                boolean newState = ((ChangesetReviewModel) e.getSource()).isReviewRequested();
     166                boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(key)).orElse(""));
     167                if (oldState != newState) {
     168                    setProperty(key, newState ? "yes" : null);
     169                }
     170            }
     171        }
     172    }
    144173}
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r12687 r12719  
    101101    private final transient ChangesetCommentModel changesetCommentModel = new ChangesetCommentModel();
    102102    private final transient ChangesetCommentModel changesetSourceModel = new ChangesetCommentModel();
     103    private final transient ChangesetReviewModel changesetReviewModel = new ChangesetReviewModel();
    103104
    104105    private transient DataSet dataSet;
     
    145146        tpConfigPanels = new CompactTabbedPane();
    146147
    147         pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel);
     148        pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel, changesetReviewModel);
    148149        tpConfigPanels.add(pnlBasicUploadSettings);
    149150        tpConfigPanels.setTitleAt(0, tr("Settings"));
    150151        tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use"));
    151152
    152         pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel);
     153        pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel, changesetReviewModel);
    153154        tpConfigPanels.add(pnlTagSettings);
    154155        tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
  • trunk/test/unit/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanelTest.java

    r10962 r12719  
    2727    @Test
    2828    public void testBasicUploadSettingsPanel() {
    29         assertNotNull(new BasicUploadSettingsPanel(new ChangesetCommentModel(), new ChangesetCommentModel()));
     29        assertNotNull(new BasicUploadSettingsPanel(new ChangesetCommentModel(), new ChangesetCommentModel(), new ChangesetReviewModel()));
    3030    }
    3131}
  • trunk/test/unit/org/openstreetmap/josm/gui/io/TagSettingsPanelTest.java

    r10962 r12719  
    2727    @Test
    2828    public void testTagSettingsPanel() {
    29         assertNotNull(new TagSettingsPanel(new ChangesetCommentModel(), new ChangesetCommentModel()));
     29        assertNotNull(new TagSettingsPanel(new ChangesetCommentModel(), new ChangesetCommentModel(), new ChangesetReviewModel()));
    3030    }
    3131}
Note: See TracChangeset for help on using the changeset viewer.