changeset 9369:1a4d2ce77423

radio choice fix
author gernotbelger
date Thu, 02 Aug 2018 17:39:13 +0200
parents 3d006afee054
children a773accce425
files artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/CalcChoice.java artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/FixationChoice.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/YearChoice.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/RiversideRadioChoice.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/YearEpochSelect.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/YearChoice.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/ScenarioTypeState.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/YearChoice.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/RadioPanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstCalcSelectRadioPanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/CustomFixationChoiceRadioPanel.java
diffstat 13 files changed, 180 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/CalcChoice.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/CalcChoice.java	Thu Aug 02 17:39:13 2018 +0200
@@ -43,4 +43,9 @@
         return ScenarioTypeState.changeHeaderForCurrentState("state.bundu.wst.calc_choice", data.getName(), cr, context);
     }
 
+    @Override
+    protected String getDatakey() {
+        return "calc_choice";
+    }
+
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/FixationChoice.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/FixationChoice.java	Thu Aug 02 17:39:13 2018 +0200
@@ -24,6 +24,7 @@
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class FixationChoice extends RadioSelect {
+
     private static final long serialVersionUID = 1L;
 
     @Override
@@ -89,4 +90,9 @@
         }
     }
 
+    @Override
+    protected String getDatakey() {
+        return "fix_choice";
+    }
+
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/YearChoice.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/YearChoice.java	Thu Aug 02 17:39:13 2018 +0200
@@ -32,4 +32,16 @@
         return entries;
     }
 
+    @Override
+    protected String getDatakey() {
+
+        return "ye_select";
+    }
+
+    @Override
+    protected String getUIProvider() {
+
+        return "collision_yearchoice_radio_panel";
+    }
+
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/RiversideRadioChoice.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/RiversideRadioChoice.java	Thu Aug 02 17:39:13 2018 +0200
@@ -61,4 +61,15 @@
         entries.put(RiversideChoiceKey.BOTH.getKey(), null);
         return entries;
     }
+
+    @Override
+    protected String getDatakey() {
+        return "riverside";
+    }
+
+    @Override
+    protected String getUIProvider() {
+
+        return "riverside_radio_panel";
+    }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java	Thu Aug 02 17:39:13 2018 +0200
@@ -28,36 +28,39 @@
     private static final long serialVersionUID = 1L;
     private Artifact artifact;
 
-    public RadioSelect() {
+    protected abstract String getDatakey();
 
-    }
+    @Override
+    protected abstract String getUIProvider(); // force override in subs!
+    // {
+    // return "radio_panel"; //no generic radiopanel
+    // }
 
     protected abstract LinkedHashMap<String, String> makeEntries(CallMeta meta, Artifact artifact); // AUSNAHMSWEISE EXPLIZITER TYP, damit Reihenfolge nicht
                                                                                                     // verrutscht
 
     @Override
-    protected String getUIProvider() {
-        return "radio_panel";
-    }
-
-    @Override
     protected Element[] createItems(final XMLUtils.ElementCreator ec, final Artifact artifact, final String name, final CallContext context) {
 
         // REMEBER: we need it for getLabelFor later
-        this.artifact = artifact;
-
-        final CallMeta meta = context.getMeta();
-        final Map<String, String> entries = makeEntries(meta, artifact);
 
-        final Element[] elements = new Element[entries.size()];
-        int i = 0;
-        for (final String key : entries.keySet()) {
-            final String label = entries.get(key);
-            final String labelToSet = label != null ? label : Resources.getMsg(meta, key);
-            elements[i] = createItem(ec, new String[] { labelToSet, key });
-            i++;
+        if (name.equals(getDatakey())) {
+            this.artifact = artifact;
+
+            final CallMeta meta = context.getMeta();
+            final Map<String, String> entries = makeEntries(meta, artifact);
+
+            final Element[] elements = new Element[entries.size()];
+            int i = 0;
+            for (final String key : entries.keySet()) {
+                final String label = entries.get(key);
+                final String labelToSet = label != null ? label : Resources.getMsg(meta, key);
+                elements[i] = createItem(ec, new String[] { labelToSet, key });
+                i++;
+            }
+            return elements;
         }
-        return elements;
+        return super.createItems(ec, artifact, name, context);
     }
 
     @Override
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/YearEpochSelect.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/YearEpochSelect.java	Thu Aug 02 17:39:13 2018 +0200
@@ -19,7 +19,7 @@
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class YearEpochSelect extends DefaultState {// TODO: RadioSelect-class; more flexible Implementation
+public class YearEpochSelect extends DefaultState {
 
     /**
      * The default constructor that initializes an empty State object.
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/YearChoice.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/YearChoice.java	Thu Aug 02 17:39:13 2018 +0200
@@ -36,4 +36,15 @@
         return entries;
     }
 
+    @Override
+    protected String getDatakey() {
+        return "ye_select";
+    }
+
+    @Override
+    protected String getUIProvider() {
+
+        return "inundationduration_yearchoice_radio_panel";
+    }
+
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/ScenarioTypeState.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/ScenarioTypeState.java	Thu Aug 02 17:39:13 2018 +0200
@@ -57,4 +57,14 @@
 
         return select;
     }
+
+    @Override
+    protected String getDatakey() {
+        return "scenario_selection";
+    }
+
+    @Override
+    protected String getUIProvider() {
+        return "salix_scenariotype_radio_panel";
+    }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/YearChoice.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/YearChoice.java	Thu Aug 02 17:39:13 2018 +0200
@@ -31,4 +31,15 @@
         entries.put("state.uinfo.epoch", null);
         return entries;
     }
+
+    @Override
+    protected String getDatakey() {
+        return "ye_select";
+    }
+
+    @Override
+    protected String getUIProvider() {
+
+        return "salix_yearchoice_radio_panel";
+    }
 }
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/RadioPanel.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/RadioPanel.java	Thu Aug 02 17:39:13 2018 +0200
@@ -29,71 +29,83 @@
 
     private static final long serialVersionUID = 3357071563224461043L;
 
-    protected String dataName;
     protected DynamicForm form;
     private final Map<String, String> valueLabelMap = new LinkedHashMap<String, String>();
 
+    private final String datakey;
+
+    public RadioPanel(final String datakey) {
+        this.datakey = datakey;
+    }
+
+    protected final String getDatakey() {
+        return this.datakey;
+    }
+
     @Override
     public Canvas createOld(final DataList dataList) {
-        final Data data = dataList.get(0);
-        final DataItem[] items = data.getItems();
-        // hat Einfluss auf Layout in der Übersicht (oben) nach Setzen des Wertes für den State
         final HLayout layout = new HLayout();
-        final Label label = new Label(dataList.getLabel());
-        final Label value = new Label(items[0].getLabel());
-        layout.setWidth(400);
-        label.setWidth(200); // nicht ändern; scheint wohl ne Konstante zu sein!
-        value.setWidth(180); // änderbar
-        layout.setHeight(35);
+        for (final Data data : dataList.getAll()) {
+            if (this.datakey.equals(data.getLabel())) {
+                final DataItem[] items = data.getItems();
+                // hat Einfluss auf Layout in der Übersicht (oben) nach Setzen des Wertes für den State
 
-        layout.addMember(label);
-        layout.addMember(value);
-        layout.addMember(getBackButton(dataList.getState()));
+                final Label label = new Label(dataList.getLabel());
+                final Label value = new Label(items[0].getLabel());
+                layout.setWidth(400);
+                label.setWidth(200); // nicht ändern; scheint wohl ne Konstante zu sein!
+                value.setWidth(180); // änderbar
+                layout.setHeight(35);
 
+                layout.addMember(label);
+                layout.addMember(value);
+                layout.addMember(getBackButton(dataList.getState()));
+
+            }
+        }
         return layout;
     }
 
     @Override
     public Canvas create(final DataList dataList) {
-        final Data data = dataList.get(0);
-        final DataItem[] items = data.getItems();
-
-        this.dataName = data.getLabel();
-
         final VLayout layout = new VLayout();
-        final Label label = new Label(data.getDescription());
-        label.setWrap(false);
-        final RadioGroupItem rgi = new RadioGroupItem("selection");
-        rgi.setWrapTitle(false);
-        rgi.setWrap(false);
-        rgi.setShowTitle(false);
-        GWT.log("items: " + items.length);
-        final LinkedHashMap<String, String> elems = new LinkedHashMap<String, String>();
-        for (final DataItem item : items) {
-            GWT.log(item.getStringValue() + "; " + item.getLabel());
-            if (!item.getLabel().startsWith("ignore_")) {
-                elems.put(item.getStringValue(), item.getLabel());
-                this.valueLabelMap.put(item.getStringValue(), item.getLabel());
+        for (final Data data : dataList.getAll()) {
+            if (this.datakey.equals(data.getLabel())) {
+                final DataItem[] items = data.getItems();
+
+                final Label label = new Label(data.getDescription());
+                label.setWrap(false);
+                final RadioGroupItem rgi = new RadioGroupItem("selection");
+                rgi.setWrapTitle(false);
+                rgi.setWrap(false);
+                rgi.setShowTitle(false);
+                GWT.log("items: " + items.length);
+                final LinkedHashMap<String, String> elems = new LinkedHashMap<String, String>();
+                for (final DataItem item : items) {
+                    GWT.log(item.getStringValue() + "; " + item.getLabel());
+                    if (!item.getLabel().startsWith("ignore_")) {
+                        elems.put(item.getStringValue(), item.getLabel());
+                        this.valueLabelMap.put(item.getStringValue(), item.getLabel());
+                    }
+                }
+                rgi.setValueMap(elems);
+                rgi.setDefaultValue(items[0].getStringValue());
+
+                this.form = new DynamicForm();
+                this.form.setFields(rgi);
+                layout.setMembersMargin(10);
+                layout.setHeight(35);
+                label.setHeight(35);
+                layout.setWidth(300);
+                label.setWidth(300);
+
+                layout.addMember(label);
+                layout.addMember(this.form);
+                layout.addMember(getNextButton());
+                layout.setMembersMargin(10);
+
             }
         }
-        rgi.setValueMap(elems);
-        rgi.setDefaultValue(items[0].getStringValue());
-
-        this.form = new DynamicForm();
-        this.form.setFields(rgi);
-        layout.setMembersMargin(10);
-        layout.setHeight(35);
-        label.setHeight(35);
-        layout.setWidth(300);
-        label.setWidth(300);
-
-        layout.addMember(label);
-        layout.addMember(this.form);
-        layout.addMember(getNextButton());
-        layout.setMembersMargin(10);
-
-        // initDefaultValues(dataList);
-
         return layout;
     }
 
@@ -102,13 +114,9 @@
         final String value = this.form.getValueAsString("selection");
 
         final DataItem item = new DefaultDataItem("label_irrelevant", "description_irrelevant", value);
-        // Alles hoffnungslos:
-        // final DataItem useHeader = new DefaultDataItem("label_irrelevant", "description_irrelevant",
-        // this.valueLabelMap.get(value));
 
-        return new Data[] { new DefaultData(this.dataName, "label_no_effect", "description_no_effect", new DataItem[] { item // , useHeader
-                })
-                // ,new DefaultData("value", "label", "description", new DataItem[] { useHeader }) DOES NOT WORK
+        return new Data[] { new DefaultData(this.datakey, "label_no_effect", "description_no_effect", new DataItem[] { item })
+
         };
     }
 
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Thu Aug 02 17:39:13 2018 +0200
@@ -165,11 +165,17 @@
         } else if (uiProvider.equals("parameter-matrix")) {
             return new ParameterMatrixPanel();
         } else if (uiProvider.equals("minfo.bed.year_epoch")) {// legacy
-            return new RadioPanel();
+            return new RadioPanel("ye_select");
         } else if (uiProvider.equals("bundu_calc_choice_radio_panel")) {
-            return new BunduWstCalcSelectRadioPanel();
-        } else if (uiProvider.equals("radio_panel")) {
-            return new RadioPanel();
+            return new BunduWstCalcSelectRadioPanel("calc_choice");
+        } else if (uiProvider.equals("collision_yearchoice_radio_panel")) {
+            return new RadioPanel("ye_select");
+        } else if (uiProvider.equals("inundationduration_yearchoice_radio_panel")) {
+            return new RadioPanel("ye_select");
+        } else if (uiProvider.equals("salix_yearchoice_radio_panel")) {
+            return new RadioPanel("ye_select");
+        } else if (uiProvider.equals("salix_scenariotype_radio_panel")) {
+            return new RadioPanel("scenario_selection");
         } else if (uiProvider.equals("custom_fixation_radio_panel")) {
             return new CustomFixationChoiceRadioPanel();
         } else if (uiProvider.equals("bedquality_periods_select")) {
@@ -179,8 +185,12 @@
         } else if (uiProvider.equals("minfo.bed.char_diameter")) {
             return new CheckboxPanel();
         } else if (uiProvider.equals("minfo.sedimentload_unit_select")) {
-            return new RadioPanel();
-        } else if (uiProvider.equals("static_data")) {
+            return new RadioPanel("unit");
+        } else if (uiProvider.equals("riverside_radio_panel")) {
+            return new RadioPanel("riverside");
+        }
+
+        else if (uiProvider.equals("static_data")) {
             return new StaticDataPanel();
         } else if (uiProvider.equals("minfo.sedimentload_distance_select")) {
             return new SedLoadDistancePanel();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstCalcSelectRadioPanel.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstCalcSelectRadioPanel.java	Thu Aug 02 17:39:13 2018 +0200
@@ -16,6 +16,10 @@
 
 public class BunduWstCalcSelectRadioPanel extends RadioPanel {
 
+    public BunduWstCalcSelectRadioPanel(final String datakey) {
+        super(datakey);
+    }
+
     private static final long serialVersionUID = 3357071563224461043L;
 
     @Override
@@ -24,7 +28,7 @@
         final String value = this.form.getValueAsString("selection");
 
         final DataItem item = new DefaultDataItem("label_irrelevant", "description_irrelevant", value);
-        final DefaultData selection = new DefaultData(this.dataName, "label_no_effect", "description_no_effect", new DataItem[] { item });
+        final DefaultData selection = new DefaultData(getDatakey(), "label_no_effect", "description_no_effect", new DataItem[] { item });
         if (value.equals("state.bundu.calc.auto")) {
             final Data[] data = new Data[2];
             data[0] = selection;
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/CustomFixationChoiceRadioPanel.java	Thu Aug 02 15:06:22 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/CustomFixationChoiceRadioPanel.java	Thu Aug 02 17:39:13 2018 +0200
@@ -37,6 +37,10 @@
     private String events[];
     private int bezugsjahr = 0;
 
+    public CustomFixationChoiceRadioPanel() {
+        super("fix_choice");
+    }
+
     @Override
     public Canvas createOld(final DataList dataList) { // wild überschrieben :-(
         final List<Data> list = dataList.getAll();
@@ -47,7 +51,7 @@
         layoutChoice.setWidth(400);
 
         for (final Data item : list) {
-            if ("fix_choice".equals(item.getLabel())) {
+            if (getDatakey().equals(item.getLabel())) {
                 final Label labelLabel = new Label(this.MSG.bundu_bezugswst_fix_choice_title());
                 final Label valueLabel = new Label(item.getItems()[0].getLabel());
 
@@ -106,8 +110,8 @@
         DataItem startItem = new DefaultDataItem(null, null, "");
         DataItem endItem = new DefaultDataItem(null, null, "");
 
-        final DataItem item = new DefaultDataItem("fix_choice", "fix_choice", value);
-        data.add(new DefaultData("fix_choice", null, null, new DataItem[] { item }));
+        final DataItem item = new DefaultDataItem(getDatakey(), getDatakey(), value);
+        data.add(new DefaultData(getDatakey(), null, null, new DataItem[] { item }));
 
         if (value.equals("state.bundu.wst.fix.auto")) {
             // set gauges: (do not appear in create old, but need to be set for calculation purpose

http://dive4elements.wald.intevation.org