source: josm/trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.java@ 3186

Last change on this file since 3186 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.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7
8import javax.swing.JLabel;
9import javax.swing.tree.DefaultMutableTreeNode;
10import javax.swing.tree.MutableTreeNode;
11
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
15import org.openstreetmap.josm.gui.layer.OsmDataLayer;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18/**
19 * Represents a the resolution of a conflict between the coordinates of two {@see Node}s
20 *
21 */
22public class DeletedStateConflictResolveCommand extends ConflictResolveCommand {
23
24 /** the conflict to resolve */
25 private Conflict<? extends OsmPrimitive> conflict;
26
27 /** the merge decision */
28 private final MergeDecisionType decision;
29
30 /**
31 * constructor
32 *
33 * @param my my node
34 * @param their their node
35 * @param decision the merge decision
36 */
37 public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
38 this.conflict = conflict;
39 this.decision = decision;
40 }
41
42 @Override
43 public MutableTreeNode description() {
44 return new DefaultMutableTreeNode(
45 new JLabel(
46 tr("Resolve conflicts in deleted state in {0}",conflict.getMy().getId()),
47 ImageProvider.get("data", "object"),
48 JLabel.HORIZONTAL
49 )
50 );
51 }
52
53 @Override
54 public boolean executeCommand() {
55 // remember the current state of modified primitives, i.e. of
56 // OSM primitive 'my'
57 //
58 super.executeCommand();
59
60 OsmDataLayer layer = getLayer();
61
62 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
63 if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) {
64 // because my was involved in a conflict it my still be referred
65 // to from a way or a relation. Fix this now.
66 //
67 layer.data.unlinkReferencesToPrimitive(conflict.getMy());
68 conflict.getMy().setDeleted(true);
69 }
70 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
71 if (conflict.getTheir().isDeleted()) {
72 layer.data.unlinkReferencesToPrimitive(conflict.getMy());
73 conflict.getMy().setDeleted(true);
74 } else {
75 conflict.getMy().setDeleted(false);
76 }
77 } else
78 // should not happen
79 throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
80
81 rememberConflict(conflict);
82 return true;
83 }
84
85 @Override
86 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
87 Collection<OsmPrimitive> added) {
88 modified.add(conflict.getMy());
89 modified.addAll(conflict.getMy().getReferrers());
90 }
91}
Note: See TracBrowser for help on using the repository browser.