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

Last change on this file since 755 was 755, checked in by stoecker, 16 years ago

better sorting of selected elements and relation list, reenabled relation search, translation cleanups

  • Property svn:eol-style set to native
File size: 2.3 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;
8import java.util.Collections;
9
10import javax.swing.JLabel;
11import javax.swing.tree.DefaultMutableTreeNode;
12import javax.swing.tree.MutableTreeNode;
13
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 /**
30 * Constructor for a collection of data
31 */
32 public DeleteCommand(Collection<? extends OsmPrimitive> data) {
33 this.data = data;
34 }
35 /**
36 * Constructor for a single data item. Use the collection
37 * constructor to delete multiple objects.
38 */
39 public DeleteCommand(OsmPrimitive data) {
40 this.data = Collections.singleton(data);
41 }
42
43 @Override public boolean executeCommand() {
44 super.executeCommand();
45 for (OsmPrimitive osm : data) {
46 osm.delete(true);
47 }
48 return true;
49 }
50
51 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
52 deleted.addAll(data);
53 }
54
55 @Override public MutableTreeNode description() {
56 NameVisitor v = new NameVisitor();
57
58 if (data.size() == 1) {
59 data.iterator().next().visit(v);
60 return new DefaultMutableTreeNode(new JLabel(tr("Delete {1} {0}", v.name, tr(v.className)), v.icon, JLabel.HORIZONTAL));
61 }
62
63 String cname = null;
64 String cnamem = null;
65 for (OsmPrimitive osm : data) {
66 osm.visit(v);
67 if (cname == null)
68 {
69 cname = v.className;
70 cnamem = v.classNamePlural;
71 }
72 else if (!cname.equals(v.className))
73 {
74 cname = "object";
75 cnamem = trn("object", "objects", 2);
76 }
77 }
78 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(
79 tr("Delete {0} {1}", data.size(), trn(cname, cnamem, data.size())), ImageProvider.get("data", cname), JLabel.HORIZONTAL));
80 for (OsmPrimitive osm : data) {
81 osm.visit(v);
82 root.add(new DefaultMutableTreeNode(v.toLabel()));
83 }
84 return root;
85 }
86}
Note: See TracBrowser for help on using the repository browser.