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