1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.xmlhammer.gui.util;
22
23 import javax.swing.JComboBox;
24 import javax.swing.undo.AbstractUndoableEdit;
25
26 import org.xmlhammer.gui.Page;
27 import org.xmlhammer.gui.history.HistoryComboBox;
28
29 public class UndoableComboBoxEdit extends AbstractUndoableEdit {
30 private static final long serialVersionUID = 8615885869967750791L;
31
32 private Object current = null;
33 private Object previous = null;
34 private Page page = null;
35 private JComboBox combo = null;
36
37 public UndoableComboBoxEdit(Page page, JComboBox combo, Object current, Object previous) {
38 super();
39
40 this.page = page;
41 this.combo = combo;
42 this.current = current;
43 this.previous = previous;
44 }
45
46 public void undo() {
47 super.undo();
48
49 page.getProjectView().getOverviewPanel().selectNode(page);
50 combo.requestFocusInWindow();
51 combo.setSelectedItem(previous);
52
53 if (combo.isEditable() && previous != null) {
54 combo.getEditor().setItem(previous);
55 } else if (previous == null && combo instanceof HistoryComboBox) {
56 combo.getEditor().setItem(((HistoryComboBox)combo).getEmptyValue());
57 }
58 }
59
60 public void redo() {
61 super.redo();
62
63 page.getProjectView().getOverviewPanel().selectNode(page);
64 combo.requestFocusInWindow();
65 combo.setSelectedItem(current);
66
67 if (combo.isEditable() && current != null) {
68 combo.getEditor().setItem(current);
69 } else if (current == null && combo instanceof HistoryComboBox) {
70 combo.getEditor().setItem(((HistoryComboBox)combo).getEmptyValue());
71 }
72 }
73
74 public String getUndoPresentationName() {
75 return "Set "+previous.toString();
76 }
77
78 public String getRedoPresentationName() {
79 return "Reset "+current.toString();
80 }
81
82 public String toString() {
83 StringBuffer buffer = new StringBuffer("ComboBoxEdit Undo ");
84
85 if ( previous != null) {
86 buffer.append(previous.toString());
87 } else {
88 buffer.append("null");
89 }
90
91 buffer.append(" Redo ");
92
93 if ( current != null) {
94 buffer.append(current.toString());
95 } else {
96 buffer.append("null");
97 }
98
99 return buffer.toString();
100 }
101 }