01: package jimm.datavision.gui.cmd;
02:
03: import jimm.datavision.Report;
04: import jimm.datavision.gui.Designer;
05: import jimm.datavision.gui.FieldPickerTree;
06: import jimm.datavision.gui.FPLeafInfo;
07: import jimm.util.I18N;
08: import javax.swing.tree.*;
09:
10: /**
11: * Deletes something from the field picker tree.
12: *
13: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
14: */
15: public class FPDeleteCommand extends CommandAdapter {
16:
17: protected Report report;
18: protected Designer designer;
19: protected FieldPickerTree tree;
20: protected DefaultMutableTreeNode leafNode;
21: protected MutableTreeNode parentNode;
22: protected FPLeafInfo info;
23:
24: /**
25: * Constructor.
26: */
27: public FPDeleteCommand(Report report, Designer designer,
28: FieldPickerTree tree, DefaultMutableTreeNode node) {
29: this (report, designer, tree, node, I18N
30: .get("FPDeleteCommand.name"));
31: }
32:
33: /**
34: * The delegated constructor.
35: */
36: protected FPDeleteCommand(Report report, Designer designer,
37: FieldPickerTree tree, DefaultMutableTreeNode node,
38: String name) {
39: super (name);
40: this .report = report;
41: this .designer = designer;
42: this .tree = tree;
43: leafNode = node;
44: parentNode = (MutableTreeNode) node.getParent();
45: Object obj = node.getUserObject();
46: if (obj instanceof FPLeafInfo)
47: info = (FPLeafInfo) obj;
48: }
49:
50: public void perform() {
51: if (info != null) {
52: report.remove(info.getLeaf());
53: tree.removeCurrentNode();
54: }
55: }
56:
57: public void undo() {
58: if (info != null) {
59: report.add(info.getLeaf());
60:
61: ((DefaultTreeModel) tree.getModel()).insertNodeInto(
62: leafNode, parentNode, parentNode.getChildCount());
63:
64: // Make leaf visible and make it the current selection
65: TreePath path = new TreePath(leafNode.getPath());
66: tree.scrollPathToVisible(path);
67: tree.setSelectionPath(path);
68: }
69: }
70:
71: }
|