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

Last change on this file since 3083 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 3.2 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;
7
8import javax.swing.table.DefaultTableModel;
9
10import org.openstreetmap.josm.command.WayNodesConflictResolverCommand;
11import org.openstreetmap.josm.data.conflict.Conflict;
12import org.openstreetmap.josm.data.osm.DataSet;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.Way;
16import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
17import org.openstreetmap.josm.gui.conflict.pair.ListRole;
18import org.openstreetmap.josm.tools.CheckParameterUtil;
19
20public 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}
Note: See TracBrowser for help on using the repository browser.