view flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java @ 58:d018995fbee7

The 'old' items in the parameter panel have a button to step back to a previous state (NOTE: just the UI stuff is implemented now). flys-client/trunk@1517 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 18 Mar 2011 12:01:55 +0000
parents 246af33f621c
children f793d35bfb08
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;

import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;

import de.intevation.flys.client.client.FLYSMessages;
import de.intevation.flys.client.client.event.HasStepForwardHandlers;
import de.intevation.flys.client.client.event.StepForwardEvent;
import de.intevation.flys.client.client.event.StepForwardHandler;
import de.intevation.flys.client.shared.model.Data;
import de.intevation.flys.client.shared.model.DataList;


/**
 * An abstract UIProvider that provides some basic methods.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public abstract class AbstractUIProvider
implements   UIProvider, HasStepForwardHandlers, ClickHandler
{
    /** The message class that provides i18n strings.*/
    protected FLYSMessages MSG = GWT.create(FLYSMessages.class);


    /** The StepForwardHandlers.*/
    protected List<StepForwardHandler> forwardHandlers;


    /**
     * Creates a new UIProvider instance of this class.
     */
    public AbstractUIProvider() {
        forwardHandlers = new ArrayList<StepForwardHandler>();
    }


    /**
     * Appends a StepForwardHandler that wants to listen to StepForwardEvents.
     *
     * @param handler A new StepForwardHandler.
     */
    public void addStepForwardHandler(StepForwardHandler handler) {
        if (handler != null) {
            forwardHandlers.add(handler);
        }
    }


    /**
     * This method is called after the user has clicked on the 'next' button to
     * step to the next state.
     *
     * @param e The StepForwardEvent.
     */
    protected void fireStepForwardEvent(StepForwardEvent e) {
        GWT.log("AbstractUIProvider - fireStepForwardEvent() handlers: " + forwardHandlers.size());
        for (StepForwardHandler handler: forwardHandlers) {
            handler.onStepForward(e);
        }
    }


    /**
     * This method is used to listen to click events on the 'next' button. The
     * fireStepForwardEvent() method is called here.
     *
     * @param e The click event.
     */
    public void onClick(ClickEvent e) {
        Data[] data = getData();

        fireStepForwardEvent(new StepForwardEvent(data));
    }


    /**
     * Creates the 'next' button to step forward to the next state.
     *
     * @return the 'next' button.
     */
    protected Canvas getNextButton() {
        Img go = new Img(MSG.imageNext(), 80, 25);
        go.addClickHandler(this);

        return go;
    }


    /**
     * Creates the 'back' button to step back to a previous state.
     *
     * @param targetState The identifier of the target state.
     *
     * @return the 'back' button.
     */
    protected Canvas getBackButton(final String targetState) {
        Img back = new Img(MSG.imageBack(), 16, 16);

        back.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                GWT.log("Step back to: " + targetState);
                GWT.log("TODO: fire StepBack event!");
            }
        });

        return back;
    }


    /**
     * This method needs to be implemented by concrete subclasses. It should
     * create a new Canvas object with a representation of <i>data</i>.
     *
     * @param data The data that should be displayed.
     *
     * @return a Canvas object that displays <i>data</i>.
     */
    public abstract Canvas create(DataList data);


    /**
     * This method needs to be implemented by concrete subclasses. It should
     * return the selected data.
     *
     * @return the selected data.
     */
    protected abstract Data[] getData();
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org