Ignore:
Timestamp:
2013-11-22T22:19:33+01:00 (10 years ago)
Author:
simon04
Message:

see #6381 - Ask for source tag in changeset/upload

File:
1 edited

Legend:

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

    r6309 r6401  
    2222
    2323    /** checkbox for selecting whether an atomic upload is to be used  */
    24     private TagEditorPanel pnlTagEditor;
     24    private final TagEditorPanel pnlTagEditor = new TagEditorPanel(null);
    2525    /** the model for the changeset comment */
    26     private ChangesetCommentModel changesetCommentModel;
     26    private final ChangesetCommentModel changesetCommentModel;
     27    private final ChangesetCommentModel changesetSourceModel;
    2728    /** tags that applied to uploaded changesets by default*/
    28     private Map<String, String> defaultTags = new HashMap<String, String>();
     29    private final Map<String, String> defaultTags = new HashMap<String, String>();
    2930
    3031    protected void build() {
    3132        setLayout(new BorderLayout());
    32         add(pnlTagEditor = new TagEditorPanel(null), BorderLayout.CENTER);
     33        add(pnlTagEditor, BorderLayout.CENTER);
    3334    }
    3435
     
    3738     *
    3839     * @param changesetCommentModel the changeset comment model. Must not be null.
     40     * @param changesetSourceModel the changeset source model. Must not be null.
    3941     * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null
    4042     */
    41     public TagSettingsPanel(ChangesetCommentModel changesetCommentModel) throws IllegalArgumentException{
     43    public TagSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel) throws IllegalArgumentException{
    4244        CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel");
     45        CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel");
    4346        this.changesetCommentModel = changesetCommentModel;
    44         this.changesetCommentModel.addObserver(new ChangesetCommentObserver());
     47        this.changesetSourceModel = changesetSourceModel;
     48        this.changesetCommentModel.addObserver(new ChangesetCommentObserver("comment"));
     49        this.changesetSourceModel.addObserver(new ChangesetCommentObserver("source"));
    4550        build();
    4651        pnlTagEditor.getModel().addTableModelListener(this);
    4752    }
    4853
    49     protected void setUploadComment(String comment) {
    50         if (comment == null) {
    51             comment = "";
     54    protected void setProperty(String key, String value) {
     55        if (value == null) {
     56            value = "";
    5257        }
    53         comment  = comment.trim();
    54         String commentInTag = getUploadComment();
    55         if (comment.equals(commentInTag))
     58        value = value.trim();
     59        String commentInTag = getTagEditorValue(key);
     60        if (value.equals(commentInTag))
    5661            return;
    5762
    58         if (comment.isEmpty()) {
    59             pnlTagEditor.getModel().delete("comment");
     63        if (value.isEmpty()) {
     64            pnlTagEditor.getModel().delete(key);
    6065            return;
    6166        }
    62         TagModel tag = pnlTagEditor.getModel().get("comment");
     67        TagModel tag = pnlTagEditor.getModel().get(key);
    6368        if (tag == null) {
    64             tag = new TagModel("comment", comment);
     69            tag = new TagModel(key, value);
    6570            pnlTagEditor.getModel().add(tag);
    6671        } else {
    67             pnlTagEditor.getModel().updateTagValue(tag, comment);
     72            pnlTagEditor.getModel().updateTagValue(tag, value);
    6873        }
    6974    }
    7075
    71     protected String getUploadComment() {
    72         TagModel tag = pnlTagEditor.getModel().get("comment");
     76    protected String getTagEditorValue(String key) {
     77        TagModel tag = pnlTagEditor.getModel().get(key);
    7378        if (tag == null) return null;
    7479        return tag.getValue();
     
    7681
    7782    public void initFromChangeset(Changeset cs) {
    78         String currentComment = getUploadComment();
     83        String currentComment = getTagEditorValue("comment");
    7984        Map<String,String> tags = getDefaultTags();
    8085        if (cs != null) {
     
    8388        if (tags.get("comment") == null) {
    8489            tags.put("comment", currentComment);
     90        }
     91        if (tags.get("source") == null) {
     92            tags.put("source", "");
    8593        }
    8694        String agent = Version.getInstance().getAgentString(false);
     
    123131    @Override
    124132    public void tableChanged(TableModelEvent e) {
    125         String uploadComment = getUploadComment();
    126         changesetCommentModel.setComment(uploadComment);
     133        changesetCommentModel.setComment(getTagEditorValue("comment"));
     134        changesetSourceModel.setComment(getTagEditorValue("source"));
    127135    }
    128136
     
    133141     */
    134142    class ChangesetCommentObserver implements Observer {
     143
     144        private final String key;
     145
     146        ChangesetCommentObserver(String key) {
     147            this.key = key;
     148        }
     149
    135150        @Override
    136151        public void update(Observable o, Object arg) {
    137152            if (!(o instanceof ChangesetCommentModel)) return;
    138153            String newValue = (String)arg;
    139             String oldValue = getUploadComment();
     154            String oldValue = getTagEditorValue(key);
    140155            if (oldValue == null) {
    141156                oldValue = "";
    142157            }
    143158            if (!oldValue.equals(newValue)) {
    144                 setUploadComment((String)arg);
     159                setProperty(key, (String) arg);
    145160            }
    146161        }
Note: See TracChangeset for help on using the changeset viewer.