source: josm/trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java@ 1750

Last change on this file since 1750 was 1750, checked in by Gubaer, 15 years ago

new: replaced global conflict list by conflict list per layer, similar to datasets

File size: 2.2 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.Main;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.Relation;
15import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
16
17/**
18 * Command that changes the role of a relation member
19 *
20 * @author Teemu Koskinen <teemu.koskinen@mbnet.fi>
21 */
22public class ChangeRelationMemberRoleCommand extends Command {
23
24 // The relation to be changed
25 private final Relation relation;
26 // Position of the member
27 private int position = -1;
28 // The new role
29 private final String newRole;
30 // The old role
31 private String oldRole;
32 // Old value of modified;
33 private Boolean oldModified;
34
35 public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) {
36 super();
37 this.relation = relation;
38 this.position = position;
39 this.newRole = newRole;
40 }
41
42 @Override public boolean executeCommand() {
43 if (position < 0 || position >= relation.members.size()) {
44 Main.debug("error changing the role");
45 return false;
46 }
47
48 oldRole = relation.members.get(position).role;
49 relation.members.get(position).role = newRole;
50
51 oldModified = relation.modified;
52 relation.modified = true;
53 return true;
54 }
55
56 @Override public void undoCommand() {
57 relation.members.get(position).role = oldRole;
58 relation.modified = oldModified;
59 }
60
61 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
62 modified.add(relation);
63 }
64
65 @Override public MutableTreeNode description() {
66 NameVisitor v = new NameVisitor();
67 relation.visit(v);
68 return new DefaultMutableTreeNode(new JLabel(tr("ChangeRelationMemberRole {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
69 }
70}
Note: See TracBrowser for help on using the repository browser.