Changeset 5298 in josm for trunk/src


Ignore:
Timestamp:
2012-06-24T21:02:36+02:00 (8 years ago)
Author:
Don-vip
Message:

see #4899, see #7266, see #7333: Resolved NPE in conflict manager when copying a member created by merging two layers

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/conflict/Conflict.java

    r5266 r5298  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.conflict;
     3
     4import java.util.Map;
    35
    46import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2224    private final T their;
    2325    private final boolean isMyDeleted;
     26   
     27    // mergedMap is only set if the conflict results from merging two layers
     28    private Map<PrimitiveId, PrimitiveId> mergedMap;
    2429
    2530    public Conflict(T my, T their) {
     
    111116        return isMyDeleted;
    112117    }
     118
     119    public final Map<PrimitiveId, PrimitiveId> getMergedMap() {
     120        return mergedMap;
     121    }
     122
     123    public final void setMergedMap(Map<PrimitiveId, PrimitiveId> mergedMap) {
     124        this.mergedMap = mergedMap;
     125    }
    113126}
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r5266 r5298  
    134134            return null;
    135135        return targetDataSet.getPrimitiveById(targetId);
     136    }
     137   
     138    protected void addConflict(Conflict<?> c) {
     139        c.setMergedMap(mergedMap);
     140        conflicts.add(c);
     141    }
     142
     143    protected void addConflict(OsmPrimitive my, OsmPrimitive their) {
     144        addConflict(new Conflict<OsmPrimitive>(my, their));
    136145    }
    137146
     
    188197                        // add a conflict and don't delete the object
    189198                        if (!objectsToDelete.contains(referrer)) {
    190                             conflicts.add(target, source);
     199                            addConflict(target, source);
    191200                            it.remove();
    192201                            flag = true;
     
    235244                newNodes.add(targetNode);
    236245                if (targetNode.isDeleted() && !conflicts.hasConflictForMy(targetNode)) {
    237                     conflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true));
     246                    addConflict(new Conflict<OsmPrimitive>(targetNode, sourceNode, true));
    238247                    targetNode.setDeleted(false);
    239248                }
     
    263272            newMembers.add(newMember);
    264273            if (targetMember.isDeleted() && !conflicts.hasConflictForMy(targetMember)) {
    265                 conflicts.add(new Conflict<OsmPrimitive>(targetMember, sourceMember.getMember(), true));
     274                addConflict(new Conflict<OsmPrimitive>(targetMember, sourceMember.getMember(), true));
    266275                targetMember.setDeleted(false);
    267276            }
     
    317326            for (OsmPrimitive referrer: source.getReferrers()) {
    318327                if (targetDataSet.getPrimitiveById(referrer.getPrimitiveId()) == null) {
    319                     conflicts.add(new Conflict<OsmPrimitive>(target, source, true));
     328                    addConflict(new Conflict<OsmPrimitive>(target, source, true));
    320329                    target.setDeleted(false);
    321330                    break;
     
    352361            // this have to be resolved manually.
    353362            //
    354             conflicts.add(target,source);
     363            addConflict(target,source);
    355364        } else if (! target.hasEqualSemanticAttributes(source)) {
    356365            // target is modified and is not semantically equal with source. Can't automatically
    357366            // resolve the differences
    358367            // =>  create a conflict
    359             conflicts.add(target,source);
     368            addConflict(target,source);
    360369        } else {
    361370            // clone from other. mergeFrom will mainly copy
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMergeModel.java

    r5297 r5298  
    1515import java.util.HashMap;
    1616import java.util.List;
     17import java.util.Map;
    1718import java.util.Observable;
    1819
     
    2122import javax.swing.DefaultListSelectionModel;
    2223import javax.swing.JOptionPane;
     24import javax.swing.JTable;
     25import javax.swing.ListSelectionModel;
    2326import javax.swing.table.DefaultTableModel;
    2427import javax.swing.table.TableModel;
    2528
    2629import org.openstreetmap.josm.Main;
     30import org.openstreetmap.josm.data.osm.DataSet;
    2731import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2832import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    3034import org.openstreetmap.josm.gui.help.HelpUtil;
    3135import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel;
     36import org.openstreetmap.josm.tools.CheckParameterUtil;
    3237
    3338/**
     
    6368 * @see ListMerger
    6469 */
    65 public abstract class ListMergeModel<T> extends Observable {
     70public abstract class ListMergeModel<T extends PrimitiveId> extends Observable {
    6671    public static final String FROZEN_PROP = ListMergeModel.class.getName() + ".frozen";
    6772
     
    8186    private boolean isFrozen = false;
    8287    private final ComparePairListModel comparePairListModel;
     88   
     89    private DataSet myDataset;
     90    private Map<PrimitiveId, PrimitiveId> mergedMap;
    8391
    8492    /**
     
    118126     * @return Primitive from my dataset referenced by entry
    119127     */
    120     protected abstract OsmPrimitive getMyPrimitive(T entry);
     128    protected OsmPrimitive getMyPrimitive(T entry) {
     129        return getMyPrimitiveDefault(entry);
     130    }
     131   
     132    protected final OsmPrimitive getMyPrimitiveDefault(PrimitiveId entry) {
     133        OsmPrimitive result = myDataset.getPrimitiveById(entry);
     134        if (result == null && mergedMap != null) {
     135            PrimitiveId id = mergedMap.get(entry);
     136            if (id == null && entry instanceof OsmPrimitive) {
     137                id = mergedMap.get(((OsmPrimitive)entry).getPrimitiveId());
     138            }
     139            if (id != null) {
     140                result = myDataset.getPrimitiveById(id);
     141            }
     142        }
     143        return result;
     144    }
    121145
    122146    protected void buildMyEntriesTableModel() {
     
    310334        getMergedEntries().clear();
    311335        fireModelDataChanged();
     336    }
     337   
     338    protected final void initPopulate(OsmPrimitive my, OsmPrimitive their, Map<PrimitiveId, PrimitiveId> mergedMap) {
     339        CheckParameterUtil.ensureParameterNotNull(my, "my");
     340        CheckParameterUtil.ensureParameterNotNull(their, "their");
     341        this.myDataset = my.getDataSet();
     342        this.mergedMap = mergedMap;
     343        getMergedEntries().clear();
     344        getMyEntries().clear();
     345        getTheirEntries().clear();
    312346    }
    313347
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMerger.java

    r5297 r5298  
    3636import javax.swing.event.ListSelectionListener;
    3737
     38import org.openstreetmap.josm.data.osm.PrimitiveId;
    3839import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTable;
    3940import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    4647 * @see ListMergeModel
    4748 */
    48 public abstract class ListMerger<T> extends JPanel implements PropertyChangeListener, Observer {
     49public abstract class ListMerger<T extends PrimitiveId> extends JPanel implements PropertyChangeListener, Observer {
    4950    protected OsmPrimitivesTable myEntriesTable;
    5051    protected OsmPrimitivesTable mergedEntriesTable;
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMergeModel.java

    r5266 r5298  
    55
    66import java.util.ArrayList;
     7import java.util.Map;
    78
    89import javax.swing.table.DefaultTableModel;
     
    1011import org.openstreetmap.josm.command.WayNodesConflictResolverCommand;
    1112import org.openstreetmap.josm.data.conflict.Conflict;
    12 import org.openstreetmap.josm.data.osm.DataSet;
    1313import org.openstreetmap.josm.data.osm.Node;
    1414import org.openstreetmap.josm.data.osm.OsmPrimitive;
     15import org.openstreetmap.josm.data.osm.PrimitiveId;
    1516import org.openstreetmap.josm.data.osm.Way;
    1617import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
    1718import org.openstreetmap.josm.gui.conflict.pair.ListRole;
    18 import org.openstreetmap.josm.tools.CheckParameterUtil;
    1919
    2020public class NodeListMergeModel extends ListMergeModel<Node>{
    21     private DataSet myDataset;
    2221
    2322    /**
     
    2726     * @param my  my way (i.e. the way in the local dataset)
    2827     * @param their their way (i.e. the way in the server dataset)
     28     * @param mergedMap The map of merged primitives if the conflict results from merging two layers
    2929     * @exception IllegalArgumentException thrown, if my is null
    3030     * @exception IllegalArgumentException  thrown, if their is null
    3131     */
    32     public void populate(Way my, Way their) {
    33         this.myDataset = my.getDataSet();
     32    public void populate(Way my, Way their, Map<PrimitiveId, PrimitiveId> mergedMap) {
     33        initPopulate(my, their, mergedMap);
    3434
    35         CheckParameterUtil.ensureParameterNotNull(my, "my");
    36         CheckParameterUtil.ensureParameterNotNull(their, "their");
    37         getMergedEntries().clear();
    38         getMyEntries().clear();
    39         getTheirEntries().clear();
    4035        for (Node n : my.getNodes()) {
    4136            getMyEntries().add(n);
     
    8580        return (Node) getMyPrimitive(entry);
    8681    }
    87 
    88     @Override
    89     protected OsmPrimitive getMyPrimitive(Node entry) {
    90         return myDataset.getPrimitiveById(entry);
    91     }
    92 
    9382}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMerger.java

    r5297 r5298  
    5757        Way myWay = (Way)conflict.getMy();
    5858        Way theirWay = (Way)conflict.getTheir();
    59         ((NodeListMergeModel)model).populate(myWay, theirWay);
     59        ((NodeListMergeModel)model).populate(myWay, theirWay, conflict.getMergedMap());
    6060        myEntriesTable.setLayer(findLayerFor(myWay));
    6161        theirEntriesTable.setLayer(findLayerFor(theirWay));
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberListMergeModel.java

    r4191 r5298  
    55
    66import java.util.List;
     7import java.util.Map;
    78
    89import javax.swing.table.DefaultTableModel;
    910
    1011import org.openstreetmap.josm.command.RelationMemberConflictResolverCommand;
    11 import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
     13import org.openstreetmap.josm.data.osm.PrimitiveId;
    1314import org.openstreetmap.josm.data.osm.Relation;
    1415import org.openstreetmap.josm.data.osm.RelationMember;
     
    2122 */
    2223public class RelationMemberListMergeModel extends ListMergeModel<RelationMember>{
    23     private DataSet myDataset;
    2424
    2525    @Override
     
    6060     * @param my my relation. Must not be null.
    6161     * @param their their relation. Must not be null.
     62     * @param mergedMap The map of merged primitives if the conflict results from merging two layers
    6263     *
    6364     * @throws IllegalArgumentException if my is null
    6465     * @throws IllegalArgumentException if their is null
    6566     */
    66     public void populate(Relation my, Relation their) {
    67         this.myDataset = my.getDataSet();
    68 
    69         CheckParameterUtil.ensureParameterNotNull(my, "my");
    70         CheckParameterUtil.ensureParameterNotNull(their, "their");
    71 
    72         getMergedEntries().clear();
    73         getMyEntries().clear();
    74         getTheirEntries().clear();
     67    public void populate(Relation my, Relation their, Map<PrimitiveId, PrimitiveId> mergedMap) {
     68        initPopulate(my, their, mergedMap);
    7569
    7670        for (RelationMember n : my.getMembers()) {
     
    9488    @Override
    9589    protected RelationMember cloneEntryForMergedList(RelationMember entry) {
    96         OsmPrimitive primitive = getMyPrimitive(entry);
    97         return new RelationMember(entry.getRole(), primitive);
     90        return new RelationMember(entry.getRole(), getMyPrimitive(entry));
    9891    }
    9992
    10093    @Override
    10194    protected OsmPrimitive getMyPrimitive(RelationMember entry) {
    102         return myDataset.getPrimitiveById(entry.getMember());
     95        return getMyPrimitiveDefault(entry.getMember());
    10396    }
    10497
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberMerger.java

    r5297 r5298  
    4848    public void populate(Conflict<? extends OsmPrimitive> conflict) {
    4949        RelationMemberListMergeModel model = (RelationMemberListMergeModel)getModel();
    50         model.populate((Relation)conflict.getMy(), (Relation)conflict.getTheir());
     50        model.populate((Relation)conflict.getMy(), (Relation)conflict.getTheir(), conflict.getMergedMap());
    5151    }
    5252
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r5297 r5298  
    705705        @Override
    706706        public void updateEnabledState() {
    707             GuiHelper.runInEDT(new Runnable() {
     707            GuiHelper.runInEDTAndWait(new Runnable() {
    708708                @Override
    709709                public void run() {
Note: See TracChangeset for help on using the changeset viewer.