1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package triptracker.client.ui;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 /***
26 * An abstract {@link FormManager} class to handle adding, removal and
27 * displaying of forms. This class implements basic logic for form management
28 * and calls addComponent, removeComponent and showComponent so that the
29 * sub-class can modify its component container when needed. This class exists
30 * as convenience for creating form manager objects.
31 * <p>
32 * Extend this class to create a FormManager and override the addComponent,
33 * removeComponent and showComponent methods for simplified form component
34 * management. If you implement the FormManager interface, you have to write all
35 * the form management logic, which can cause code duplication where more than
36 * one form manager class exists.
37 */
38 public abstract class AbstractFormManager implements FormManager {
39 /*** List of currently registered forms. */
40 protected List<Form> forms = new ArrayList<Form>();
41
42 /*** The currently activated form. */
43 protected Form currentForm = null;
44
45 /***
46 * {@inheritDoc}
47 */
48 public void register(Form form) {
49 forms.add(form);
50 addComponent(form);
51
52 if (currentForm == null) {
53 currentForm = form;
54 }
55 }
56
57 /***
58 * {@inheritDoc}
59 */
60 public void deregister(Form form) {
61 if (currentForm == form) {
62 currentForm = null;
63 }
64
65 forms.remove(form);
66 removeComponent(form);
67 }
68
69 /***
70 * {@inheritDoc}
71 */
72 public void showForm(Form form) {
73
74 currentForm = form;
75 currentForm.refreshView();
76
77 showComponent(form);
78 }
79
80 /***
81 * Invoked as a result of a form calling register. Sub-classes must
82 * override this method in order to provide adding of components to their
83 * component container.
84 *
85 * @param form form to add to container
86 * @see #register(Form)
87 */
88 public abstract void addComponent(Form form);
89
90 /***
91 * Invoked as a result of a form calling deregister. Sub-classes must
92 * override this method in order to provide removal of components from their
93 * component container.
94 *
95 * @param form form to remove from container
96 * @see #deregister(Form)
97 */
98 public abstract void removeComponent(Form form);
99
100 /***
101 * Invoked as a result of a call to showForm. Sub-classes must override
102 * this method in order to implement show the appropriate forms when needed.
103 *
104 * @param form form to display
105 * @see #showForm(Form)
106 */
107 public abstract void showComponent(Form form);
108 }