source: josm/trunk/src/org/openstreetmap/josm/command/DeleteCommand.java@ 343

Last change on this file since 343 was 343, checked in by gebner, 17 years ago

Merge 0.5.

File size: 2.0 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trn;
6
7import java.util.Collection;
8
9import javax.swing.JLabel;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13import org.openstreetmap.josm.data.osm.Relation;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18/**
19 * A command to delete a number of primitives from the dataset.
20 * @author imi
21 */
22public 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}
Note: See TracBrowser for help on using the repository browser.