changeset 1523:07b532f9e057

Added new panels for inserting ranges, int ranges and time (year) ranges. flys-client/trunk@3700 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 18 Jan 2012 09:19:36 +0000
parents df9baca681a0
children 487c3ff7e838
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/RangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/TimerangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java
diffstat 5 files changed, 329 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jan 18 09:14:17 2012 +0000
+++ b/flys-client/ChangeLog	Wed Jan 18 09:19:36 2012 +0000
@@ -1,3 +1,20 @@
+2012-01-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/RangePanel.java: New.
+	  This panel allows inserting two values (min and max) for ranges. It is
+	  abstract, so concrete subclasses are required.
+
+	* src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java:
+	  New. A subclass of RangePanel that allows inserting an integer range.
+
+	* src/main/java/de/intevation/flys/client/client/ui/TimerangePanel.java:
+	  New. A subclass of IntegerRangePanel that requires an IntegerRangeData
+	  object to set the min and max values for the range.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Create new instances of TimerangePanel if the ui provider is set to
+	  'timerange'.
+
 2012-01-18  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java	Wed Jan 18 09:19:36 2012 +0000
@@ -0,0 +1,85 @@
+package de.intevation.flys.client.client.ui;
+
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.IntegerItem;
+import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator;
+import com.smartgwt.client.widgets.form.validator.Validator;
+
+import de.intevation.flys.client.shared.model.DataList;
+
+
+public class IntegerRangePanel extends RangePanel {
+
+    protected Integer maxLower;
+    protected Integer maxUpper;
+
+
+    @Override
+    protected FormItem newFormItem(String name) {
+        IntegerItem item = new IntegerItem(name, "");
+        item.setShowTitle(false);
+
+        return item;
+    }
+
+
+    @Override
+    protected Validator[] createLowerValidators(DataList dataList) {
+        Validator validator = newRangeValidator();
+
+        if (validator != null) {
+            return new Validator[] { validator };
+        }
+
+        return null;
+    }
+
+
+    @Override
+    protected Validator[] createUpperValidators(DataList dataList) {
+        Validator validator = newRangeValidator();
+
+        if (validator != null) {
+            return new Validator[] { validator };
+        }
+
+        return null;
+    }
+
+
+    protected Validator newRangeValidator() {
+        Integer maxLower = getMaxLower();
+        Integer maxUpper = getMaxUpper();
+
+        if (maxLower != null && maxUpper != null) {
+            IntegerRangeValidator validator = new IntegerRangeValidator();
+            validator.setMax(maxUpper);
+            validator.setMin(maxLower);
+
+            return validator;
+        }
+
+        return null;
+    }
+
+
+    public Integer getMaxLower() {
+        return maxLower;
+    }
+
+
+    public void setMaxLower(Integer maxLower) {
+        this.maxLower = maxLower;
+    }
+
+
+    public Integer getMaxUpper() {
+        return maxUpper;
+    }
+
+
+    public void setMaxUpper(Integer maxUpper) {
+        this.maxUpper = maxUpper;
+    }
+}
+// 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/RangePanel.java	Wed Jan 18 09:19:36 2012 +0000
@@ -0,0 +1,181 @@
+package de.intevation.flys.client.client.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.smartgwt.client.data.DataSource;
+import com.smartgwt.client.data.DataSourceField;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.FieldType;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.validator.Validator;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.shared.model.DataList;
+import de.intevation.flys.client.shared.model.Data;
+
+
+/**
+ * An UIProvider for inserting ranges.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public abstract class RangePanel extends AbstractUIProvider {
+
+    public static final String FIELD_LOWER = "field_lower";
+    public static final String FIELD_UPPER = "field_upper";
+
+
+    protected DynamicForm lowerForm;
+    protected DynamicForm upperForm;
+
+
+    @Override
+    public Canvas create(DataList data) {
+        VLayout root = new VLayout();
+
+        root.addMember(createLabel(data));
+        root.addMember(createForm(data));
+        root.addMember(getNextButton());
+
+        return root;
+    }
+
+
+    @Override
+    public Canvas createOld(DataList data) {
+        // TODO IMPLEMENT ME
+        return new Canvas();
+    }
+
+
+    @Override
+    protected Data[] getData() {
+        return new Data[0];
+    }
+
+
+    @Override
+    public List<String> validate() {
+        List<String> errors = new ArrayList<String>();
+
+        if (!lowerForm.validate()) {
+            errors.add("LOWER ERRORS");
+        }
+
+        if (!upperForm.validate()) {
+            errors.add("UPPER ERRORS");
+        }
+
+        return errors;
+    }
+
+
+    protected Canvas createLabel(DataList dataList) {
+        Label label = new Label(dataList.getLabel());
+
+        label.setWidth(100);
+        label.setHeight(25);
+
+        return label;
+    }
+
+
+    protected Canvas createForm(DataList dataList) {
+        lowerForm = createLowerForm(dataList);
+        upperForm = createUpperForm(dataList);
+
+        HLayout formLayout = new HLayout();
+        formLayout.addMember(lowerForm);
+        formLayout.addMember(createSpacer());
+        formLayout.addMember(upperForm);
+
+        return formLayout;
+    }
+
+
+    protected DynamicForm newForm() {
+        DynamicForm form = new DynamicForm();
+        form.setTitlePrefix("");
+        form.setTitleSuffix("");
+        form.setTitle("");
+        form.setTitleField("");
+
+        return form;
+    }
+
+
+    protected FormItem newFormItem(String name) {
+        TextItem item = new TextItem(name, "");
+        item.setShowTitle(false);
+
+        return item;
+    }
+
+
+    protected DynamicForm createLowerForm(DataList dataList) {
+        DynamicForm lowerForm = newForm();
+        FormItem    lower     = createLowerField(dataList);
+
+        lowerForm.setFields(lower);
+
+        return lowerForm;
+    }
+
+
+    protected DynamicForm createUpperForm(DataList dataList) {
+        DynamicForm upperForm = newForm();
+        FormItem    upper     = createUpperField(dataList);
+
+        upperForm.setFields(upper);
+
+        return upperForm;
+    }
+
+
+    protected Canvas createSpacer() {
+        Label spacer = new Label("-");
+        spacer.setWidth(25);
+        spacer.setHeight(25);
+        spacer.setAlign(Alignment.CENTER);
+
+        return spacer;
+    }
+
+
+    protected FormItem createLowerField(DataList dataList) {
+        return createField(FIELD_LOWER, createLowerValidators(dataList));
+    }
+
+
+    protected FormItem createUpperField(DataList dataList) {
+        return createField(FIELD_UPPER, createUpperValidators(dataList));
+    }
+
+
+    protected FormItem createField(String name, Validator[] validators) {
+        FormItem field = newFormItem(name);
+
+        if (validators != null && validators.length > 0) {
+            field.setValidators(validators);
+        }
+
+        return field;
+    }
+
+
+    protected Validator[] createLowerValidators(DataList dataList) {
+        return null;
+    }
+
+
+    protected Validator[] createUpperValidators(DataList dataList) {
+        return 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/TimerangePanel.java	Wed Jan 18 09:19:36 2012 +0000
@@ -0,0 +1,43 @@
+package de.intevation.flys.client.client.ui;
+
+import com.smartgwt.client.types.FieldType;
+import com.smartgwt.client.widgets.form.validator.Validator;
+
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.IntegerRangeData;
+import de.intevation.flys.client.shared.model.DataList;
+
+
+public class TimerangePanel extends IntegerRangePanel {
+
+
+    @Override
+    protected Validator[] createLowerValidators(DataList dataList) {
+        setMaxLower(dataList);
+        setMaxUpper(dataList);
+
+        return super.createLowerValidators(dataList);
+    }
+
+
+    @Override
+    protected Validator[] createUpperValidators(DataList dataList) {
+        setMaxUpper(dataList);
+        setMaxLower(dataList);
+
+        return super.createUpperValidators(dataList);
+    }
+
+
+    protected void setMaxLower(DataList dataList) {
+        IntegerRangeData range = (IntegerRangeData) dataList.get(0);
+        setMaxLower(range.getLower());
+    }
+
+
+    protected void setMaxUpper(DataList dataList) {
+        IntegerRangeData range = (IntegerRangeData) dataList.get(0);
+        setMaxUpper(range.getUpper());
+    }
+}
+// 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/UIProviderFactory.java	Wed Jan 18 09:14:17 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Jan 18 09:19:36 2012 +0000
@@ -62,6 +62,9 @@
         else if (uiProvider.equals("map_digitize")) {
             return new DigitizePanel();
         }
+        else if (uiProvider.equals("timerange")) {
+            return new TimerangePanel();
+        }
         else {
             return new SelectProvider();
         }

http://dive4elements.wald.intevation.org