Changeset 4734 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2011-12-28T20:40:46+01:00 (13 years ago)
Author:
Don-vip
Message:

fix #7194 - Reworking of osmChange downloads (Fail to update a way loaded from osmChange that have been deleted after)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 deleted
7 edited

Legend:

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

    r4661 r4734  
    11package org.openstreetmap.josm.actions.downloadtasks;
    22
    3 import static org.openstreetmap.josm.tools.I18n.tr;
    4 
     3import java.util.ArrayList;
     4import java.util.Date;
     5import java.util.Iterator;
     6import java.util.List;
    57import java.util.concurrent.Future;
    68
     
    810import org.openstreetmap.josm.data.Bounds;
    911import org.openstreetmap.josm.data.osm.DataSet;
    10 import org.openstreetmap.josm.gui.io.UpdatePrimitivesTask;
     12import org.openstreetmap.josm.data.osm.NodeData;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
     14import org.openstreetmap.josm.data.osm.PrimitiveData;
     15import org.openstreetmap.josm.data.osm.PrimitiveId;
     16import org.openstreetmap.josm.data.osm.RelationData;
     17import org.openstreetmap.josm.data.osm.WayData;
     18import org.openstreetmap.josm.data.osm.history.History;
     19import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
     20import org.openstreetmap.josm.data.osm.history.HistoryDataSetListener;
     21import org.openstreetmap.josm.data.osm.history.HistoryNode;
     22import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
     23import org.openstreetmap.josm.data.osm.history.HistoryRelation;
     24import org.openstreetmap.josm.data.osm.history.HistoryWay;
     25import org.openstreetmap.josm.gui.history.HistoryLoadTask;
    1126import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1227import org.openstreetmap.josm.io.OsmServerLocationReader;
    1328import org.openstreetmap.josm.io.OsmServerReader;
    1429import org.openstreetmap.josm.io.OsmTransferException;
     30import org.openstreetmap.josm.tools.Pair;
    1531
    1632public class DownloadOsmChangeTask extends DownloadOsmTask {
     
    6581            if (isFailed() || isCanceled() || downloadedData == null)
    6682                return; // user canceled download or error occurred
    67             progressMonitor.subTask(tr("Updating data"));
    68             UpdatePrimitivesTask task = new UpdatePrimitivesTask(targetLayer, downloadedData.allPrimitives());
    69             Main.worker.submit(task);
     83            try {
     84                // A changeset does not contain all referred primitives, this is the list of incomplete ones
     85                List<OsmPrimitive> toLoad = new ArrayList<OsmPrimitive>();
     86                // For each incomplete primitive, we'll have to get its state at date it was referred
     87                List<Pair<OsmPrimitive, Date>> toMonitor = new ArrayList<Pair<OsmPrimitive, Date>>();
     88                for (OsmPrimitive p : downloadedData.allNonDeletedPrimitives()) {
     89                    if (p.isIncomplete()) {
     90                        Date timestamp = null;
     91                        for (OsmPrimitive ref : p.getReferrers()) {
     92                            if (!ref.isTimestampEmpty()) {
     93                                timestamp = ref.getTimestamp();
     94                                break;
     95                            }
     96                        }
     97                        toLoad.add(p);
     98                        toMonitor.add(new Pair<OsmPrimitive, Date>(p, timestamp));
     99                    }
     100                }
     101                if (isCanceled()) return;
     102                // Updating process is asynchronous and done after each history request
     103                HistoryDataSet.getInstance().addHistoryDataSetListener(new HistoryListener(toMonitor));
     104                // Let's load all required history
     105                Main.worker.submit(new HistoryLoadTask().add(toLoad));
     106            } catch (Exception e) {
     107                rememberException(e);
     108                setFailed(true);
     109            }
     110        }
     111    }
     112    /**
     113     * Asynchroneous updater of incomplete primitives.
     114     *
     115     */
     116    private class HistoryListener implements HistoryDataSetListener {
     117
     118        private final List<Pair<OsmPrimitive, Date>> toMonitor;
     119       
     120        public HistoryListener(List<Pair<OsmPrimitive, Date>> toMonitor) {
     121            this.toMonitor = toMonitor;
     122        }
     123
     124        @Override
     125        public void historyUpdated(HistoryDataSet source, PrimitiveId id) {
     126            for (Iterator<Pair<OsmPrimitive, Date>> it = toMonitor.iterator(); it.hasNext();) {
     127                Pair<OsmPrimitive, Date> pair = it.next();
     128                History history = source.getHistory(pair.a.getPrimitiveId());
     129                // If the history has been loaded and a timestamp is known
     130                if (history != null && pair.b != null) {
     131                    // Lookup for the primitive version at the specified timestamp
     132                    HistoryOsmPrimitive hp = history.getByDate(pair.b);
     133                    if (hp != null) {
     134                        PrimitiveData data = null;
     135                       
     136                        switch (pair.a.getType()) {
     137                            case NODE:
     138                                data = new NodeData();
     139                                ((NodeData)data).setCoor(((HistoryNode)hp).getCoords());
     140                                break;
     141                            case WAY:
     142                                data = new WayData();
     143                                ((WayData)data).setNodes(((HistoryWay)hp).getNodes());
     144                                break;
     145                            case RELATION:
     146                                data = new RelationData();
     147                                ((RelationData)data).setMembers(((HistoryRelation)hp).getMembers());
     148                                break;
     149                            default: throw new AssertionError();
     150                        }
     151                       
     152                        data.setUser(hp.getUser());
     153                        data.setVisible(hp.isVisible());
     154                        data.setTimestamp(hp.getTimestamp());
     155                        data.setKeys(hp.getTags());
     156                        data.setOsmId(hp.getChangesetId(), (int) hp.getVersion());
     157                       
     158                        // Load the history data
     159                        pair.a.load(data);
     160                        // Forget this primitive
     161                        it.remove();
     162                    }
     163                }
     164            }
     165            if (toMonitor.isEmpty()) {
     166                // No more primitive to update. Processing is finished
     167                source.removeHistoryDataSetListener(this);
     168                // Be sure all updated primitives are correctly drawn
     169                Main.map.repaint();
     170            }
     171        }
     172
     173        @Override
     174        public void historyDataSetCleared(HistoryDataSet source) {
    70175        }
    71176    }
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java

    r4602 r4734  
    1010import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1111import org.openstreetmap.josm.data.osm.Relation;
     12import org.openstreetmap.josm.data.osm.RelationMemberData;
    1213import org.openstreetmap.josm.data.osm.User;
    1314import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    2021public class HistoryRelation extends HistoryOsmPrimitive{
    2122
    22     private ArrayList<RelationMember> members = new ArrayList<RelationMember>();
     23    private ArrayList<RelationMemberData> members = new ArrayList<RelationMemberData>();
    2324
    2425    /**
     
    5455     */
    5556    public HistoryRelation(long id, long version, boolean visible, User user, long changesetId,
    56             Date timestamp, ArrayList<RelationMember> members) {
     57            Date timestamp, ArrayList<RelationMemberData> members) {
    5758        this(id, version, visible, user, changesetId, timestamp);
    5859        if (members != null) {
     
    7071     * @return an immutable list of members of this relation
    7172     */
    72     public List<RelationMember> getMembers() {
     73    public List<RelationMemberData> getMembers() {
    7374        return Collections.unmodifiableList(members);
    7475    }
     
    9091     * @throws IndexOutOfBoundsException thrown, if idx is out of bounds
    9192     */
    92     public RelationMember getRelationMember(int idx) throws IndexOutOfBoundsException  {
     93    public RelationMemberData getRelationMember(int idx) throws IndexOutOfBoundsException  {
    9394        if (idx < 0 || idx >= members.size())
    9495            throw new IndexOutOfBoundsException(MessageFormat.format("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", members.size(),idx));
     
    111112     * @exception IllegalArgumentException thrown, if member is null
    112113     */
    113     public void addMember(RelationMember member) throws IllegalArgumentException {
     114    public void addMember(RelationMemberData member) throws IllegalArgumentException {
    114115        CheckParameterUtil.ensureParameterNotNull(member, "member");
    115116        members.add(member);
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r4689 r4734  
    1818import org.openstreetmap.josm.data.osm.Relation;
    1919import org.openstreetmap.josm.data.osm.RelationMember;
     20import org.openstreetmap.josm.data.osm.RelationMemberData;
    2021import org.openstreetmap.josm.data.osm.User;
    2122import org.openstreetmap.josm.data.osm.Way;
     
    4243import org.openstreetmap.josm.io.XmlWriter;
    4344import org.openstreetmap.josm.tools.CheckParameterUtil;
    44 import org.openstreetmap.josm.tools.Diff;
    4545
    4646/**
     
    721721                return false;
    722722            return
    723             thisRelation.getMembers().get(row).getPrimitiveId() == oppositeRelation.getMembers().get(row).getPrimitiveId()
     723            thisRelation.getMembers().get(row).getMemberId() == oppositeRelation.getMembers().get(row).getMemberId()
    724724            &&  thisRelation.getMembers().get(row).getRole().equals(oppositeRelation.getMembers().get(row).getRole());
    725725        }
     
    881881            HistoryRelation hr = (HistoryRelation)clone;
    882882            for (RelationMember rm : r.getMembers()) {
    883                 hr.addMember(new org.openstreetmap.josm.data.osm.history.RelationMember(rm.getRole(), rm.getType(), rm.getUniqueId()));
     883                hr.addMember(new RelationMemberData(rm.getRole(), rm.getType(), rm.getUniqueId()));
    884884            }
    885885        }
  • trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListTableCellRenderer.java

    r4566 r4734  
    1414
    1515import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    16 import org.openstreetmap.josm.data.osm.history.RelationMember;
     16import org.openstreetmap.josm.data.osm.RelationMemberData;
    1717import org.openstreetmap.josm.tools.ImageProvider;
    1818
     
    3939    }
    4040
    41     protected void renderIcon(RelationMember member) {
     41    protected void renderIcon(RelationMemberData member) {
    4242        if (member == null) {
    4343            setIcon(null);
    4444        } else {
    45             setIcon(icons.get(member.getPrimitiveType()));
     45            setIcon(icons.get(member.getMemberType()));
    4646        }
    4747    }
    4848
    49     protected void renderRole( HistoryBrowserModel.RelationMemberTableModel model, RelationMember member, int row, boolean isSelected) {
     49    protected void renderRole( HistoryBrowserModel.RelationMemberTableModel model, RelationMemberData member, int row, boolean isSelected) {
    5050        String text = "";
    5151        Color bgColor = Color.WHITE;
     
    6767    }
    6868
    69     protected void renderPrimitive( HistoryBrowserModel.RelationMemberTableModel model, RelationMember member, int row, boolean isSelected) {
     69    protected void renderPrimitive( HistoryBrowserModel.RelationMemberTableModel model, RelationMemberData member, int row, boolean isSelected) {
    7070        String text = "";
    7171        Color bgColor = Color.WHITE;
     
    7474        } else {
    7575            text = "";
    76             switch(member.getPrimitiveType()) {
    77             case NODE: text = tr("Node {0}", member.getPrimitiveId()); break;
    78             case WAY: text = tr("Way {0}", member.getPrimitiveId()); break;
    79             case RELATION: text = tr("Relation {0}", member.getPrimitiveId()); break;
     76            switch(member.getMemberType()) {
     77            case NODE: text = tr("Node {0}", member.getMemberId()); break;
     78            case WAY: text = tr("Way {0}", member.getMemberId()); break;
     79            case RELATION: text = tr("Relation {0}", member.getMemberId()); break;
    8080            }
    8181            if (model.isSameInOppositeWay(row)) {
     
    9797
    9898        HistoryBrowserModel.RelationMemberTableModel model = gteRelationMemberTableModel(table);
    99         RelationMember member = (RelationMember)value;
     99        RelationMemberData member = (RelationMemberData)value;
    100100        renderIcon(member);
    101101        switch(column) {
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java

    r4602 r4734  
    1717import org.openstreetmap.josm.data.osm.ChangesetDataSet;
    1818import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     19import org.openstreetmap.josm.data.osm.RelationMemberData;
    1920import org.openstreetmap.josm.data.osm.User;
    2021import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType;
     
    209210            }
    210211            String role = getMandatoryAttributeString(atts, "role");
    211             org.openstreetmap.josm.data.osm.history.RelationMember member = new org.openstreetmap.josm.data.osm.history.RelationMember(role, type,ref);
     212            RelationMemberData member = new RelationMemberData(role, type,ref);
    212213            ((HistoryRelation)currentPrimitive).addMember(member);
    213214        }
  • trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java

    r4602 r4734  
    1414import org.openstreetmap.josm.data.coor.LatLon;
    1515import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     16import org.openstreetmap.josm.data.osm.RelationMemberData;
    1617import org.openstreetmap.josm.data.osm.User;
    1718import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
     
    203204            }
    204205            String role = getMandatoryAttributeString(atts, "role");
    205             org.openstreetmap.josm.data.osm.history.RelationMember member = new org.openstreetmap.josm.data.osm.history.RelationMember(role, type,ref);
     206            RelationMemberData member = new RelationMemberData(role, type,ref);
    206207            ((HistoryRelation)current).addMember(member);
    207208        }
  • trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java

    r3083 r4734  
    2222 * It can either download the object including or not including its immediate children.
    2323 * The former case is called a "full download".
     24 *
     25 * It can also download a specific version of the object (however, "full" download is not possible
     26 * in that case).
    2427 *
    2528 */
     
    2932    /** true if a full download is required, i.e. a download including the immediate children */
    3033    private boolean full;
     34    /** the specific version number, if required (incompatible with full), or -1 else */
     35    private int version;
    3136
    3237    /**
     
    4146     */
    4247    public OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full) throws IllegalArgumentException {
     48        this(id, type, full, -1);
     49    }
     50
     51    /**
     52     * Creates a new server object reader for a given id and a primitive type.
     53     *
     54     * @param id the object id. > 0 required.
     55     * @param type the type. Must not be null.
     56     * @param version the specific version number, if required; -1, otherwise
     57     * @throws IllegalArgumentException thrown if id <= 0
     58     * @throws IllegalArgumentException thrown if type is null
     59     */
     60    public OsmServerObjectReader(long id, OsmPrimitiveType type, int version) throws IllegalArgumentException {
     61        this(id, type, false, version);
     62    }
     63
     64    protected OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full, int version) throws IllegalArgumentException {
    4365        if (id <= 0)
    4466            throw new IllegalArgumentException(MessageFormat.format("Expected value > 0 for parameter ''{0}'', got {1}", "id", id));
     
    4668        this.id = new SimplePrimitiveId(id, type);
    4769        this.full = full;
     70        this.version = version;
    4871    }
    4972
     
    5881     */
    5982    public OsmServerObjectReader(PrimitiveId id, boolean full) {
     83        this(id, full, -1);
     84    }
     85
     86    /**
     87     * Creates a new server object reader for an object with the given <code>id</code>
     88     *
     89     * @param id the object id. Must not be null. Unique id > 0 required.
     90     * @param version the specific version number, if required; -1, otherwise
     91     * @throws IllegalArgumentException thrown if id is null
     92     * @throws IllegalArgumentException thrown if id.getUniqueId() <= 0
     93     */
     94    public OsmServerObjectReader(PrimitiveId id, int version) {
     95        this(id, false, version);
     96    }
     97
     98    protected OsmServerObjectReader(PrimitiveId id, boolean full, int version) {
    6099        CheckParameterUtil.ensureValidPrimitiveId(id, "id");
    61100        this.id = id;
    62101        this.full = full;
     102        this.version = version;
    63103    }
    64104
     
    87127            if (full && ! id.getType().equals(OsmPrimitiveType.NODE)) {
    88128                sb.append("/full");
     129            } else if (version > 0) {
     130                sb.append("/"+version);
    89131            }
    90132
Note: See TracChangeset for help on using the changeset viewer.