01: /*
02: * MyGWT Widget Library
03: * Copyright(c) 2007, MyGWT.
04: * licensing@mygwt.net
05: *
06: * http://mygwt.net/license
07: */
08: package net.mygwt.ui.client.mvc;
09:
10: /**
11: * <code>Views</code> are responsible for rendering the user interface.
12: */
13: public abstract class View {
14:
15: protected Controller controller;
16: boolean initialized;
17:
18: /**
19: * Creates a new view instance.
20: *
21: * @param controller the parent controller
22: */
23: public View(Controller controller) {
24: this .controller = controller;
25: }
26:
27: /**
28: * Returns the view's controller.
29: *
30: * @return the controller
31: */
32: public Controller getController() {
33: return controller;
34: }
35:
36: /**
37: * Called when a view needs to pass an event to it's controller.
38: *
39: * @param event the app event
40: */
41: protected void fireEvent(AppEvent event) {
42: Controller c = controller;
43: while (c != null) {
44: if (c.canHandle(event)) {
45: c.handleEvent(event);
46: }
47: c = c.parent;
48: }
49: }
50:
51: /**
52: * Called when a view needs to pass an event to it's controller.
53: *
54: * @param eventType the event type
55: */
56: protected void fireEvent(int eventType) {
57: fireEvent(new AppEvent(eventType));
58: }
59:
60: /**
61: * Process the event.
62: *
63: * @param event the event to be processed
64: */
65: protected abstract void handleEvent(AppEvent event);
66:
67: /**
68: * Called once prior to handleEvent being called. Widgets should be
69: * instantiated in the init method rather than the view constructor.
70: */
71: protected void initialize() {
72:
73: }
74:
75: }
|