diff 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
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java	Fri Mar 18 13:45:34 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java	Mon Mar 21 08:28:02 2011 +0000
@@ -11,7 +11,10 @@
 import com.smartgwt.client.widgets.events.ClickHandler;
 
 import de.intevation.flys.client.client.FLYSMessages;
+import de.intevation.flys.client.client.event.HasStepBackHandlers;
 import de.intevation.flys.client.client.event.HasStepForwardHandlers;
+import de.intevation.flys.client.client.event.StepBackEvent;
+import de.intevation.flys.client.client.event.StepBackHandler;
 import de.intevation.flys.client.client.event.StepForwardEvent;
 import de.intevation.flys.client.client.event.StepForwardHandler;
 import de.intevation.flys.client.shared.model.Data;
@@ -24,7 +27,8 @@
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public abstract class AbstractUIProvider
-implements   UIProvider, HasStepForwardHandlers, ClickHandler
+implements   UIProvider, HasStepForwardHandlers, ClickHandler,
+             HasStepBackHandlers
 {
     /** The message class that provides i18n strings.*/
     protected FLYSMessages MSG = GWT.create(FLYSMessages.class);
@@ -33,12 +37,28 @@
     /** The StepForwardHandlers.*/
     protected List<StepForwardHandler> forwardHandlers;
 
+    /** The StepForwardHandlers.*/
+    protected List<StepBackHandler> backHandlers;
+
 
     /**
      * Creates a new UIProvider instance of this class.
      */
     public AbstractUIProvider() {
         forwardHandlers = new ArrayList<StepForwardHandler>();
+        backHandlers    = new ArrayList<StepBackHandler>();
+    }
+
+
+    /**
+     * Appends a StepBackHandler that wants to listen to StepBackEvents.
+     *
+     * @param handler A new StepBackHandler.
+     */
+    public void addStepBackHandler(StepBackHandler handler) {
+        if (handler != null) {
+            backHandlers.add(handler);
+        }
     }
 
 
@@ -55,6 +75,20 @@
 
 
     /**
+     * This method is called after the user has clicked one of the buttons to
+     * step back to a previous state.
+     *
+     * @param e The StepBackEvent.
+     */
+    protected void fireStepBackEvent(StepBackEvent e) {
+        GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: " + backHandlers.size());
+        for (StepBackHandler handler: backHandlers) {
+            handler.onStepBack(e);
+        }
+    }
+
+
+    /**
      * This method is called after the user has clicked on the 'next' button to
      * step to the next state.
      *
@@ -106,8 +140,7 @@
 
         back.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent event) {
-                GWT.log("Step back to: " + targetState);
-                GWT.log("TODO: fire StepBack event!");
+                fireStepBackEvent(new StepBackEvent(targetState));
             }
         });
 

http://dive4elements.wald.intevation.org