comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java @ 60:f793d35bfb08

Implemented a mechanism to step back to previous states. flys-client/trunk@1523 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 21 Mar 2011 08:28:02 +0000
parents d018995fbee7
children 1d0fb625248d
comparison
equal deleted inserted replaced
59:a3d235c63195 60:f793d35bfb08
9 import com.smartgwt.client.widgets.Img; 9 import com.smartgwt.client.widgets.Img;
10 import com.smartgwt.client.widgets.events.ClickEvent; 10 import com.smartgwt.client.widgets.events.ClickEvent;
11 import com.smartgwt.client.widgets.events.ClickHandler; 11 import com.smartgwt.client.widgets.events.ClickHandler;
12 12
13 import de.intevation.flys.client.client.FLYSMessages; 13 import de.intevation.flys.client.client.FLYSMessages;
14 import de.intevation.flys.client.client.event.HasStepBackHandlers;
14 import de.intevation.flys.client.client.event.HasStepForwardHandlers; 15 import de.intevation.flys.client.client.event.HasStepForwardHandlers;
16 import de.intevation.flys.client.client.event.StepBackEvent;
17 import de.intevation.flys.client.client.event.StepBackHandler;
15 import de.intevation.flys.client.client.event.StepForwardEvent; 18 import de.intevation.flys.client.client.event.StepForwardEvent;
16 import de.intevation.flys.client.client.event.StepForwardHandler; 19 import de.intevation.flys.client.client.event.StepForwardHandler;
17 import de.intevation.flys.client.shared.model.Data; 20 import de.intevation.flys.client.shared.model.Data;
18 import de.intevation.flys.client.shared.model.DataList; 21 import de.intevation.flys.client.shared.model.DataList;
19 22
22 * An abstract UIProvider that provides some basic methods. 25 * An abstract UIProvider that provides some basic methods.
23 * 26 *
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
25 */ 28 */
26 public abstract class AbstractUIProvider 29 public abstract class AbstractUIProvider
27 implements UIProvider, HasStepForwardHandlers, ClickHandler 30 implements UIProvider, HasStepForwardHandlers, ClickHandler,
31 HasStepBackHandlers
28 { 32 {
29 /** The message class that provides i18n strings.*/ 33 /** The message class that provides i18n strings.*/
30 protected FLYSMessages MSG = GWT.create(FLYSMessages.class); 34 protected FLYSMessages MSG = GWT.create(FLYSMessages.class);
31 35
32 36
33 /** The StepForwardHandlers.*/ 37 /** The StepForwardHandlers.*/
34 protected List<StepForwardHandler> forwardHandlers; 38 protected List<StepForwardHandler> forwardHandlers;
35 39
40 /** The StepForwardHandlers.*/
41 protected List<StepBackHandler> backHandlers;
42
36 43
37 /** 44 /**
38 * Creates a new UIProvider instance of this class. 45 * Creates a new UIProvider instance of this class.
39 */ 46 */
40 public AbstractUIProvider() { 47 public AbstractUIProvider() {
41 forwardHandlers = new ArrayList<StepForwardHandler>(); 48 forwardHandlers = new ArrayList<StepForwardHandler>();
49 backHandlers = new ArrayList<StepBackHandler>();
50 }
51
52
53 /**
54 * Appends a StepBackHandler that wants to listen to StepBackEvents.
55 *
56 * @param handler A new StepBackHandler.
57 */
58 public void addStepBackHandler(StepBackHandler handler) {
59 if (handler != null) {
60 backHandlers.add(handler);
61 }
42 } 62 }
43 63
44 64
45 /** 65 /**
46 * Appends a StepForwardHandler that wants to listen to StepForwardEvents. 66 * Appends a StepForwardHandler that wants to listen to StepForwardEvents.
48 * @param handler A new StepForwardHandler. 68 * @param handler A new StepForwardHandler.
49 */ 69 */
50 public void addStepForwardHandler(StepForwardHandler handler) { 70 public void addStepForwardHandler(StepForwardHandler handler) {
51 if (handler != null) { 71 if (handler != null) {
52 forwardHandlers.add(handler); 72 forwardHandlers.add(handler);
73 }
74 }
75
76
77 /**
78 * This method is called after the user has clicked one of the buttons to
79 * step back to a previous state.
80 *
81 * @param e The StepBackEvent.
82 */
83 protected void fireStepBackEvent(StepBackEvent e) {
84 GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: " + backHandlers.size());
85 for (StepBackHandler handler: backHandlers) {
86 handler.onStepBack(e);
53 } 87 }
54 } 88 }
55 89
56 90
57 /** 91 /**
104 protected Canvas getBackButton(final String targetState) { 138 protected Canvas getBackButton(final String targetState) {
105 Img back = new Img(MSG.imageBack(), 16, 16); 139 Img back = new Img(MSG.imageBack(), 16, 16);
106 140
107 back.addClickHandler(new ClickHandler() { 141 back.addClickHandler(new ClickHandler() {
108 public void onClick(ClickEvent event) { 142 public void onClick(ClickEvent event) {
109 GWT.log("Step back to: " + targetState); 143 fireStepBackEvent(new StepBackEvent(targetState));
110 GWT.log("TODO: fire StepBack event!");
111 } 144 }
112 }); 145 });
113 146
114 return back; 147 return back;
115 } 148 }

http://dive4elements.wald.intevation.org