Ignore:
Timestamp:
2009-12-11T23:07:59+01:00 (16 years ago)
Author:
Gubaer
Message:

new: global in-memory cache for downloaded changesets
new: toggle dialog for changesets
new: downloading of changesets (currently without changeset content, will follow later)

File:
1 edited

Legend:

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

    r2512 r2613  
    22package org.openstreetmap.josm.io;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
     6
    47import java.io.InputStream;
     8import java.util.ArrayList;
     9import java.util.Collection;
     10import java.util.Collections;
     11import java.util.Iterator;
    512import java.util.List;
    613
     
    916import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1017import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    11 import static org.openstreetmap.josm.tools.I18n.tr;
    1218
    1319/**
     
    6874
    6975    /**
    70      * Reads teh changeset with id <code>id</code> from the server
     76     * Reads the changeset with id <code>id</code> from the server
    7177     *
    7278     * @param id  the changeset id. id > 0 required.
     
    104110
    105111    /**
     112     * Reads the changeset with id <code>id</code> from the server
     113     *
     114     * @param ids  the list of ids. Ignored if null. Only load changesets for ids > 0.
     115     * @param monitor the progress monitor. Set to {@see NullProgressMonitor#INSTANCE} if null
     116     * @return the changeset read
     117     * @throws OsmTransferException thrown if something goes wrong
     118     * @throws IllegalArgumentException if id <= 0
     119     */
     120    public List<Changeset> readChangesets(Collection<Integer> ids, ProgressMonitor monitor) throws OsmTransferException {
     121        if (ids == null)
     122            return Collections.emptyList();
     123        if (monitor == null) {
     124            monitor = NullProgressMonitor.INSTANCE;
     125        }
     126        try {
     127            monitor.beginTask(trn("Downloading {0} changeset ...", "Downloading {0} changesets ...",ids.size(),ids.size()));
     128            monitor.setTicksCount(ids.size());
     129            List<Changeset> ret = new ArrayList<Changeset>();
     130            int i=0;
     131            for (Iterator<Integer> it = ids.iterator(); it.hasNext(); ) {
     132                int id = it.next();
     133                if (id <= 0) {
     134                    continue;
     135                }
     136                i++;
     137                StringBuffer sb = new StringBuffer();
     138                sb.append("changeset/").append(id);
     139                InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true));
     140                if (in == null)
     141                    return null;
     142                monitor.indeterminateSubTask(tr("({0}/{1}) Downloading changeset {0} ...", i,ids.size(), id));
     143                List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true));
     144                if (changesets == null || changesets.isEmpty()) {
     145                    continue;
     146                }
     147                ret.addAll(changesets);
     148                monitor.worked(1);
     149            }
     150            return ret;
     151        } catch(OsmTransferException e) {
     152            throw e;
     153        } catch(IllegalDataException e) {
     154            throw new OsmTransferException(e);
     155        } finally {
     156            monitor.finishTask();
     157        }
     158    }
     159
     160    /**
    106161     * not implemented yet
    107162     *
Note: See TracChangeset for help on using the changeset viewer.