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

Last change on this file since 8444 was 8444, checked in by Don-vip, 9 years ago

remove extra whitespaces

  • Property svn:eol-style set to native
File size: 2.8 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.conflict.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 * @throws IllegalArgumentException if my is null
30 * @throws IllegalArgumentException 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<>(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 conflict the conflict data set
55 * @return the command
56 * @throws IllegalStateException if the merge is not yet frozen
57 */
58 public WayNodesConflictResolverCommand buildResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
59 if (!isFrozen())
60 throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Cannot build resolution command."));
61 return new WayNodesConflictResolverCommand(conflict, getMergedEntries());
62 }
63
64 @Override
65 public boolean isEqualEntry(Node e1, Node e2) {
66 if (!e1.isNew())
67 return e1.getId() == e2.getId();
68 else
69 return e1 == e2;
70 }
71
72 @Override
73 protected void setValueAt(DefaultTableModel model, Object value, int row, int col) {
74 // do nothing - node list tables are not editable
75 }
76
77 @Override
78 protected Node cloneEntryForMergedList(Node entry) {
79 return (Node) getMyPrimitive(entry);
80 }
81}
Note: See TracBrowser for help on using the repository browser.