ingo@41: package de.intevation.flys.client.client.ui;
ingo@41:
ingo@41: import java.util.ArrayList;
ingo@41: import java.util.List;
ingo@41:
ingo@41: import com.google.gwt.core.client.GWT;
ingo@41:
ingo@41: import com.smartgwt.client.widgets.Canvas;
ingo@57: import com.smartgwt.client.widgets.Img;
ingo@41: import com.smartgwt.client.widgets.events.ClickEvent;
ingo@41: import com.smartgwt.client.widgets.events.ClickHandler;
ingo@41:
ingo@57: import de.intevation.flys.client.client.FLYSMessages;
ingo@60: import de.intevation.flys.client.client.event.HasStepBackHandlers;
ingo@41: import de.intevation.flys.client.client.event.HasStepForwardHandlers;
ingo@60: import de.intevation.flys.client.client.event.StepBackEvent;
ingo@60: import de.intevation.flys.client.client.event.StepBackHandler;
ingo@41: import de.intevation.flys.client.client.event.StepForwardEvent;
ingo@41: import de.intevation.flys.client.client.event.StepForwardHandler;
ingo@41: import de.intevation.flys.client.shared.model.Data;
ingo@51: import de.intevation.flys.client.shared.model.DataList;
ingo@41:
ingo@41:
ingo@41: /**
ingo@41: * An abstract UIProvider that provides some basic methods.
ingo@41: *
ingo@41: * @author Ingo Weinzierl
ingo@41: */
ingo@41: public abstract class AbstractUIProvider
ingo@60: implements UIProvider, HasStepForwardHandlers, ClickHandler,
ingo@60: HasStepBackHandlers
ingo@41: {
ingo@57: /** The message class that provides i18n strings.*/
ingo@57: protected FLYSMessages MSG = GWT.create(FLYSMessages.class);
ingo@57:
ingo@57:
ingo@41: /** The StepForwardHandlers.*/
ingo@41: protected List forwardHandlers;
ingo@41:
ingo@60: /** The StepForwardHandlers.*/
ingo@60: protected List backHandlers;
ingo@60:
ingo@41:
ingo@41: /**
ingo@41: * Creates a new UIProvider instance of this class.
ingo@41: */
ingo@41: public AbstractUIProvider() {
ingo@41: forwardHandlers = new ArrayList();
ingo@60: backHandlers = new ArrayList();
ingo@60: }
ingo@60:
ingo@60:
ingo@60: /**
ingo@60: * Appends a StepBackHandler that wants to listen to StepBackEvents.
ingo@60: *
ingo@60: * @param handler A new StepBackHandler.
ingo@60: */
ingo@60: public void addStepBackHandler(StepBackHandler handler) {
ingo@60: if (handler != null) {
ingo@60: backHandlers.add(handler);
ingo@60: }
ingo@41: }
ingo@41:
ingo@41:
ingo@41: /**
ingo@41: * Appends a StepForwardHandler that wants to listen to StepForwardEvents.
ingo@41: *
ingo@41: * @param handler A new StepForwardHandler.
ingo@41: */
ingo@41: public void addStepForwardHandler(StepForwardHandler handler) {
ingo@41: if (handler != null) {
ingo@41: forwardHandlers.add(handler);
ingo@41: }
ingo@41: }
ingo@41:
ingo@41:
ingo@41: /**
ingo@60: * This method is called after the user has clicked one of the buttons to
ingo@60: * step back to a previous state.
ingo@60: *
ingo@60: * @param e The StepBackEvent.
ingo@60: */
ingo@60: protected void fireStepBackEvent(StepBackEvent e) {
ingo@60: GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: " + backHandlers.size());
ingo@60: for (StepBackHandler handler: backHandlers) {
ingo@60: handler.onStepBack(e);
ingo@60: }
ingo@60: }
ingo@60:
ingo@60:
ingo@60: /**
ingo@41: * This method is called after the user has clicked on the 'next' button to
ingo@41: * step to the next state.
ingo@41: *
ingo@41: * @param e The StepForwardEvent.
ingo@41: */
ingo@41: protected void fireStepForwardEvent(StepForwardEvent e) {
ingo@41: GWT.log("AbstractUIProvider - fireStepForwardEvent() handlers: " + forwardHandlers.size());
ingo@41: for (StepForwardHandler handler: forwardHandlers) {
ingo@41: handler.onStepForward(e);
ingo@41: }
ingo@41: }
ingo@41:
ingo@41:
ingo@41: /**
ingo@41: * This method is used to listen to click events on the 'next' button. The
ingo@41: * fireStepForwardEvent() method is called here.
ingo@41: *
ingo@41: * @param e The click event.
ingo@41: */
ingo@41: public void onClick(ClickEvent e) {
ingo@41: Data[] data = getData();
ingo@41:
ingo@41: fireStepForwardEvent(new StepForwardEvent(data));
ingo@41: }
ingo@41:
ingo@41:
ingo@58: /**
ingo@58: * Creates the 'next' button to step forward to the next state.
ingo@58: *
ingo@58: * @return the 'next' button.
ingo@58: */
ingo@57: protected Canvas getNextButton() {
ingo@57: Img go = new Img(MSG.imageNext(), 80, 25);
ingo@57: go.addClickHandler(this);
ingo@57:
ingo@57: return go;
ingo@57: }
ingo@57:
ingo@57:
ingo@41: /**
ingo@58: * Creates the 'back' button to step back to a previous state.
ingo@58: *
ingo@58: * @param targetState The identifier of the target state.
ingo@58: *
ingo@58: * @return the 'back' button.
ingo@58: */
ingo@58: protected Canvas getBackButton(final String targetState) {
ingo@58: Img back = new Img(MSG.imageBack(), 16, 16);
ingo@58:
ingo@58: back.addClickHandler(new ClickHandler() {
ingo@58: public void onClick(ClickEvent event) {
ingo@60: fireStepBackEvent(new StepBackEvent(targetState));
ingo@58: }
ingo@58: });
ingo@58:
ingo@58: return back;
ingo@58: }
ingo@58:
ingo@58:
ingo@58: /**
ingo@41: * This method needs to be implemented by concrete subclasses. It should
ingo@41: * create a new Canvas object with a representation of data.
ingo@41: *
ingo@41: * @param data The data that should be displayed.
ingo@41: *
ingo@41: * @return a Canvas object that displays data.
ingo@41: */
ingo@51: public abstract Canvas create(DataList data);
ingo@41:
ingo@41:
ingo@41: /**
ingo@41: * This method needs to be implemented by concrete subclasses. It should
ingo@41: * return the selected data.
ingo@41: *
ingo@41: * @return the selected data.
ingo@41: */
ingo@41: protected abstract Data[] getData();
ingo@41: }
ingo@41: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :