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

Last change on this file since 630 was 630, checked in by framm, 16 years ago
  • make commands able to fail (patch by DH)
  • add Command.getOrig() (patch by DH)
  • add RemoveRelationMemberCommand (patch by DH)
  • Property svn:eol-style set to native
File size: 2.2 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")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
61 }
62
63 String cname = null;
64 for (OsmPrimitive osm : data) {
65 osm.visit(v);
66 if (cname == null)
67 cname = v.className;
68 else if (!cname.equals(v.className))
69 cname = "object";
70 }
71 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(
72 tr("Delete")+" "+data.size()+" "+trn(cname, cname+"s", data.size()), ImageProvider.get("data", cname), JLabel.HORIZONTAL));
73 for (OsmPrimitive osm : data) {
74 osm.visit(v);
75 root.add(new DefaultMutableTreeNode(v.toLabel()));
76 }
77 return root;
78 }
79}
Note: See TracBrowser for help on using the repository browser.