# HG changeset patch # User Ingo Weinzierl # Date 1300696082 0 # Node ID f793d35bfb0831f3dc49fe124f4844db7edbd0f9 # Parent a3d235c63195889e0b1dd8b42ba1419106edb05a Implemented a mechanism to step back to previous states. flys-client/trunk@1523 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a3d235c63195 -r f793d35bfb08 flys-client/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java, diff -r a3d235c63195 -r f793d35bfb08 flys-client/src/main/java/de/intevation/flys/client/client/event/HasStepBackHandlers.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 Ingo Weinzierl + */ +public interface HasStepBackHandlers extends Serializable { + + public void addStepBackHandler(StepBackHandler handler); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a3d235c63195 -r f793d35bfb08 flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackEvent.java --- /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 Ingo Weinzierl + */ +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 : diff -r a3d235c63195 -r f793d35bfb08 flys-client/src/main/java/de/intevation/flys/client/client/event/StepBackHandler.java --- /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 Ingo Weinzierl + */ +public interface StepBackHandler extends Serializable { + + public void onStepBack(StepBackEvent event); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a3d235c63195 -r f793d35bfb08 flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java --- 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 Ingo Weinzierl */ 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 forwardHandlers; + /** The StepForwardHandlers.*/ + protected List backHandlers; + /** * Creates a new UIProvider instance of this class. */ public AbstractUIProvider() { forwardHandlers = new ArrayList(); + backHandlers = new ArrayList(); + } + + + /** + * 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)); } }); diff -r a3d235c63195 -r f793d35bfb08 flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java --- 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(); this.parameterHandlers = new ArrayList(); 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() { + 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); } diff -r a3d235c63195 -r f793d35bfb08 flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java --- 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 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(); 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 :