source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMergeModel.java@ 5299

Last change on this file since 5299 was 5298, checked in by Don-vip, 12 years ago

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

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.conflict.pair.nodes;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.Map;
8
9import javax.swing.table.DefaultTableModel;
10
11import org.openstreetmap.josm.command.WayNodesConflictResolverCommand;
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.PrimitiveId;
16import org.openstreetmap.josm.data.osm.Way;
17import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
18import org.openstreetmap.josm.gui.conflict.pair.ListRole;
19
20public class NodeListMergeModel extends ListMergeModel<Node>{
21
22 /**
23 * Populates the model with the nodes in the two {@link Way}s <code>my</code> and
24 * <code>their</code>.
25 *
26 * @param my my way (i.e. the way in the local dataset)
27 * @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
29 * @exception IllegalArgumentException thrown, if my is null
30 * @exception IllegalArgumentException thrown, if their is null
31 */
32 public void populate(Way my, Way their, Map<PrimitiveId, PrimitiveId> mergedMap) {
33 initPopulate(my, their, mergedMap);
34
35 for (Node n : my.getNodes()) {
36 getMyEntries().add(n);
37 }
38 for (Node n : their.getNodes()) {
39 getTheirEntries().add(n);
40 }
41 if (myAndTheirEntriesEqual()) {
42 entries.put(ListRole.MERGED_ENTRIES, new ArrayList<Node>(getMyEntries()));
43 setFrozen(true);
44 } else {
45 setFrozen(false);
46 }
47
48 fireModelDataChanged();
49 }
50
51 /**
52 * Builds the command to resolve conflicts in the node list of a way
53 *
54 * @param my my way. Must not be null.
55 * @param their their way. Must not be null
56 * @return the command
57 * @exception IllegalStateException thrown, if the merge is not yet frozen
58 */
59 public WayNodesConflictResolverCommand buildResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
60 if (! isFrozen())
61 throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Cannot build resolution command."));
62 return new WayNodesConflictResolverCommand(conflict, getMergedEntries());
63 }
64
65 @Override
66 public boolean isEqualEntry(Node e1, Node e2) {
67 if (!e1.isNew())
68 return e1.getId() == e2.getId();
69 else
70 return e1 == e2;
71 }
72
73 @Override
74 protected void setValueAt(DefaultTableModel model, Object value, int row, int col) {
75 // do nothing - node list tables are not editable
76 }
77
78 @Override
79 protected Node cloneEntryForMergedList(Node entry) {
80 return (Node) getMyPrimitive(entry);
81 }
82}
Note: See TracBrowser for help on using the repository browser.