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

Last change on this file since 2846 was 2846, checked in by mjulius, 14 years ago

fix messages for gui/conflict

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;
7import java.util.logging.Logger;
8
9import javax.swing.table.DefaultTableModel;
10
11import org.openstreetmap.josm.command.WayNodesConflictResolverCommand;
12import org.openstreetmap.josm.data.osm.Node;
13import org.openstreetmap.josm.data.osm.Way;
14import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
15import org.openstreetmap.josm.gui.conflict.pair.ListRole;
16import org.openstreetmap.josm.tools.CheckParameterUtil;
17
18public class NodeListMergeModel extends ListMergeModel<Node>{
19
20 private static final Logger logger = Logger.getLogger(NodeListMergeModel.class.getName());
21
22 /**
23 * Populates the model with the nodes in the two {@see 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 * @exception IllegalArgumentException thrown, if my is null
29 * @exception IllegalArgumentException thrown, if their is null
30 */
31 public void populate(Way my, Way their) {
32 CheckParameterUtil.ensureParameterNotNull(my, "my");
33 CheckParameterUtil.ensureParameterNotNull(their, "their");
34 getMergedEntries().clear();
35 getMyEntries().clear();
36 getTheirEntries().clear();
37 for (Node n : my.getNodes()) {
38 getMyEntries().add(n);
39 }
40 for (Node n : their.getNodes()) {
41 getTheirEntries().add(n);
42 }
43 if (myAndTheirEntriesEqual()) {
44 entries.put(ListRole.MERGED_ENTRIES, new ArrayList<Node>(getMyEntries()));
45 setFrozen(true);
46 } else {
47 setFrozen(false);
48 }
49
50 fireModelDataChanged();
51 }
52
53 /**
54 * Builds the command to resolve conflicts in the node list of a way
55 *
56 * @param my my way. Must not be null.
57 * @param their their way. Must not be null
58 * @return the command
59 * @exception IllegalArgumentException thrown, if my is null or not a {@see Way}
60 * @exception IllegalArgumentException thrown, if their is null or not a {@see Way}
61 * @exception IllegalStateException thrown, if the merge is not yet frozen
62 */
63 public WayNodesConflictResolverCommand buildResolveCommand(Way my, Way their) {
64 CheckParameterUtil.ensureParameterNotNull(my, "my");
65 CheckParameterUtil.ensureParameterNotNull(their, "their");
66 if (! isFrozen())
67 throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Cannot build resolution command."));
68 return new WayNodesConflictResolverCommand(my, their, getMergedEntries());
69 }
70
71 @Override
72 public boolean isEqualEntry(Node e1, Node e2) {
73 if (!e1.isNew())
74 return e1.getId() == e2.getId();
75 else
76 return e1 == e2;
77 }
78
79 @Override
80 protected void setValueAt(DefaultTableModel model, Object value, int row, int col) {
81 // do nothing - node list tables are not editable
82 }
83
84 @Override
85 protected Node cloneEntryForMergedList(Node entry) {
86 return entry;
87 }
88}
Note: See TracBrowser for help on using the repository browser.