Changeset 9514 in josm for trunk/src/org


Ignore:
Timestamp:
2016-01-17T22:38:38+01:00 (9 years ago)
Author:
simon04
Message:

fix #4003 fix #7004 fix #8149 - Improve changeset tags handling (from earlier changeset, from dataset)

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r9462 r9514  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
    9 import java.util.HashMap;
    109import java.util.LinkedList;
    1110import java.util.List;
    12 import java.util.Map;
    1311
    1412import javax.swing.JOptionPane;
    15 import javax.swing.SwingUtilities;
    1613
    1714import org.openstreetmap.josm.Main;
     
    234231
    235232        final UploadDialog dialog = UploadDialog.getUploadDialog();
    236         // If we simply set the changeset comment here, it would be
    237         // overridden by subsequent events in EDT that are caused by
    238         // dialog creation. The current solution is to queue this operation
    239         // after these events.
    240         // TODO: find better way to initialize the comment field
    241         SwingUtilities.invokeLater(new Runnable() {
    242             @Override
    243             public void run() {
    244                 final Map<String, String> tags = new HashMap<>(layer.data.getChangeSetTags());
    245                 if (!tags.containsKey("source")) {
    246                     tags.put("source", dialog.getLastChangesetSourceFromHistory());
    247                 }
    248                 if (!tags.containsKey("comment")) {
    249                     tags.put("comment", dialog.getLastChangesetCommentFromHistory());
    250                 }
    251                 dialog.setDefaultChangesetTags(tags);
    252             }
    253         });
     233        dialog.setChangesetTags(layer.data);
    254234        dialog.setUploadedPrimitives(apiData);
    255235        dialog.setVisible(true);
  • trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java

    r9078 r9514  
    290290                Changeset cs = (Changeset) cbOpenChangesets.getSelectedItem();
    291291                if (cs == null) return;
    292                 changesetCommentModel.setComment(cs.get("comment"));
    293292                firePropertyChange(SELECTED_CHANGESET_PROP, null, cs);
    294293            }
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r9246 r9514  
    33
    44import java.awt.BorderLayout;
    5 import java.util.HashMap;
     5import java.util.Collections;
    66import java.util.Map;
    77import java.util.Observable;
     
    1313
    1414import org.openstreetmap.josm.Main;
    15 import org.openstreetmap.josm.data.Version;
    1615import org.openstreetmap.josm.data.osm.Changeset;
     16import org.openstreetmap.josm.data.osm.DataSet;
    1717import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    1818import org.openstreetmap.josm.gui.tagging.TagModel;
     
    2626    private final transient ChangesetCommentModel changesetCommentModel;
    2727    private final transient ChangesetCommentModel changesetSourceModel;
    28     /** tags that applied to uploaded changesets by default*/
    29     private final transient Map<String, String> defaultTags = new HashMap<>();
    3028
    3129    protected void build() {
     
    8179
    8280    /**
    83      * Initialize panel from changeset.
    84      * @param cs changeset
     81     * Initialize panel from the given tags.
     82     * @param tags the tags used to initialize the panel
    8583     */
    86     public void initFromChangeset(Changeset cs) {
    87         Map<String, String> tags = getDefaultTags();
    88         if (cs != null) {
    89             tags.putAll(cs.getKeys());
    90         }
    91         if (tags.get("comment") == null) {
    92             tags.put("comment", getTagEditorValue("comment"));
    93         }
    94         if (tags.get("source") == null) {
    95             tags.put("source", getTagEditorValue("source"));
    96         }
    97         String agent = Version.getInstance().getAgentString(false);
    98         String created_by = tags.get("created_by");
    99         if (created_by == null || created_by.isEmpty()) {
    100             tags.put("created_by", agent);
    101         } else if (!created_by.contains(agent)) {
    102             tags.put("created_by", created_by + ';' + agent);
    103         }
     84    public void initFromTags(Map<String, String> tags) {
    10485        pnlTagEditor.getModel().initFromTags(tags);
    10586    }
     
    11596
    11697    /**
    117      * Replies the map with the default tags.
    118      * @return the map with the default tags
     98     * @return an empty map
     99     * @deprecated No longer supported, returns an empty map
    119100     */
     101    @Deprecated
    120102    public Map<String, String> getDefaultTags() {
    121         Map<String, String> tags = new HashMap<>();
    122         tags.putAll(defaultTags);
    123         return tags;
     103        return Collections.emptyMap();
    124104    }
    125105
    126106    /**
    127      * Sets the map with the default tags.
    128      * @param tags the map with the default tags
     107     * @param tags ignored
     108     * @deprecated No longer supported, does nothing; use {@link UploadDialog#setChangesetTags(DataSet)} instead!
    129109     */
     110    @Deprecated
    130111    public void setDefaultTags(Map<String, String> tags) {
    131         defaultTags.clear();
    132         defaultTags.putAll(tags);
    133         tableChanged(null);
    134112    }
    135113
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r8870 r9514  
    2020import java.util.Collection;
    2121import java.util.Collections;
     22import java.util.HashMap;
     23import java.util.Iterator;
    2224import java.util.List;
    2325import java.util.Map;
     
    3941import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    4042import org.openstreetmap.josm.data.Preferences.Setting;
     43import org.openstreetmap.josm.data.Version;
    4144import org.openstreetmap.josm.data.osm.Changeset;
     45import org.openstreetmap.josm.data.osm.DataSet;
    4246import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4347import org.openstreetmap.josm.gui.ExtendedDialog;
     
    101105    private final transient ChangesetCommentModel changesetSourceModel = new ChangesetCommentModel();
    102106
     107    private transient DataSet dataSet;
     108
    103109    /**
    104110     * builds the content panel for the upload dialog
     
    194200        // changes
    195201        //
     202        pnlChangesetManagement.addPropertyChangeListener(this);
    196203        pnlChangesetManagement.addPropertyChangeListener(
    197204                pnlBasicUploadSettings.getUploadParameterSummaryPanel()
     
    267274    }
    268275
     276    /**
     277     * Sets the tags for this upload based on (later items overwrite earlier ones):
     278     * <ul>
     279     * <li>previous "source" and "comment" input</li>
     280     * <li>the tags set in the dataset (see {@link DataSet#getChangeSetTags()})</li>
     281     * <li>the tags from the selected open changeset</li>
     282     * <li>the JOSM user agent (see {@link Version#getAgentString(boolean)})</li>
     283     * </ul>
     284     *
     285     * @param dataSet to obtain the tags set in the dataset
     286     */
     287    public void setChangesetTags(DataSet dataSet) {
     288        final Map<String, String> tags = new HashMap<>();
     289
     290        // obtain from previos input
     291        tags.put("source", getLastChangesetSourceFromHistory());
     292        tags.put("comment", getLastChangesetCommentFromHistory());
     293
     294        // obtain from dataset
     295        if (dataSet != null) {
     296            tags.putAll(dataSet.getChangeSetTags());
     297        }
     298        this.dataSet = dataSet;
     299
     300        // obtain from selected open changeset
     301        if (pnlChangesetManagement.getSelectedChangeset() != null) {
     302            tags.putAll(pnlChangesetManagement.getSelectedChangeset().getKeys());
     303        }
     304
     305        // set/adapt created_by
     306        final String agent = Version.getInstance().getAgentString(false);
     307        final String created_by = tags.get("created_by");
     308        if (created_by == null || created_by.isEmpty()) {
     309            tags.put("created_by", agent);
     310        } else if (!created_by.contains(agent)) {
     311            tags.put("created_by", created_by + ';' + agent);
     312        }
     313
     314        // remove empty values
     315        final Iterator<String> it = tags.keySet().iterator();
     316        while (it.hasNext()) {
     317            final String v = tags.get(it.next());
     318            if (v == null || v.isEmpty()) {
     319                it.remove();
     320            }
     321        }
     322
     323        pnlTagSettings.initFromTags(tags);
     324        pnlTagSettings.tableChanged(null);
     325    }
     326
    269327    @Override
    270328    public void rememberUserInput() {
     
    280338        pnlBasicUploadSettings.startUserInput();
    281339        pnlTagSettings.startUserInput();
    282         pnlTagSettings.initFromChangeset(pnlChangesetManagement.getSelectedChangeset());
    283340        pnlUploadStrategySelectionPanel.initFromPreferences();
    284341        UploadParameterSummaryPanel pnl = pnlBasicUploadSettings.getUploadParameterSummaryPanel();
     
    310367    }
    311368
     369    /**
     370     * @deprecated No longer supported, does nothing; use {@link #setChangesetTags(DataSet)} instead!
     371     */
     372    @Deprecated
    312373    public void setDefaultChangesetTags(Map<String, String> tags) {
    313         pnlTagSettings.setDefaultTags(tags);
    314         changesetCommentModel.setComment(tags.get("comment"));
    315         changesetSourceModel.setComment(tags.get("source"));
    316374    }
    317375
     
    543601        if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) {
    544602            Changeset cs = (Changeset) evt.getNewValue();
     603            setChangesetTags(dataSet);
    545604            if (cs == null) {
    546605                tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
Note: See TracChangeset for help on using the changeset viewer.