changeset 791:9b1499a65aaa

Finished the panel that allows integers and the string 'auto'. flys-client/trunk@2298 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 07 Jul 2011 10:33:29 +0000 (2011-07-07)
parents 3fa8583434b2
children 696e3404e991
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/TextProvider.java flys-client/src/main/webapp/FLYS.css
diffstat 4 files changed, 183 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jul 06 15:34:38 2011 +0000
+++ b/flys-client/ChangeLog	Thu Jul 07 10:33:29 2011 +0000
@@ -1,3 +1,18 @@
+2011-07-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/TextProvider.java:
+	  Made methods in this class much smaller to override them easily in
+	  subclasses. In addition, the TextItem has been replaced with a
+	  DataSourceField which seems to be more easily to change in subclasses.
+
+	* src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java:
+	  Override required methods of TextProvider. This panel now accepts
+	  integer values and the string "auto". An inner class
+	  AutoIntegerValidator is used to validate the user input.
+
+	* src/main/webapp/FLYS.css: Set style for html label elements. Those label
+	  elements are used in forms to label items.
+
 2011-07-06  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/event/ParameterChangeEvent.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java	Wed Jul 06 15:34:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java	Thu Jul 07 10:33:29 2011 +0000
@@ -4,12 +4,11 @@
 
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.validator.Validator;
+import com.smartgwt.client.widgets.form.validator.CustomValidator;
 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.shared.model.DataList;
 
 import de.intevation.flys.client.client.FLYSConstants;
@@ -20,6 +19,9 @@
  */
 public class AutoIntegerPanel extends TextProvider {
 
+    public static final String FIELD_NAME = "integer_field";
+
+
     protected static FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
     protected String dataName;
@@ -31,7 +33,7 @@
         this.dataName = data.getLabel();
 
         Canvas label  = new Label(data.getDescription());
-        Canvas form   = createForm(MSG.uesk_profile_distance());
+        Canvas form   = createForm(getTitle());
         Canvas submit = getNextButton();
 
         VLayout layout = new VLayout();
@@ -47,13 +49,55 @@
     }
 
 
+    protected String getTitle() {
+        return MSG.uesk_profile_distance();
+    }
+
+
     @Override
-    protected Data[] getData() {
-        GWT.log("+++ RETURN DATA FOR STATE: " + dataName + " +++");
-        String value  = "TODO:FIND VALUE";
-        DataItem item = new DefaultDataItem(dataName, dataName, value);
-        return new Data[] { new DefaultData(
-            dataName, null, null, new DataItem[] { item }) };
+    protected String getDataName() {
+        return dataName;
+    }
+
+
+    @Override
+    protected String getValueAsString() {
+        String v = (String) form.getValue(getFieldName());
+        return v.toLowerCase();
+    }
+
+
+    @Override
+    protected Validator getValidator() {
+        Validator v = new AutoIntegerValidator();
+        v.setValidateOnChange(false);
+
+        return v;
+    }
+
+
+    public class AutoIntegerValidator extends CustomValidator {
+        @Override
+        protected boolean condition(Object value) {
+            String v = (String) value;
+
+            if (v == null || v.length() == 0) {
+                return false;
+            }
+
+            if (v.trim().equalsIgnoreCase("auto")) {
+                return true;
+            }
+
+            try {
+                Integer anInt = Integer.parseInt(v);
+
+                return true;
+            }
+            catch (NumberFormatException nfe) {
+                return false;
+            }
+        }
     }
 }
 // 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/TextProvider.java	Wed Jul 06 15:34:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/TextProvider.java	Thu Jul 07 10:33:29 2011 +0000
@@ -1,32 +1,52 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.google.gwt.core.client.GWT;
 
+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.types.TitleOrientation;
 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.TextItem;
+import com.smartgwt.client.widgets.form.events.ItemChangedEvent;
+import com.smartgwt.client.widgets.form.events.ItemChangedHandler;
+import com.smartgwt.client.widgets.form.validator.Validator;
 import com.smartgwt.client.widgets.layout.HLayout;
 
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.DataList;
+import de.intevation.flys.client.shared.model.DefaultData;
+import de.intevation.flys.client.shared.model.DefaultDataItem;
+
+import de.intevation.flys.client.client.FLYSConstants;
 
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class TextProvider extends AbstractUIProvider {
+public class TextProvider
+extends      AbstractUIProvider
+implements   ItemChangedHandler
+{
 
-    public static final String FIELD_NAME = "textprovider_inputfield";
+    public static final String FIELD_NAME  = "textprovider_inputfield";
+    public static final int    FORM_WIDTH  = 400;
+    public static final int    TITLE_WIDTH = 75;
+
+
+    protected static FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
     protected DynamicForm form;
 
 
     @Override
     public Canvas create(DataList dataList) {
-        GWT.log("CREATE NEW TEXTPROVIDER PANEL");
-
         return createForm();
     }
 
@@ -37,23 +57,69 @@
 
 
     protected Canvas createForm(String title) {
-        HLayout layout = new HLayout();
+        form = new DynamicForm();
+        form.addItemChangedHandler(this);
+        form.setTitlePrefix("");
+        form.setTitleSuffix(": ");
+        form.setTitleAlign(Alignment.LEFT);
+        form.setTitleOrientation(TitleOrientation.LEFT);
+        form.setTitleWidth(getTitleWidth());
+        form.setWidth(getFormWidth());
 
-        if (title != null && title.length() > 0) {
-            Label label = new Label(title);
-            label.setHeight(25);
-            layout.addMember(label);
+        DataSourceField item = createField();
+        item.setTitle(title);
+
+        Validator validator = getValidator();
+        if (validator != null) {
+            item.setValidators(validator);
         }
 
-        form = new DynamicForm();
-        layout.addMember(form);
+        DataSource source = new DataSource();
+        source.setFields(item);
 
-        TextItem item = new TextItem(FIELD_NAME);
-        item.setShowTitle(false);
+        form.setDataSource(source);
 
-        form.setFields(item);
+        return form;
+    }
 
-        return layout;
+
+    protected DataSourceField createField() {
+        return new DataSourceField(getFieldName(), getFieldType());
+    }
+
+
+    protected String getFieldName() {
+        return FIELD_NAME;
+    }
+
+
+    protected FieldType getFieldType() {
+        return FieldType.TEXT;
+    }
+
+
+    protected Validator getValidator() {
+        return null;
+    }
+
+
+    protected int getFormWidth() {
+        return FORM_WIDTH;
+    }
+
+
+    protected int getTitleWidth() {
+        return TITLE_WIDTH;
+    }
+
+
+    protected String getDataName() {
+        return null;
+    }
+
+
+    protected String getValueAsString() {
+        return (String) form.getValue(getFieldName());
     }
 
 
@@ -79,8 +145,31 @@
 
 
     @Override
+    public List<String> validate() {
+        List<String> errors = new ArrayList<String>();
+
+        if (!form.validate()) {
+            errors.add(MSG.wrongFormat());
+        }
+
+        return errors;
+    }
+
+
+    @Override
     protected Data[] getData() {
-        return new Data[0];
+        String value = getValueAsString();
+        String name  = getDataName();
+
+        DataItem item = new DefaultDataItem(name, name, value);
+        return new Data[] { new DefaultData(
+            name, null, null, new DataItem[] { item }) };
+    }
+
+
+    @Override
+    public void onItemChanged(ItemChangedEvent event) {
+        form.validate();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/FLYS.css	Wed Jul 06 15:34:38 2011 +0000
+++ b/flys-client/src/main/webapp/FLYS.css	Thu Jul 07 10:33:29 2011 +0000
@@ -99,3 +99,11 @@
     border-bottom: 1px solid black;
     padding: 5px;
 }
+
+label {
+  font-family: Arial,Verdana,sans-serif;
+  font-size: 11px;
+  font-style: normal;
+  font-weight: 400;
+  color: #000000;
+}

http://dive4elements.wald.intevation.org