Mercurial > dive4elements > river
changeset 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 | a3d235c63195 |
children | f983d5ce6402 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/event/HasStepBackHandlers.java flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackEvent.java flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackHandler.java flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java |
diffstat | 7 files changed, 187 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri Mar 18 13:45:34 2011 +0000 +++ b/flys-client/ChangeLog Mon Mar 21 08:28:02 2011 +0000 @@ -1,3 +1,31 @@ +2011-03-21 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/client/event/HasStepBackHandlers.java, + src/main/java/de/intevation/flys/client/client/event/StepBackHandler.java, + src/main/java/de/intevation/flys/client/client/event/StepBackEvent.java: + New. These classes are used to realize a notification mechanism to + listen to the step-back part of the advance() operation. UI elements + should fire a StepBackEvent if the user tries to step back to a previous + state. + + * src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java: + The UIProvider implements the HasStepBackHandlers interface and fires + StepBackEvents if the 'back' button has been clicked. + + * src/main/java/de/intevation/flys/client/client/ui/ParameterList.java: + Listens to StepBackEvents. If such an event is received, we gonna remove + all old state items from the list and revert the view. Afterwards, the + artifact description is used to redraw the whole view. + + NOTE: I think we should just remove those items that belong to states + between the current state and the target state. This would avoid a + complete refresh of the ParameterPanel. + + * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: + Listens to StepBackEvents. If such an event is received, the advance() + operation is triggerd with the current artifact and the new target + state identifier to step back to that state. + 2011-03-18 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/HasStepBackHandlers.java Mon Mar 21 08:28:02 2011 +0000 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface HasStepBackHandlers extends Serializable { + + public void addStepBackHandler(StepBackHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackEvent.java Mon Mar 21 08:28:02 2011 +0000 @@ -0,0 +1,34 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StepBackEvent implements Serializable { + + /** The identifier of the target state.*/ + protected String target; + + + /** + * Creates a new StepBackEvent with the identifier of the target state. + * + * @param target The identifier of the target state. + */ + public StepBackEvent(String target) { + this.target = target; + } + + + /** + * A method to retrieve the target identifier. + * + * @return the target identifier. + */ + public String getTarget() { + return target; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackHandler.java Mon Mar 21 08:28:02 2011 +0000 @@ -0,0 +1,13 @@ +package de.intevation.flys.client.client.event; + +import java.io.Serializable; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface StepBackHandler extends Serializable { + + public void onStepBack(StepBackEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- 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)); } });
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Fri Mar 18 13:45:34 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Mon Mar 21 08:28:02 2011 +0000 @@ -29,13 +29,18 @@ import de.intevation.flys.client.client.FLYSMessages; import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; import de.intevation.flys.client.client.event.HasParameterChangeHandler; +import de.intevation.flys.client.client.event.HasStepBackHandlers; import de.intevation.flys.client.client.event.HasStepForwardHandlers; import de.intevation.flys.client.client.event.CollectionChangeEvent; import de.intevation.flys.client.client.event.CollectionChangeHandler; import de.intevation.flys.client.client.event.ParameterChangeEvent; import de.intevation.flys.client.client.event.ParameterChangeHandler; +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.client.services.AdvanceService; +import de.intevation.flys.client.client.services.AdvanceServiceAsync; import de.intevation.flys.client.client.services.ArtifactService; import de.intevation.flys.client.client.services.ArtifactServiceAsync; import de.intevation.flys.client.client.services.StepForwardService; @@ -52,7 +57,7 @@ extends Window implements CollectionChangeHandler, HasCollectionChangeHandlers, HasParameterChangeHandler, ParameterChangeHandler, - StepForwardHandler + StepForwardHandler, StepBackHandler { /** The ArtifactService used to communicate with the Artifact server. */ protected ArtifactServiceAsync artifactService = @@ -62,6 +67,10 @@ protected StepForwardServiceAsync forwardService = GWT.create(StepForwardService.class); + /** The StepForwardService used to put data into an existing artifact. */ + protected AdvanceServiceAsync advanceService = + GWT.create(AdvanceService.class); + /** The ArtifactService used to communicate with the Artifact server. */ protected CreateCollectionServiceAsync createCollectionService = GWT.create(CreateCollectionService.class); @@ -111,7 +120,7 @@ this.tabs = new TabSet(); this.parameterTab = new Tab(messages.winfo()); - this.parameterList = new ParameterList(); + this.parameterList = new ParameterList(this); this.handlers = new ArrayList<CollectionChangeHandler>(); this.parameterHandlers = new ArrayList<ParameterChangeHandler>(); this.layout = new VLayout(); @@ -357,6 +366,32 @@ /** + * This method is used to call the ADVANCE service to go back to a previous + * state. + * + * @param e The StepBackEvent that holds the identifier of the target state. + */ + public void onStepBack(StepBackEvent e) { + final String target = e.getTarget(); + final String serverUrl = Config.getInstance().getServerUrl(); + + advanceService.advance(serverUrl, artifact, target, + new AsyncCallback<Artifact>() { + public void onFailure(Throwable caught) { + GWT.log("Could not go back to '" + target + "'"); + GWT.log(caught.getMessage()); + } + + public void onSuccess(Artifact artifact) { + GWT.log("Successfully step back to '" + target + "'"); + setArtifact(artifact); + } + } + ); + } + + + /** * This method is called if the user clicks on the 'next' button to advance * to the next state. * @@ -394,8 +429,8 @@ String uiProvider = currentData.getUIProvider(); UIProvider provider = UIProviderFactory.getProvider(uiProvider); - HasStepForwardHandlers handler = (HasStepForwardHandlers) provider; - handler.addStepForwardHandler(this); + ((HasStepForwardHandlers) provider).addStepForwardHandler(this); + ((HasStepBackHandlers) provider).addStepBackHandler(this); parameterList.setCurrentData(currentData, provider); }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Fri Mar 18 13:45:34 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Mon Mar 21 08:28:02 2011 +0000 @@ -12,9 +12,16 @@ import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.client.event.HasStepBackHandlers; +import de.intevation.flys.client.client.event.StepBackEvent; +import de.intevation.flys.client.client.event.StepBackHandler; -public class ParameterList extends VLayout { +public class ParameterList +extends VLayout +implements StepBackHandler +{ + protected CollectionView cView; protected List<DataList> old; protected DataList current; @@ -24,7 +31,8 @@ protected VLayout oldItems; protected VLayout currentItems; - public ParameterList() { + public ParameterList(CollectionView cView) { + this.cView = cView; old = new ArrayList<DataList>(); oldItems = new VLayout(); currentItems = new VLayout(); @@ -111,6 +119,8 @@ String provider = dataList.getUIProvider(); UIProvider uiprovider = UIProviderFactory.getProvider(provider); + ((HasStepBackHandlers) uiprovider).addStepBackHandler(cView); + ((HasStepBackHandlers) uiprovider).addStepBackHandler(this); oldItems.addMember(uiprovider.createOld(dataList)); } @@ -139,5 +149,17 @@ currentItems.addMember(c); } } + + + /** + * This method is used to remove all old items from this list after the user + * has clicked the step back button. + * + * @param e The StepBackEvent. + */ + public void onStepBack(StepBackEvent e) { + old.clear(); + oldItems.removeMembers(oldItems.getMembers()); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :