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

Last change on this file since 6883 was 6881, checked in by Don-vip, 10 years ago

javadoc/code style/minor refactorization

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