Ignore:
Timestamp:
2009-12-04T15:53:55+01:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3684: Add "chunked" upload mode
Removed support for API "0.5" when uploading (there are still 0.5-files around, but I'm not aware of any 0.5-servers)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMergeModel.java

    r2512 r2569  
    1515import java.util.HashMap;
    1616import java.util.Observable;
    17 import java.util.logging.Logger;
    1817
    1918import javax.swing.AbstractListModel;
     
    120119        return entries.get(MERGED_ENTRIES);
    121120    }
     121
    122122    protected ArrayList<T> getMyEntries() {
    123123        return entries.get(MY_ENTRIES);
    124124    }
     125
    125126    protected ArrayList<T> getTheirEntries() {
    126127        return entries.get(THEIR_ENTRIES);
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberListMergeModel.java

    r2512 r2569  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.util.ArrayList;
    67import java.util.logging.Logger;
    78
     
    1617 * The model for merging two lists of relation members
    1718 *
    18  *
    1919 */
    2020public class RelationMemberListMergeModel extends ListMergeModel<RelationMember>{
     
    2424    @Override
    2525    public boolean isEqualEntry(RelationMember e1, RelationMember e2) {
    26         boolean ret = e1.getRole().equals(e2.getRole());
    27         if (!e1.getMember().isNew() ) {
    28             ret = ret && (e1.getMember().getId() == e2.getMember().getId());
    29         } else {
    30             ret = ret && (e1 == e2);
    31         }
    32         return ret;
     26        return e1.equals(e2);
    3327    }
    3428
     
    119113        if (! isFrozen())
    120114            throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Can't build resolution command"));
    121         return new RelationMemberConflictResolverCommand(my, their, getMergedEntries());
     115        ArrayList<RelationMember> entries = getMergedEntries();
     116        return new RelationMemberConflictResolverCommand(my, their, entries);
    122117    }
    123118}
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r2512 r2569  
    298298        public void cancel() {
    299299            switch(model.getMode()) {
    300                 case EDITING_DATA: cancelWhenInEditingModel(); break;
    301                 case UPLOADING_AND_SAVING: cancelSafeAndUploadTask(); break;
     300            case EDITING_DATA: cancelWhenInEditingModel(); break;
     301            case UPLOADING_AND_SAVING: cancelSafeAndUploadTask(); break;
    302302            }
    303303        }
     
    333333                Mode mode = (Mode)evt.getNewValue();
    334334                switch(mode) {
    335                     case EDITING_DATA: setEnabled(true); break;
    336                     case UPLOADING_AND_SAVING: setEnabled(false); break;
     335                case EDITING_DATA: setEnabled(true); break;
     336                case UPLOADING_AND_SAVING: setEnabled(false); break;
    337337                }
    338338            }
     
    367367                SaveLayersModel.Mode mode = (SaveLayersModel.Mode)evt.getNewValue();
    368368                switch(mode) {
    369                     case EDITING_DATA: setEnabled(true); break;
    370                     case UPLOADING_AND_SAVING: setEnabled(false); break;
     369                case EDITING_DATA: setEnabled(true); break;
     370                case UPLOADING_AND_SAVING: setEnabled(false); break;
    371371                }
    372372            }
     
    408408
    409409                currentTask = new UploadLayerTask(
     410                        UploadDialog.getUploadDialog().getUploadStrategySpecification(),
    410411                        layerInfo.getLayer(),
    411412                        monitor,
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r2512 r2569  
    22package org.openstreetmap.josm.gui.io;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.I18n.trn;
     
    5051import org.openstreetmap.josm.data.osm.Changeset;
    5152import org.openstreetmap.josm.data.osm.OsmPrimitive;
     53import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    5254import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    5355import org.openstreetmap.josm.gui.SideButton;
     
    5860import org.openstreetmap.josm.gui.tagging.TagModel;
    5961import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    60 import org.openstreetmap.josm.io.OsmApi;
    6162import org.openstreetmap.josm.tools.GBC;
    6263import org.openstreetmap.josm.tools.ImageProvider;
     
    192193                JComponent.WHEN_IN_FOCUSED_WINDOW
    193194        );
    194         pnl.add(new SideButton(new ContextSensitiveHelpAction("/Dialogs/UploadDialog")));
    195         HelpUtil.setHelpContext(getRootPane(),"/Dialogs/UploadDialog");
     195        pnl.add(new SideButton(new ContextSensitiveHelpAction(ht("/Dialogs/UploadDialog"))));
     196        HelpUtil.setHelpContext(getRootPane(),ht("/Dialogs/UploadDialog"));
    196197        return pnl;
    197198    }
     
    293294            pnlLists.add(spDelete, gcList);
    294295        }
     296        pnlChangesetSelection.setNumUploadedObjects(add.size() + update.size() + delete.size());
    295297    }
    296298
     
    320322        cs.put("comment", getUploadComment());
    321323        return cs;
     324    }
     325
     326    /**
     327     * Replies the {@see UploadStrategySpecification} the user entered in the dialog.
     328     *
     329     * @return the {@see UploadStrategySpecification} the user entered in the dialog.
     330     */
     331    public UploadStrategySpecification getUploadStrategySpecification() {
     332        return pnlChangesetSelection.getUploadStrategySpecification();
    322333    }
    323334
     
    487498
    488499        protected void warnIllegalUploadComment() {
    489             JOptionPane.showMessageDialog(
     500            HelpAwareOptionPane.showOptionDialog(
    490501                    UploadDialog.this,
    491502                    tr("Please enter a comment for this upload changeset (min. 3 characters)"),
    492503                    tr("Illegal upload comment"),
    493                     JOptionPane.ERROR_MESSAGE
     504                    JOptionPane.ERROR_MESSAGE,
     505                    ht("/Dialog/UploadDialog#IllegalUploadComment")
    494506
    495507            );
    496508        }
     509
     510        protected void warnIllegalChunkSize() {
     511            HelpAwareOptionPane.showOptionDialog(
     512                    UploadDialog.this,
     513                    tr("Please enter a valid chunk size first"),
     514                    tr("Illegal chunk size"),
     515                    JOptionPane.ERROR_MESSAGE,
     516                    ht("/Dialog/UploadDialog#IllegalChunkSize")
     517            );
     518        }
     519
     520
    497521        public void actionPerformed(ActionEvent e) {
    498522            if (getUploadComment().trim().length() < 3) {
     
    502526                return;
    503527            }
     528            UploadStrategySpecification strategy = getUploadStrategySpecification();
     529            if (strategy.getStrategy().equals(UploadStrategy.CHUNKED_DATASET_STRATEGY)) {
     530                if (strategy.getChunkSize() == UploadStrategySpecification.UNSPECIFIED_CHUNK_SIZE) {
     531                    warnIllegalChunkSize();
     532                    southTabbedPane.setSelectedIndex(0);
     533                    pnlChangesetSelection.initEditingOfChunkSize();
     534                    return;
     535                }
     536            }
    504537            setCanceled(false);
    505538            setVisible(false);
    506 
    507539        }
    508540    }
     
    607639        private OpenChangesetModel model;
    608640        private HistoryComboBox cmt;
    609         private JCheckBox cbUseAtomicUpload;
     641        private UploadStrategySelectionPanel pnlUploadStrategy;
    610642
    611643        /**
     
    615647         * @return the panel
    616648         */
    617         protected JPanel buildAtomicUploadControlPanel() {
    618             JPanel pnl = new JPanel();
    619             pnl.setLayout(new GridBagLayout());
    620             GridBagConstraints gc = new GridBagConstraints();
    621             gc.fill = GridBagConstraints.HORIZONTAL;
    622             gc.weightx = 1.0;
    623             gc.anchor = GridBagConstraints.FIRST_LINE_START;
    624             pnl.add(cbUseAtomicUpload = new JCheckBox(tr("Upload all changes in one request")), gc);
    625             cbUseAtomicUpload.setToolTipText(tr("Enable to upload all changes in one request, disable to use one request per changed primitive"));
    626             boolean useAtomicUpload = Main.pref.getBoolean("osm-server.atomic-upload", true);
    627             cbUseAtomicUpload.setSelected(useAtomicUpload);
    628             cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasSupportForDiffUploads());
    629             return pnl;
     649        protected JPanel buildUploadStrategySelectionPanel() {
     650            pnlUploadStrategy = new UploadStrategySelectionPanel();
     651            pnlUploadStrategy.initFromPreferences();
     652            return pnlUploadStrategy;
    630653        }
    631654
     
    678701            gc.weightx = 1.0;
    679702            gc.anchor = GridBagConstraints.FIRST_LINE_START;
    680             add(buildAtomicUploadControlPanel(), gc);
     703            add(buildUploadStrategySelectionPanel(), gc);
    681704
    682705            // -- changeset command
     
    764787            cmt.addCurrentItemToHistory();
    765788            Main.pref.putCollection(HISTORY_KEY, cmt.getHistory());
    766             Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected());
     789            pnlUploadStrategy.saveToPreferences();
    767790        }
    768791
     
    819842        }
    820843
     844        public void initEditingOfChunkSize() {
     845            pnlUploadStrategy.initEditingOfChunkSize();
     846        }
     847
    821848        protected void refreshGUI() {
    822849            rbExisting.setEnabled(model.getSize() > 0);
     
    848875                return new Changeset();
    849876            return cs;
     877        }
     878
     879        /**
     880         * Replies the {@see UploadStrategySpecification} the user entered in the dialog.
     881         *
     882         * @return the {@see UploadStrategySpecification} the user entered in the dialog.
     883         */
     884        public UploadStrategySpecification getUploadStrategySpecification() {
     885            return pnlUploadStrategy.getUploadStrategySpecification();
    850886        }
    851887
     
    932968        public boolean isCloseAfterUpload() {
    933969            return cbCloseAfterUpload.isSelected();
     970        }
     971
     972        public void setNumUploadedObjects(int numUploadedObjects) {
     973            pnlUploadStrategy.setNumUploadedObjects(numUploadedObjects);
    934974        }
    935975
  • trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java

    r2512 r2569  
    4444    private Collection<OsmPrimitive> toUpload;
    4545    private HashSet<OsmPrimitive> processedPrimitives;
     46    private UploadStrategySpecification strategy;
    4647
    4748    /**
    48      *
     49     * Creates the upload task
     50     *
     51     * @param strategy the upload strategy specification
    4952     * @param layer the layer. Must not be null.
    5053     * @param monitor  a progress monitor. If monitor is null, uses {@see NullProgressMonitor#INSTANCE}
     
    5255     * @param closeChangesetAfterUpload true, if the changeset should be closed after the upload
    5356     * @throws IllegalArgumentException thrown, if layer is null
     57     * @throws IllegalArgumentException thrown if strategy is null
    5458     */
    55     public UploadLayerTask(OsmDataLayer layer, ProgressMonitor monitor, Changeset changeset, boolean closeChangesetAfterUpload) {
     59    public UploadLayerTask(UploadStrategySpecification strategy, OsmDataLayer layer, ProgressMonitor monitor, Changeset changeset, boolean closeChangesetAfterUpload) {
    5660        if (layer == null)
    57             throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", layer));
     61            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "layer"));
     62        if (strategy == null)
     63            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "strategy"));
    5864        if (monitor == null) {
    5965            monitor = NullProgressMonitor.INSTANCE;
     
    6268        this.monitor = monitor;
    6369        this.changeset = changeset;
     70        this.strategy = strategy;
    6471        this.closeChangesetAfterUpload = closeChangesetAfterUpload;
    6572        processedPrimitives = new HashSet<OsmPrimitive>();
     
    103110    @Override
    104111    public void run() {
    105         monitor.subTask(tr("Preparing primitives to upload ..."));
     112        monitor.indeterminateSubTask(tr("Preparing primitives to upload ..."));
    106113        APIDataSet ds = new APIDataSet(layer.data);
    107114        try {
     
    120127                    ProgressMonitor m = monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    121128                    if (isCancelled()) return;
    122                     writer.uploadOsm(layer.data.getVersion(), toUpload, changeset, m);
     129                    writer.uploadOsm(strategy, toUpload, changeset, m);
    123130                    processedPrimitives.addAll(writer.getProcessedPrimitives());
    124131                    break;
Note: See TracChangeset for help on using the changeset viewer.