01: package jimm.datavision.gui.cmd;
02:
03: import jimm.datavision.gui.Designer;
04: import jimm.datavision.gui.FieldWidget;
05: import jimm.datavision.gui.SectionWidget;
06: import jimm.util.I18N;
07: import java.util.*;
08:
09: /**
10: * Deletes a list of field widgets.
11: *
12: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
13: */
14: public class DeleteCommand extends CommandAdapter {
15:
16: protected Designer designer;
17: protected Collection fieldWidgets;
18:
19: /**
20: * Constructor.
21: */
22: public DeleteCommand(Designer designer, ArrayList selectedFields) {
23: this (designer, selectedFields, I18N.get("DeleteCommand.name"));
24: }
25:
26: /**
27: * The delegated constructor.
28: */
29: protected DeleteCommand(Designer designer,
30: ArrayList selectedFields, String name) {
31: super (name);
32: this .designer = designer;
33: fieldWidgets = (ArrayList) selectedFields.clone();
34: }
35:
36: public void perform() {
37: HashSet affectedSections = new HashSet();
38: designer.deselectAll();
39:
40: for (Iterator iter = fieldWidgets.iterator(); iter.hasNext();) {
41: FieldWidget fw = (FieldWidget) iter.next();
42: fw.doDelete(); // Widget deletes itself and field from report
43: affectedSections.add(fw.getSectionWidget());
44: }
45:
46: for (Iterator iter = affectedSections.iterator(); iter
47: .hasNext();)
48: ((SectionWidget) iter.next()).repaint();
49:
50: designer.enableMenuItems();
51: }
52:
53: public void undo() {
54: for (Iterator iter = fieldWidgets.iterator(); iter.hasNext();) {
55: FieldWidget fw = (FieldWidget) iter.next();
56: fw.moveToSection(fw.getSectionWidget());
57: designer.select(fw, true, false);
58: }
59: // Don't need to call Designer.enableMenuItems because each call
60: // to Designer.select already does that.
61: }
62:
63: }
|