# HG changeset patch # User Ingo Weinzierl # Date 1298395032 0 # Node ID c128d675386bc9352caa59954fc769b26c5b45f2 # Parent f48b2cb2e2197086dc36a2a81ba8c5688c44edb6 Added UIProviders that are used to create widgets for entering data. flys-client/trunk@1334 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r f48b2cb2e219 -r c128d675386b flys-client/ChangeLog --- a/flys-client/ChangeLog Mon Feb 21 07:03:13 2011 +0000 +++ b/flys-client/ChangeLog Tue Feb 22 17:17:12 2011 +0000 @@ -1,3 +1,16 @@ +2011-02-22 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/client/ui/UIProvider.java, + src/main/java/de/intevation/flys/client/client/ui/MapSelection.java, + src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java: The + interface description and two implementations of a UIProvider. A + UIProvider is used to create widgets for the user input. The UIProvider + that is used in the current state depends on the data type in the describe + document and a 'uiprovider' flag that might be configured there. + + * src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java: + The factory that is used to create new instances of UIProvider. + 2011-02-21 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: diff -r f48b2cb2e219 -r c128d675386b flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java Tue Feb 22 17:17:12 2011 +0000 @@ -0,0 +1,57 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.VerticalAlignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; + +import de.intevation.flys.client.shared.model.Data; + + +/** + * This UIProvider displays the DataItems contained in the Data object in a + * combo box as SelectProvider does. Furthermore, there is a map displayed that + * lets the user choose a river by selecting it on the map. + * + * @author Ingo Weinzierl + */ +public class MapSelection extends SelectProvider { + + public MapSelection() { + } + + + /** + * This method currently returns a + * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all + * data items in a combobox stored in data.
+ * + * TODO: The map panel for the river selection needs to be + * implemented! + * + * @param data The {@link Data} object. + * + * @return a combobox. + */ + protected Canvas createWidget(Data data) { + GWT.log("MapSelection - create()"); + + HLayout h = new HLayout(); + h.setAlign(VerticalAlignment.TOP); + + Canvas form = super.createWidget(data); + + Label label = new Label("TODO: Map with rivers."); + label.setValign(VerticalAlignment.TOP); + + // TODO add the map panel to select the rivers via map. + + h.addMember(form); + h.addMember(label); + + return h; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r f48b2cb2e219 -r c128d675386b flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java Tue Feb 22 17:17:12 2011 +0000 @@ -0,0 +1,155 @@ +package de.intevation.flys.client.client.ui; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.IButton; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.ComboBoxItem; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +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; + + +/** + * This UIProvider displays the DataItems of the Data object in a combo box. + * + * @author Ingo Weinzierl + */ +public class SelectProvider implements UIProvider, HasStepForwardHandlers, + ClickHandler +{ + /** The message class that provides i18n strings.*/ + protected FLYSMessages messages = GWT.create(FLYSMessages.class); + + /** The StepForwardHandlers.*/ + protected List forwardHandlers; + + /** The combobox.*/ + protected ComboBoxItem combobox; + + + /** + * Creates a new UIProvider instance of this class. + */ + public SelectProvider() { + forwardHandlers = new ArrayList(); + } + + + public void addStepForwardHandler(StepForwardHandler handler) { + if (handler != null) { + GWT.log("SelectProvider - addStepForwardHandler()"); + forwardHandlers.add(handler); + } + + GWT.log("Handlers now: " + forwardHandlers.size()); + } + + + /** + * 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("SelectProvider - fireStepForwardEvent() handlers: " + forwardHandlers.size()); + for (StepForwardHandler handler: forwardHandlers) { + GWT.log("SelectProvider - fireStepForwardEvent()"); + handler.onStepForward(e); + } + } + + public void onClick(ClickEvent e) { + GWT.log("SelectProvider - feed and advance..."); + Data[] data = getData(); + + GWT.log("GO ON..."); + SelectProvider.this.fireStepForwardEvent(new StepForwardEvent(data)); + } + + /** + * This method currently returns a + * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all + * data items in a combobox stored in data. + * + * @param data The {@link Data} object. + * + * @return a combobox. + */ + public Canvas create(Data data) { + VLayout v = new VLayout(); + + Canvas content = createWidget(data); + + IButton button = new IButton(messages.next(), this); + //IButton button = new IButton(messages.next(), new ClickHandler() { + // public void onClick(ClickEvent e) { + // GWT.log("SelectProvider - feed and advance..."); + // Data[] data = getData(); + + // GWT.log("GO ON..."); + // SelectProvider.this.fireStepForwardEvent(new StepForwardEvent(data)); + // } + //}); + + v.addMember(content); + v.addMember(button); + + return v; + } + + + /** + * This method creates the content of the widget. + * + * @param data The {@link Data} object. + * + * @return a combobox. + */ + protected Canvas createWidget(Data data) { + GWT.log("SelectProvider - create()"); + + DynamicForm form = new DynamicForm(); + combobox = new ComboBoxItem("river"); + + LinkedHashMap it = new LinkedHashMap(); + + for (DataItem item: data.getItems()) { + GWT.log("Add item: " + item.getLabel()); + it.put(item.getStringValue(), item.getLabel()); + } + + combobox.setValueMap(it); + form.setItems(combobox); + + return form; + } + + + protected Data[] getData() { + String selection = combobox.getValueAsString(); + + GWT.log("SelectProvider - getData() Selected value = " + selection); + DataItem item = new DefaultDataItem("river", null, selection); + + return new Data[] { new DefaultData( + "river", null, null, new DataItem[] { item }, null) }; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r f48b2cb2e219 -r c128d675386b flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProvider.java Tue Feb 22 17:17:12 2011 +0000 @@ -0,0 +1,28 @@ +package de.intevation.flys.client.client.ui; + +import java.io.Serializable; + +import com.smartgwt.client.widgets.Canvas; + +import de.intevation.flys.client.shared.model.Data; + + +/** + * This interface describes a method that creates a Canvas element displaying + * DataItems for a current state of the artifact. + * + * @author Ingo Weinzierl + */ +public interface UIProvider extends Serializable { + + /** + * This method creates a Canvas element showing the DataItems in + * data. + * + * @param data The data object. + * + * @return the Canvas showing the Data. + */ + public Canvas create(Data data); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r f48b2cb2e219 -r c128d675386b flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Tue Feb 22 17:17:12 2011 +0000 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.ui; + +public class UIProviderFactory { + + private UIProviderFactory() { + } + + public static UIProvider getProvider(String uiProvider) { + if (uiProvider == null || uiProvider.equals("")) { + return new SelectProvider(); + } + else if (uiProvider.equals("select_with_map")) { + return new MapSelection(); + } + else { + return new SelectProvider(); + } + } +}