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