1 | package org.openstreetmap.josm.command;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 |
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
10 | import javax.swing.tree.MutableTreeNode;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * A command to delete a number of primitives from the dataset.
|
---|
18 | * @author imi
|
---|
19 | */
|
---|
20 | public class DeleteCommand extends Command {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * The primitive that get deleted.
|
---|
24 | */
|
---|
25 | private final Collection<OsmPrimitive> data;
|
---|
26 |
|
---|
27 | public DeleteCommand(Collection<OsmPrimitive> data) {
|
---|
28 | this.data = data;
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override public void executeCommand() {
|
---|
32 | super.executeCommand();
|
---|
33 | for (OsmPrimitive osm : data)
|
---|
34 | osm.delete(true);
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
38 | deleted.addAll(data);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override public MutableTreeNode description() {
|
---|
42 | NameVisitor v = new NameVisitor();
|
---|
43 |
|
---|
44 | if (data.size() == 1) {
|
---|
45 | data.iterator().next().visit(v);
|
---|
46 | return new DefaultMutableTreeNode(new JLabel(tr("Delete")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
|
---|
47 | }
|
---|
48 |
|
---|
49 | String cname = null;
|
---|
50 | for (OsmPrimitive osm : data) {
|
---|
51 | osm.visit(v);
|
---|
52 | if (cname == null)
|
---|
53 | cname = v.className;
|
---|
54 | else if (!cname.equals(v.className))
|
---|
55 | cname = "object";
|
---|
56 | }
|
---|
57 | DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(
|
---|
58 | tr("Delete")+" "+data.size()+" "+trn(cname, cname+"s", data.size()), ImageProvider.get("data", cname), JLabel.HORIZONTAL));
|
---|
59 | for (OsmPrimitive osm : data) {
|
---|
60 | osm.visit(v);
|
---|
61 | root.add(new DefaultMutableTreeNode(v.toLabel()));
|
---|
62 | }
|
---|
63 | return root;
|
---|
64 | }
|
---|
65 | }
|
---|