Changeset 2040 in josm for trunk/src/org


Ignore:
Timestamp:
2009-09-03T18:51:04+02:00 (15 years ago)
Author:
Gubaer
Message:

improved upload dialog
new: tags for changesets
new: multiple uploads to the same changeset
fixed #3381: simple imput of a changeset source
fixed #2491: Allow arbitrary key-value pairs in changesets
fixed #2436: Allow multiple uploads to one changeset

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
7 edited
6 moved

Legend:

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

    r2037 r2040  
    66import java.awt.BorderLayout;
    77import java.awt.Dimension;
    8 import java.awt.FlowLayout;
    98import java.awt.GridBagConstraints;
    109import java.awt.GridBagLayout;
     
    2019import java.util.regex.Pattern;
    2120
     21import javax.swing.BoxLayout;
     22import javax.swing.ButtonGroup;
    2223import javax.swing.JCheckBox;
    2324import javax.swing.JLabel;
     
    2526import javax.swing.JOptionPane;
    2627import javax.swing.JPanel;
     28import javax.swing.JRadioButton;
    2729import javax.swing.JScrollPane;
     30import javax.swing.JTabbedPane;
    2831
    2932import org.openstreetmap.josm.Main;
    3033import org.openstreetmap.josm.data.APIDataSet;
    3134import org.openstreetmap.josm.data.conflict.ConflictCollection;
     35import org.openstreetmap.josm.data.osm.Changeset;
    3236import org.openstreetmap.josm.data.osm.DataSet;
    3337import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3943import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4044import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     45import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
     46import org.openstreetmap.josm.io.ChangesetProcessingType;
    4147import org.openstreetmap.josm.io.OsmApi;
    4248import org.openstreetmap.josm.io.OsmApiException;
     
    164170        if (!checkPreUploadConditions(Main.map.mapView.getEditLayer(), apiData))
    165171            return;
    166         Main.worker.execute(createUploadTask(Main.map.mapView.getEditLayer(), apiData.getPrimitives()));
     172        Main.worker.execute(
     173                createUploadTask(
     174                        Main.map.mapView.getEditLayer(),
     175                        apiData.getPrimitives(),
     176                        UploadConfirmationHook.getUploadDialogPanel().getChangeset(),
     177                        UploadConfirmationHook.getUploadDialogPanel().getChangesetProcessingType()
     178                )
     179        );
    167180    }
    168181
     
    439452
    440453
    441     class UploadConfirmationHook implements UploadHook {
    442 
     454    static public class UploadConfirmationHook implements UploadHook {
     455        static private UploadDialogPanel uploadDialogPanel;
     456
     457        static public UploadDialogPanel getUploadDialogPanel() {
     458            if (uploadDialogPanel == null) {
     459                uploadDialogPanel = new UploadDialogPanel();
     460            }
     461            return uploadDialogPanel;
     462        }
    443463
    444464        public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) {
    445             final UploadDialogPanel panel = new UploadDialogPanel(add, update, delete);
     465            final UploadDialogPanel panel = getUploadDialogPanel();
     466            panel.setUploadedPrimitives(add, update, delete);
    446467
    447468            ExtendedDialog dialog = new ExtendedDialog(
     
    483504    }
    484505
    485     public UploadDiffTask createUploadTask(OsmDataLayer layer, Collection<OsmPrimitive> toUpload) {
    486         return new UploadDiffTask(layer, toUpload);
     506    public UploadDiffTask createUploadTask(OsmDataLayer layer, Collection<OsmPrimitive> toUpload, Changeset changeset, ChangesetProcessingType changesetProcessingType) {
     507        return new UploadDiffTask(layer, toUpload, changeset, changesetProcessingType);
    487508    }
    488509
     
    493514        private OsmServerWriter writer;
    494515        private OsmDataLayer layer;
    495 
    496         private UploadDiffTask(OsmDataLayer layer, Collection <OsmPrimitive> toUpload) {
     516        private Changeset changeset;
     517        private ChangesetProcessingType changesetProcessingType;
     518
     519        private UploadDiffTask(OsmDataLayer layer, Collection <OsmPrimitive> toUpload, Changeset changeset, ChangesetProcessingType changesetProcessingType) {
    497520            super(tr("Uploading data for layer ''{0}''", layer.getName()),false /* don't ignore exceptions */);
    498521            this.toUpload = toUpload;
    499522            this.layer = layer;
     523            this.changeset = changeset;
     524            this.changesetProcessingType = changesetProcessingType == null ? ChangesetProcessingType.USE_NEW_AND_CLOSE : changesetProcessingType;
    500525        }
    501526
     
    504529            try {
    505530                ProgressMonitor monitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    506                 writer.uploadOsm(layer.data.version, toUpload, monitor);
     531                writer.uploadOsm(layer.data.version, toUpload, changeset,changesetProcessingType, monitor);
    507532            } catch (Exception sxe) {
    508533                if (uploadCancelled) {
     
    554579     * The panel displaying information about primitives to upload and providing
    555580     * UI widgets for entering the changeset comment and other configuration
    556      * setttings.
     581     * settings.
    557582     *
    558583     */
    559     static private class UploadDialogPanel extends JPanel {
     584    static public class UploadDialogPanel extends JPanel {
    560585
    561586        private JList lstAdd;
    562587        private JList lstUpdate;
    563588        private JList lstDelete;
     589        private JLabel lblAdd;
     590        private JLabel lblUpdate;
     591        private JLabel lblDelete;
    564592        private JCheckBox cbUseAtomicUpload;
    565593        private SuggestingJHistoryComboBox cmt;
    566 
    567         protected int getNumLists() {
    568             int ret = 0;
    569             if (lstAdd.getModel().getSize() > 0) {
    570                 ret++;
    571             }
    572             if (lstUpdate.getModel().getSize() > 0) {
    573                 ret++;
    574             }
    575             if (lstDelete.getModel().getSize() > 0) {
    576                 ret++;
    577             }
    578             return ret;
    579         }
     594        private TagEditorPanel tagEditorPanel;
     595        private JTabbedPane southTabbedPane;
     596        private ButtonGroup bgChangesetHandlingOptions;
     597        private JRadioButton rbUseNewAndClose;
     598        private JRadioButton rbUseNewAndLeaveOpen;
     599        private JRadioButton rbUseExistingAndClose;
     600        private JRadioButton rbUseExistingAndLeaveOpen;
     601        private ChangesetProcessingType changesetProcessingType;
    580602
    581603        protected JPanel buildListsPanel() {
     
    592614            gcList.fill = GridBagConstraints.BOTH;
    593615            gcList.weightx = 1.0;
    594             gcList.weighty = 1.0 / getNumLists();
     616            gcList.weighty = 1.0;
    595617            gcList.anchor = GridBagConstraints.CENTER;
    596618
    597             int y = -1;
    598 
    599             if (lstAdd.getModel().getSize() >0) {
    600                 y++;
    601                 gcLabel.gridy = y;
    602                 pnl.add(new JLabel(tr("Objects to add:")), gcLabel);
    603                 y++;
    604                 gcList.gridy = y;
    605                 pnl.add(new JScrollPane(lstAdd), gcList);
    606             }
    607             if (lstUpdate.getModel().getSize() >0) {
    608                 y++;
    609                 gcLabel.gridy = y;
    610                 pnl.add(new JLabel(tr("Objects to modify:")), gcLabel);
    611                 y++;
    612                 gcList.gridy = y;
    613                 pnl.add(new JScrollPane(lstUpdate), gcList);
    614             }
    615             if (lstDelete.getModel().getSize() >0) {
    616                 y++;
    617                 gcLabel.gridy = y;
    618                 pnl.add(new JLabel(tr("Objects to delete:")), gcLabel);
    619                 y++;
    620                 gcList.gridy = y;
    621                 pnl.add(new JScrollPane(lstDelete), gcList);
    622             }
     619            gcLabel.gridy = 0;
     620            pnl.add(lblAdd = new JLabel(tr("Objects to add:")), gcLabel);
     621
     622            gcList.gridy = 1;
     623            pnl.add(new JScrollPane(lstAdd), gcList);
     624
     625            gcLabel.gridy = 2;
     626            pnl.add(lblUpdate = new JLabel(tr("Objects to modify:")), gcLabel);
     627
     628            gcList.gridy = 3;
     629            pnl.add(new JScrollPane(lstUpdate), gcList);
     630
     631            gcLabel.gridy = 4;
     632            pnl.add(lblDelete = new JLabel(tr("Objects to delete:")), gcLabel);
     633
     634            gcList.gridy = 5;
     635            pnl.add(new JScrollPane(lstDelete), gcList);
     636            return pnl;
     637        }
     638
     639        protected JPanel buildChangesetHandlingControlPanel() {
     640            JPanel pnl = new JPanel();
     641            pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
     642            bgChangesetHandlingOptions = new ButtonGroup();
     643
     644            rbUseNewAndClose = new JRadioButton(tr("Use a new changeset and close it"));
     645            rbUseNewAndClose.setToolTipText(tr("Select to upload the data using a new changeset and to close the changeset after the upload"));
     646
     647            rbUseNewAndLeaveOpen = new JRadioButton(tr("Use a new changeset and leave it open"));
     648            rbUseNewAndLeaveOpen.setToolTipText(tr("Select to upload the data using a new changeset and to leave the changeset open after the upload"));
     649
     650            rbUseExistingAndClose = new JRadioButton();
     651            rbUseExistingAndLeaveOpen = new JRadioButton();
     652
     653            pnl.add(new JLabel(tr("Upload to a new or to an existing changeset?")));
     654            pnl.add(rbUseNewAndClose);
     655            pnl.add(rbUseNewAndLeaveOpen);
     656            pnl.add(rbUseExistingAndClose);
     657            pnl.add(rbUseExistingAndLeaveOpen);
     658
     659            rbUseNewAndClose.setVisible(false);
     660            rbUseNewAndLeaveOpen.setVisible(false);
     661            rbUseExistingAndClose.setVisible(false);
     662            rbUseExistingAndLeaveOpen.setVisible(false);
     663
     664            bgChangesetHandlingOptions.add(rbUseNewAndClose);
     665            bgChangesetHandlingOptions.add(rbUseNewAndLeaveOpen);
     666            bgChangesetHandlingOptions.add(rbUseExistingAndClose);
     667            bgChangesetHandlingOptions.add(rbUseExistingAndLeaveOpen);
    623668            return pnl;
    624669        }
     
    626671        protected JPanel buildChangesetControlPanel() {
    627672            JPanel pnl = new JPanel();
    628             pnl.setLayout(new FlowLayout(FlowLayout.LEFT));
     673            pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
    629674            pnl.add(cbUseAtomicUpload = new JCheckBox(tr("upload all changes in one request")));
    630675            cbUseAtomicUpload.setToolTipText(tr("Enable to upload all changes in one request, disable to use one request per changed primitive"));
    631676            boolean useAtomicUpload = Main.pref.getBoolean("osm-server.atomic-upload", true);
    632677            cbUseAtomicUpload.setSelected(useAtomicUpload);
    633             cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasChangesetSupport());
     678            cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasSupportForDiffUploads());
     679
     680            pnl.add(buildChangesetHandlingControlPanel());
    634681            return pnl;
    635682        }
     
    651698
    652699        protected void build() {
    653             setLayout(new BorderLayout());
    654             add(buildListsPanel(), BorderLayout.CENTER);
    655             add(buildUploadControlPanel(), BorderLayout.SOUTH);
    656         }
    657 
    658         public UploadDialogPanel(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) {
     700            setLayout(new GridBagLayout());
     701            GridBagConstraints gc = new GridBagConstraints();
     702            gc.fill = GridBagConstraints.BOTH;
     703            gc.weightx = 1.0;
     704            gc.weighty = 1.0;
     705            add(buildListsPanel(), gc);
     706
     707            southTabbedPane = new JTabbedPane();
     708            southTabbedPane.add(buildUploadControlPanel());
     709            tagEditorPanel = new TagEditorPanel();
     710            southTabbedPane.add(tagEditorPanel);
     711            southTabbedPane.setTitleAt(0, tr("Settings"));
     712            southTabbedPane.setTitleAt(1, tr("Changeset Tags"));
     713            JPanel pnl = new JPanel();
     714            pnl.setLayout(new BorderLayout());
     715            pnl.add(southTabbedPane,BorderLayout.CENTER);
     716            gc.fill = GridBagConstraints.HORIZONTAL;
     717            gc.gridy = 1;
     718            gc.weightx = 1.0;
     719            gc.weighty = 0.0;
     720            add(pnl, gc);
     721        }
     722
     723
     724        protected UploadDialogPanel() {
    659725            OsmPrimitivRenderer renderer = new OsmPrimitivRenderer();
    660726
    661             lstAdd = new JList(add.toArray());
     727            lstAdd = new JList();
    662728            lstAdd.setCellRenderer(renderer);
    663729            lstAdd.setVisibleRowCount(Math.min(lstAdd.getModel().getSize(), 10));
    664730
    665             lstUpdate = new JList(update.toArray());
     731            lstUpdate = new JList();
    666732            lstUpdate.setCellRenderer(renderer);
    667733            lstUpdate.setVisibleRowCount(Math.min(lstUpdate.getModel().getSize(), 10));
    668734
    669             lstDelete = new JList(update.toArray());
     735            lstDelete = new JList();
    670736            lstDelete.setCellRenderer(renderer);
    671737            lstDelete.setVisibleRowCount(Math.min(lstDelete.getModel().getSize(), 10));
    672738            build();
     739        }
     740
     741        public void setUploadedPrimitives(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) {
     742            lstAdd.setListData(add.toArray());
     743            lstAdd.setVisible(!add.isEmpty());
     744            lblAdd.setVisible(!add.isEmpty());
     745            lstUpdate.setListData(update.toArray());
     746            lstUpdate.setVisible(!update.isEmpty());
     747            lblUpdate.setVisible(!update.isEmpty());
     748            lstDelete.setListData(delete.toArray());
     749            lstDelete.setVisible(!delete.isEmpty());
     750            lblDelete.setVisible(!delete.isEmpty());
    673751        }
    674752
     
    682760            Main.pref.putCollection(HISTORY_KEY, cmt.getHistory());
    683761            Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected());
     762
     763            if (rbUseNewAndClose.isSelected()) {
     764                changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
     765            } else if (rbUseNewAndLeaveOpen.isSelected()) {
     766                changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN;
     767            } else if (rbUseExistingAndClose.isSelected()) {
     768                changesetProcessingType = ChangesetProcessingType.USE_EXISTING_AND_CLOSE;
     769            } else if (rbUseExistingAndLeaveOpen.isSelected()) {
     770                changesetProcessingType = ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN;
     771            }
    684772        }
    685773
    686774        public void startUserInput() {
     775            rbUseNewAndClose.setVisible(true);
     776            rbUseNewAndLeaveOpen.setVisible(true);
     777            if (OsmApi.getOsmApi().getCurrentChangeset() != null) {
     778                Changeset cs = OsmApi.getOsmApi().getCurrentChangeset();
     779                rbUseExistingAndClose.setVisible(true);
     780                rbUseExistingAndLeaveOpen.setVisible(true);
     781
     782                rbUseExistingAndClose.setText(tr("Use the existing changeset {0} and close it after upload",cs.getId()));
     783                rbUseExistingAndClose.setToolTipText(tr("Select to upload to the existing changeset {0} and to close the changeset after this upload",cs.getId()));
     784
     785                rbUseExistingAndLeaveOpen.setText(tr("Use the existing changeset {0} and leave it open",cs.getId()));
     786                rbUseExistingAndLeaveOpen.setToolTipText(tr("Select to upload to the existing changeset {0} and to leave the changeset open for further uploads",cs.getId()));
     787
     788                if (changesetProcessingType == null) {
     789                    rbUseNewAndClose.setSelected(true);
     790                } else {
     791                    switch(changesetProcessingType) {
     792                        case USE_NEW_AND_CLOSE: rbUseNewAndClose.setSelected(true); break;
     793                        case USE_NEW_AND_LEAVE_OPEN: rbUseNewAndLeaveOpen.setSelected(true); break;
     794                        case USE_EXISTING_AND_CLOSE: rbUseExistingAndClose.setSelected(true); break;
     795                        case USE_EXISTING_AND_LEAVE_OPEN: rbUseExistingAndLeaveOpen.setSelected(true); break;
     796                    }
     797                }
     798            } else {
     799                if (changesetProcessingType == null) {
     800                    changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
     801                }
     802                rbUseExistingAndClose.setVisible(false);
     803                rbUseExistingAndLeaveOpen.setVisible(false);
     804                switch(changesetProcessingType) {
     805                    case USE_NEW_AND_CLOSE: rbUseNewAndClose.setSelected(true); break;
     806                    case USE_NEW_AND_LEAVE_OPEN: rbUseNewAndLeaveOpen.setSelected(true); break;
     807                    default: rbUseNewAndClose.setSelected(true); break;
     808                }
     809            }
    687810            cmt.getEditor().selectAll();
    688811            cmt.requestFocus();
    689812        }
     813
     814        public ChangesetProcessingType getChangesetProcessingType() {
     815            if (changesetProcessingType == null) return ChangesetProcessingType.USE_NEW_AND_CLOSE;
     816            return changesetProcessingType;
     817        }
     818
     819        public Changeset getChangeset() {
     820            Changeset changeset = new Changeset();
     821            tagEditorPanel.getModel().applyToPrimitive(changeset);
     822            changeset.put("comment", cmt.getText());
     823            return changeset;
     824        }
    690825    }
    691826}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r2017 r2040  
    7373import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    7474import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     75import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField;
     76import org.openstreetmap.josm.gui.tagging.TagCellEditor;
     77import org.openstreetmap.josm.gui.tagging.TagEditorModel;
     78import org.openstreetmap.josm.gui.tagging.TagTable;
    7579import org.openstreetmap.josm.io.OsmApi;
    7680import org.openstreetmap.josm.io.OsmServerObjectReader;
     
    267271
    268272        final JScrollPane scrollPane = new JScrollPane(tagTable);
    269 
    270         // this adapters ensures that the width of the tag table columns is adjusted
    271         // to the width of the scroll pane viewport. Also tried to overwrite
    272         // getPreferredViewportSize() in JTable, but did not work.
    273         //
    274         scrollPane.addComponentListener(new ComponentAdapter() {
    275             @Override
    276             public void componentResized(ComponentEvent e) {
    277                 super.componentResized(e);
    278                 Dimension d = scrollPane.getViewport().getExtentSize();
    279                 tagTable.adjustColumnWidth(d.width);
    280             }
    281         });
    282273
    283274        GridBagConstraints gc = new GridBagConstraints();
     
    13551346
    13561347        protected void updateEnabledState() {
    1357             setEnabled(getRelation() != null && getRelation().id > 0);
     1348            setEnabled(getRelation() != null && getRelation().getId() > 0);
    13581349        }
    13591350    }
     
    15591550            try {
    15601551                progressMonitor.indeterminateSubTask("");
    1561                 OsmServerObjectReader reader = new OsmServerObjectReader(getRelation().id, OsmPrimitiveType.RELATION,
     1552                OsmServerObjectReader reader = new OsmServerObjectReader(getRelation().getId(), OsmPrimitiveType.RELATION,
    15621553                        true);
    15631554                DataSet dataSet = reader.parseOsm(progressMonitor
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java

    r1916 r2040  
    1313import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList;
    1414import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionListItem;
     15import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField;
    1516
    1617public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r2025 r2040  
    3333import org.openstreetmap.josm.Main;
    3434import org.openstreetmap.josm.actions.UploadAction;
     35import org.openstreetmap.josm.actions.UploadAction.UploadConfirmationHook;
    3536import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    3637import org.openstreetmap.josm.gui.SideButton;
     
    407408                }
    408409
    409                 currentTask = new UploadLayerTask(layerInfo.getLayer(), monitor);
     410                currentTask = new UploadLayerTask(
     411                        layerInfo.getLayer(),
     412                        monitor,
     413                        UploadAction.UploadConfirmationHook.getUploadDialogPanel().getChangeset(),
     414                        UploadAction.UploadConfirmationHook.getUploadDialogPanel().getChangesetProcessingType()
     415                );
    410416                currentFuture = worker.submit(currentTask);
    411417                try {
  • trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java

    r2037 r2040  
    77
    88import org.openstreetmap.josm.data.APIDataSet;
     9import org.openstreetmap.josm.data.osm.Changeset;
    910import org.openstreetmap.josm.data.osm.DataSet;
    1011import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1213import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1314import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     15import org.openstreetmap.josm.io.ChangesetProcessingType;
    1416import org.openstreetmap.josm.io.OsmServerWriter;
    1517
     
    3335    private OsmDataLayer layer;
    3436    private ProgressMonitor monitor;
     37    private Changeset changeset;
     38    private ChangesetProcessingType changesetProcessingType;
    3539
    3640    /**
     
    3842     * @param layer the layer. Must not be null.
    3943     * @param monitor  a progress monitor. If monitor is null, uses {@see NullProgressMonitor#INSTANCE}
     44     * @param changeset the changeset to be used if <code>changesetProcessingType</code> indicates that a new
     45     *   changeset is to be used
     46     * @param changesetProcessingType how we handle changesets
    4047     * @throws IllegalArgumentException thrown, if layer is null
    4148     */
    42     public UploadLayerTask(OsmDataLayer layer, ProgressMonitor monitor) {
     49    public UploadLayerTask(OsmDataLayer layer, ProgressMonitor monitor, Changeset changeset, ChangesetProcessingType changesetProcessingType) {
    4350        if (layer == null)
    4451            throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", layer));
     
    4855        this.layer = layer;
    4956        this.monitor = monitor;
     57        this.changeset = changeset;
     58        this.changesetProcessingType = changesetProcessingType == null ? ChangesetProcessingType.USE_NEW_AND_CLOSE : changesetProcessingType;
    5059    }
    5160
     
    6069            ProgressMonitor m = monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    6170            if (isCancelled()) return;
    62             writer.uploadOsm(layer.data.version, toUpload, m);
     71            writer.uploadOsm(layer.data.version, toUpload, changeset, changesetProcessingType, m);
    6372        } catch (Exception sxe) {
    6473            if (isCancelled()) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/AutoCompletingTextField.java

    r2037 r2040  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
     2package org.openstreetmap.josm.gui.tagging;
    33
    44import java.awt.event.FocusAdapter;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagCellEditor.java

    r2037 r2040  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
     2package org.openstreetmap.josm.gui.tagging;
    33
    44import java.awt.Component;
     
    5555    protected void initAutoCompletionListForKeys(TagEditorModel model, TagModel currentTag) {
    5656
    57         if (autoCompletionList == null) {
    58             logger.warning("autoCompletionList is null. Make sure an instance of AutoCompletionList is injected into TableCellEditor.");
     57        if (autoCompletionList == null)
     58            //logger.warning("autoCompletionList is null. Make sure an instance of AutoCompletionList is injected into TableCellEditor.");
    5959            return;
    60         }
    6160        autoCompletionList.clear();
    6261
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagCellRenderer.java

    r2037 r2040  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
     2package org.openstreetmap.josm.gui.tagging;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r2037 r2040  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
     2package org.openstreetmap.josm.gui.tagging;
    33
    44import static org.openstreetmap.josm.tools.I18n.trn;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagModel.java

    r2037 r2040  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
     2package org.openstreetmap.josm.gui.tagging;
    33
    44import java.util.ArrayList;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java

    r2037 r2040  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.dialogs.relation;
     2package org.openstreetmap.josm.gui.tagging;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.awt.AWTException;
     7import java.awt.Container;
     8import java.awt.Dimension;
    79import java.awt.MouseInfo;
    810import java.awt.Point;
     
    2022import javax.swing.JComponent;
    2123import javax.swing.JTable;
     24import javax.swing.JViewport;
    2225import javax.swing.KeyStroke;
    2326import javax.swing.ListSelectionModel;
     
    3033import javax.swing.table.TableModel;
    3134
     35import org.openstreetmap.josm.gui.dialogs.relation.RunnableAction;
    3236import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache;
    3337import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList;
     
    335339    }
    336340
    337 
    338 
    339     /**
    340      * adjusts the width of the columns for the tag name and the tag value
    341      * to the width of the scroll panes viewport.
    342      *
    343      * Note: {@see #getPreferredScrollableViewportSize()} did not work as expected
    344      *
    345      * @param scrollPaneWidth the width of the scroll panes viewport
    346      */
    347     public void adjustColumnWidth(int scrollPaneWidth) {
    348         TableColumnModel tcm = getColumnModel();
    349         int width = scrollPaneWidth;
    350         width = width / 2;
    351         if (width > 0) {
    352             tcm.getColumn(0).setMinWidth(width);
    353             tcm.getColumn(0).setMaxWidth(width);
    354             tcm.getColumn(1).setMinWidth(width);
    355             tcm.getColumn(1).setMaxWidth(width);
    356         }
    357     }
    358 
     341    @Override
     342    public Dimension getPreferredSize(){
     343        Container c = getParent();
     344        while(c != null && ! (c instanceof JViewport)) {
     345            c = c.getParent();
     346        }
     347        if (c != null) {
     348            Dimension d = super.getPreferredSize();
     349            d.width = c.getSize().width;
     350            return d;
     351        }
     352        return super.getPreferredSize();
     353    }
    359354
    360355    @Override protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r2037 r2040  
    145145
    146146    /**
    147      * Returns true if the negotiated version supports changesets.
    148      * @return true if the negotiated version supports changesets.
    149      */
    150     public boolean hasChangesetSupport() {
     147     * Returns true if the negotiated version supports diff uploads.
     148     * @return true if the negotiated version supports diff uploads
     149     */
     150    public boolean hasSupportForDiffUploads() {
    151151        return ((version != null) && (version.compareTo("0.6")>=0));
    152152    }
     
    280280
    281281    /**
    282      * Creates a new changeset on the server to use for subsequent calls.
    283      * @param comment the "commit comment" for the new changeset
     282     * Creates the changeset to be used for subsequent uploads.
     283     *
     284     * If changesetProcessingType is {@see ChangesetProcessingType#USE_NEW} creates a new changeset based
     285     * on <code>changeset</code>. Otherwise uses the changeset given by {@see OsmApi#getCurrentChangeset()}.
     286     * If this changeset is null or has an id of value 0, a new changeset is created too.
     287     *
     288     * @param changeset the changeset to be used for uploading if <code>changesetProcessingType</code> is
     289     *   {@see ChangesetProcessingType#USE_NEW}
     290     * @param changesetProcessingType  how to handel changesets; set to {@see ChangesetProcessingType#USE_NEW} if null
     291     * @param progressMonitor the progress monitor
    284292     * @throws OsmTransferException signifying a non-200 return code, or connection errors
    285293     */
    286     public void createChangeset(String comment, ProgressMonitor progressMonitor) throws OsmTransferException {
    287         progressMonitor.beginTask((tr("Opening changeset...")));
     294    public void createChangeset(Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
     295        if (changesetProcessingType == null) {
     296            changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
     297        }
    288298        try {
    289             changeset = new Changeset();
    290             Properties sysProp = System.getProperties();
    291             Object ua = sysProp.get("http.agent");
    292             changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString());
    293             changeset.put("comment", comment);
    294             createPrimitive(changeset, progressMonitor);
     299            progressMonitor.beginTask((tr("Creating changeset...")));
     300            if (changesetProcessingType.isUseNew()) {
     301                Properties sysProp = System.getProperties();
     302                Object ua = sysProp.get("http.agent");
     303                changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString());
     304                createPrimitive(changeset, progressMonitor);
     305                this.changeset = changeset;
     306                progressMonitor.setCustomText((tr("Successfully opened changeset {0}",changeset.getId())));
     307            } else {
     308                if (this.changeset == null || this.changeset.getId() == 0) {
     309                    progressMonitor.setCustomText((tr("No currently open changeset. Opening a new changeset...")));
     310                    System.out.println(tr("Warning: could not reuse an existing changeset as requested. Opening a new one."));
     311                    Properties sysProp = System.getProperties();
     312                    Object ua = sysProp.get("http.agent");
     313                    changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString());
     314                    createPrimitive(changeset, progressMonitor);
     315                    this.changeset = changeset;
     316                    progressMonitor.setCustomText((tr("Successfully opened changeset {0}",this.changeset.getId())));
     317                } else {
     318                    progressMonitor.setCustomText((tr("Reusing existing changeset {0}", this.changeset.getId())));
     319                }
     320            }
    295321        } finally {
    296322            progressMonitor.finishTask();
     
    301327     * Closes a changeset on the server.
    302328     *
     329     * @param changesetProcessingType how changesets are currently handled
     330     * @param progressMonitor the progress monitor
     331     *
    303332     * @throws OsmTransferException if something goes wrong.
    304333     */
    305     public void stopChangeset(ProgressMonitor progressMonitor) throws OsmTransferException {
    306         progressMonitor.beginTask(tr("Closing changeset {0}...", changeset.getId()));
     334    public void stopChangeset(ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
     335        if (changesetProcessingType == null) {
     336            changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
     337        }
    307338        try {
     339            progressMonitor.beginTask(tr("Closing changeset..."));
    308340            initialize(progressMonitor);
    309             sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor);
    310             changeset = null;
     341            if (changesetProcessingType.isCloseAfterUpload()) {
     342                progressMonitor.setCustomText(tr("Closing changeset {0}...", changeset.getId()));
     343                if (this.changeset != null && this.changeset.getId() > 0) {
     344                    sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor);
     345                    changeset = null;
     346                }
     347            } else {
     348                progressMonitor.setCustomText(tr("Leaving changeset {0} open...", changeset.getId()));
     349            }
    311350        } finally {
    312351            progressMonitor.finishTask();
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r2037 r2040  
    1212import org.openstreetmap.josm.Main;
    1313import org.openstreetmap.josm.actions.UploadAction;
     14import org.openstreetmap.josm.data.osm.Changeset;
    1415import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    8182     *
    8283     * @param primitives the collection of primitives to upload
     84     * @param changeset the changeset to be used if <code>changesetProcessingType</code> indicates that
     85     *   a new changeset should be opened
     86     * @param changesetProcessingType how we handle changesets
    8387     * @param progressMonitor the progress monitor
    8488     * @throws OsmTransferException thrown if an exception occurs
    8589     */
    86     protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     90    protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
    8791        try {
    8892            progressMonitor.setTicksCount(primitives.size());
    89             api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false));
     93            api.createChangeset(changeset, changesetProcessingType,progressMonitor.createSubTaskMonitor(0, false));
    9094            uploadStartTime = System.currentTimeMillis();
    9195            for (OsmPrimitive osm : primitives) {
     
    121125
    122126                if (api.getCurrentChangeset() != null && api.getCurrentChangeset().getId() > 0) {
    123                     api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false));
     127                    api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false));
    124128                }
    125129            } catch(Exception e) {
     
    138142     * @throws OsmTransferException thrown if an exception occurs
    139143     */
    140     protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     144    protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
    141145        // upload everything in one changeset
    142146        //
    143147        try {
    144             api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false));
     148            api.createChangeset(changeset, changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false));
    145149            processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)));
    146150        } catch(OsmTransferException e) {
     
    150154        } finally {
    151155            try {
    152                 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false));
     156                api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false));
    153157            } catch (Exception ee) {
    154158                OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee);
     
    165169     * @param primitives list of objects to send
    166170     */
    167     public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     171    public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
    168172        processed = new LinkedList<OsmPrimitive>();
    169173
     
    171175
    172176        try {
    173             // check whether we can use changeset
     177            // check whether we can use diff upload
    174178            //
    175             boolean canUseChangeset = api.hasChangesetSupport();
    176             boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0);
    177             if (useChangeset && ! canUseChangeset) {
    178                 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion));
    179                 useChangeset = false;
    180             }
    181 
    182             if (useChangeset) {
     179            boolean casUseDiffUploads = api.hasSupportForDiffUploads();
     180            boolean useDiffUpload = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0);
     181            if (useDiffUpload && ! casUseDiffUploads) {
     182                System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use diff uploads, but API is not able to handle them. Ignoring diff upload.", "osm-server.atomic-upload", apiVersion));
     183                useDiffUpload = false;
     184            }
     185
     186            if (useDiffUpload) {
    183187                progressMonitor.beginTask(tr("Starting to upload in one request ..."));
    184                 uploadChangesAsDiffUpload(primitives, progressMonitor);
     188                uploadChangesAsDiffUpload(primitives,changeset, changesetProcessingType, progressMonitor);
    185189            } else {
    186190                progressMonitor.beginTask(tr("Starting to upload with one request per primitive ..."));
    187                 uploadChangesIndividually(primitives, progressMonitor);
     191                uploadChangesIndividually(primitives,changeset,changesetProcessingType, progressMonitor);
    188192            }
    189193        } finally {
Note: See TracChangeset for help on using the changeset viewer.