changeset 20:c128d675386b

Added UIProviders that are used to create widgets for entering data. flys-client/trunk@1334 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 22 Feb 2011 17:17:12 +0000
parents f48b2cb2e219
children e98a25b5c95a
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProvider.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java
diffstat 5 files changed, 272 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+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 <i>data</i>.<br>
+     *
+     * <b>TODO: The map panel for the river selection needs to be
+     * implemented!</b>
+     *
+     * @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 :
--- /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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+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<StepForwardHandler> forwardHandlers;
+
+    /** The combobox.*/
+    protected ComboBoxItem combobox;
+
+
+    /**
+     * Creates a new UIProvider instance of this class.
+     */
+    public SelectProvider() {
+        forwardHandlers = new ArrayList<StepForwardHandler>();
+    }
+
+
+    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 <i>data</i>.
+     *
+     * @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<String, String> it = new LinkedHashMap<String, String>();
+
+        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 :
--- /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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface UIProvider extends Serializable {
+
+    /**
+     * This method creates a Canvas element showing the DataItems in
+     * <i>data</i>.
+     *
+     * @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 :
--- /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();
+        }
+    }
+}

http://dive4elements.wald.intevation.org