changeset 30:5709bd8f4d7c

Added a new widget that combines the module and the river selection. Users can now choose the desired plugin and river in one step. flys-client/trunk@1433 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 09 Mar 2011 09:41:45 +0000
parents 44c63e7fd0d0
children e8745ca02f2b
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java
diffstat 8 files changed, 217 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Mar 09 08:00:06 2011 +0000
+++ b/flys-client/ChangeLog	Wed Mar 09 09:41:45 2011 +0000
@@ -1,3 +1,23 @@
+2011-03-09  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSMessages.java: Added
+	  i18n strings for the module and river selection.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java:
+	  New. A wrapper for the module and river selection. Both information can
+	  be chosen in just one step.
+
+	* src/main/java/de/intevation/flys/client/client/ui/MapSelection.java,
+	  src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java:
+	  Some layout improvements.
+
+	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.java:
+	  Makes use of the ModuleSelection if no artifact is existing in a new
+	  CollectionView. Users may now choose the desired plugin and the river in
+	  one single step.
+
 2011-03-09  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/services/RiverServiceAsync.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java	Wed Mar 09 08:00:06 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java	Wed Mar 09 09:41:45 2011 +0000
@@ -47,6 +47,12 @@
     @DefaultMessage("New Project")
     String new_project();
 
+    @DefaultMessage("Modul")
+    String module_selection();
+
+    @DefaultMessage("Rivers")
+    String river_selection();
+
     @DefaultMessage("WINFO")
     String winfo();
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties	Wed Mar 09 08:00:06 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties	Wed Mar 09 09:41:45 2011 +0000
@@ -11,6 +11,8 @@
 load_projects = Lade Berechnungen...
 date_format = dd.MM.yyyy
 new_project = Neues Projekt
+module_selection = Modul
+river_selection = Flüsse
 winfo = WINFO
 minfo = MINFO
 map = Karte
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties	Wed Mar 09 08:00:06 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties	Wed Mar 09 09:41:45 2011 +0000
@@ -11,6 +11,8 @@
 load_projects = Load calculations...
 date_format = yyyy-MM-dd
 new_project = New Project
+module_selection = Module
+river_selection = Rivers
 winfo = WINFO
 minfo = MINFO
 map = Map
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Wed Mar 09 08:00:06 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Wed Mar 09 09:41:45 2011 +0000
@@ -23,7 +23,11 @@
 import de.intevation.flys.client.shared.model.ArtifactDescription;
 import de.intevation.flys.client.shared.model.Collection;
 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.shared.model.DefaultCollection;
+import de.intevation.flys.client.shared.model.River;
 
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYS;
@@ -38,6 +42,7 @@
 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
 import de.intevation.flys.client.client.services.CreateCollectionService;
 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
+import de.intevation.flys.client.client.ui.ModuleSelection;
 
 
 /**
@@ -71,6 +76,9 @@
     /** The collection to be displayed.*/
     protected Collection collection;
 
+    /** The artifact that handles the parameterization.*/
+    protected Artifact artifact;
+
     protected TabSet tabs;
 
     /** The parameter tab.*/
@@ -201,33 +209,40 @@
 
 
     /**
-     * This method creates a Canvas displaying the plugins of FLYS.
+     * This method creates a Canvas displaying the plugins of FLYS combined with
+     * a widget to select a river.
      *
-     * @return a Canvas that displays the plugins of FLYS.
+     * @return a Canvas that displays the supported plugins and rivers of FLYS.
      */
     protected Canvas renderNew() {
-        VLayout newLayout = new VLayout();
-
-        DynamicForm    form  = new DynamicForm();
-        RadioGroupItem radio = new RadioGroupItem("plugin");
+        River[] rivers   = flys.getRivers();
+        DataItem[] items = new DataItem[rivers.length];
 
-        radio.setShowTitle(false);
-        radio.setVertical(false);
-        radio.setValueMap(
-            messages.winfo(),
-            messages.minfo(),
-            messages.map(),
-            messages.fix());
+        int i = 0;
+        for (River river: rivers) {
+            String name = river.getName();
+            items[i++]  = new DefaultDataItem(name, null, name);
+        }
 
-        form.setFields(radio);
+        Data data = new DefaultData(
+            "RIVER", "RIVER SELECTION", null, items, null);
 
-        IButton go = new IButton(messages.next());
-        go.addClickHandler(new ClickHandler() {
-            public void onClick(ClickEvent event) {
+        ModuleSelection widget         = new ModuleSelection();
+        HasStepForwardHandlers handler = (HasStepForwardHandlers) widget;
+
+        handler.addStepForwardHandler(new StepForwardHandler() {
+            public void onStepForward(StepForwardEvent event) {
+                Data[] data = event.getData();
+
+                DataItem[] moduleItems = data[0].getItems();
+                DataItem[] riversItems = data[1].getItems();
+
+                String module = moduleItems[0].getStringValue();
+                String river  = riversItems[0].getStringValue();
+
                 String serverUrl = Config.getInstance().getServerUrl();
-
                 artifactService.create(
-                    serverUrl, "winfo",
+                    serverUrl, module.toLowerCase(),
                     new AsyncCallback<Artifact>() {
                         public void onFailure(Throwable caught) {
                             GWT.log("Could not create the new artifact.");
@@ -236,19 +251,25 @@
 
                         public void onSuccess(Artifact artifact) {
                             GWT.log("Successfully created a new artifact.");
-                            Collection c = new DefaultCollection("TODO");
+                            setArtifact(artifact);
 
-                            c.addArtifact(artifact);
-                            setCollection(c);
+                            GWT.log("TODO: FEED WITH RIVER!");
                         }
                 });
             }
         });
 
-        newLayout.addMember(form);
-        newLayout.addMember(go);
+        return widget.create(data);
+    }
 
-        return newLayout;
+
+    /**
+     * Set the current artifact that is the master of the parameterization.
+     *
+     * @param artifact The new artifact.
+     */
+    protected void setArtifact(Artifact artifact) {
+        this.artifact = artifact;
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java	Wed Mar 09 08:00:06 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java	Wed Mar 09 09:41:45 2011 +0000
@@ -42,6 +42,7 @@
         h.setAlign(VerticalAlignment.TOP);
 
         Canvas form  = super.createWidget(data);
+        form.setWidth(250);
 
         Label  label = new Label("TODO: Map with rivers.");
         label.setValign(VerticalAlignment.TOP);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java	Wed Mar 09 09:41:45 2011 +0000
@@ -0,0 +1,123 @@
+package de.intevation.flys.client.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
+import com.smartgwt.client.widgets.layout.HLayout;
+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;
+
+/**
+ * The ModuleSelection combines the river selection and the module selection in
+ * one widget. It will display a vertical splitted widget - the upper part will
+ * render checkboxes for each module, the lower one will display a combobox at
+ * the left and a map panel on the right to choose the river.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class ModuleSelection extends MapSelection {
+
+    /** The message class that provides i18n strings.*/
+    protected FLYSMessages MESSAGES = GWT.create(FLYSMessages.class);
+
+    /** The module checkboxes.*/
+    protected RadioGroupItem radio;
+
+
+    /**
+     * The default constructor.
+     */
+    public ModuleSelection() {
+    }
+
+
+    /**
+     * This method returns a widget that renders the checkboxes for each module
+     * and the MapSelection that lets the user choose the river.
+     *
+     * @param data The provided rivers.
+     *
+     * @return the module selection combined with the river selection.
+     */
+    public Canvas create(Data data) {
+        VLayout newLayout = new VLayout();
+        newLayout.setMembersMargin(10);
+
+        Canvas moduleSelection = createWidget();
+        Canvas riverSelection  = super.createWidget(data);
+        IButton go             = new IButton(MESSAGES.next(), this);
+
+        moduleSelection.setHeight(25);
+
+        newLayout.addMember(moduleSelection);
+        newLayout.addMember(riverSelection);
+        newLayout.addMember(go);
+
+        return newLayout;
+    }
+
+
+    /**
+     * Creates a widget that displays a checkbox for each module.
+     *
+     * @return a widget with checkboxes.
+     */
+    protected Canvas createWidget() {
+        HLayout layout = new HLayout();
+
+        Label      label = new Label(MESSAGES.module_selection());
+        DynamicForm form = new DynamicForm();
+
+        radio = new RadioGroupItem("plugin");
+
+        label.setWidth(50);
+
+        radio.setShowTitle(false);
+        radio.setVertical(false);
+        radio.setValueMap(
+            messages.winfo(),
+            messages.minfo(),
+            messages.map(),
+            messages.fix());
+
+        form.setFields(radio);
+
+        layout.addMember(label);
+        layout.addMember(form);
+
+        return layout;
+    }
+
+
+    /**
+     * This method prepares the data of two widgets - the module selection and
+     * the river selection. The returning field will contain the Data that
+     * represents the module selection at first position, the second position
+     * stores the Data object that represents the river selection.
+     *
+     * @return the Data that was chosen in this widget.
+     */
+    protected Data[] getData() {
+        Data[] river = super.getData();
+
+        String module = radio.getValueAsString();
+
+        DataItem[] items = new DefaultDataItem[1];
+        items[0]         = new DefaultDataItem(module, module, module);
+
+        Data       data  = new DefaultData("module", null, null, items, null);
+
+        return new Data[] {data, river[0]};
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Wed Mar 09 08:00:06 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Wed Mar 09 09:41:45 2011 +0000
@@ -6,12 +6,15 @@
 
 import com.google.gwt.core.client.GWT;
 
+import com.smartgwt.client.types.VerticalAlignment;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.Label;
 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.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Data;
@@ -53,11 +56,8 @@
 
     public void addStepForwardHandler(StepForwardHandler handler) {
         if (handler != null) {
-            GWT.log("SelectProvider - addStepForwardHandler()");
             forwardHandlers.add(handler);
         }
-
-        GWT.log("Handlers now: " + forwardHandlers.size());
     }
 
 
@@ -70,16 +70,13 @@
     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));
     }
 
@@ -98,15 +95,6 @@
         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);
@@ -125,8 +113,10 @@
     protected Canvas createWidget(Data data) {
         GWT.log("SelectProvider - create()");
 
-        DynamicForm form      = new DynamicForm();
-        combobox = new ComboBoxItem("river");
+        HLayout layout   = new HLayout();
+        Label label      = new Label(messages.river_selection());
+        DynamicForm form = new DynamicForm();
+        combobox         = new ComboBoxItem("river");
 
         LinkedHashMap<String, String> it = new LinkedHashMap<String, String>();
 
@@ -135,18 +125,24 @@
             it.put(item.getStringValue(), item.getLabel());
         }
 
+        label.setWidth(50);
         combobox.setValueMap(it);
+        combobox.setShowTitle(false);
         form.setItems(combobox);
 
-        return form;
+        layout.addMember(label);
+        layout.addMember(form);
+
+        label.setValign(VerticalAlignment.TOP);
+        layout.setAlign(VerticalAlignment.TOP);
+
+        return layout;
     }
 
 
     protected Data[] getData() {
         String selection = combobox.getValueAsString();
-
-        GWT.log("SelectProvider - getData() Selected value = " + selection);
-        DataItem item = new DefaultDataItem("river", null, selection);
+        DataItem item    = new DefaultDataItem("river", null, selection);
 
         return new Data[] { new DefaultData(
             "river", null, null, new DataItem[] { item }, null) };

http://dive4elements.wald.intevation.org