]> source.dussan.org Git - vaadin-framework.git/commitdiff
Teached the base field factory to understand method naming conventions and thus to...
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 24 Oct 2008 18:45:02 +0000 (18:45 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 24 Oct 2008 18:45:02 +0000 (18:45 +0000)
svn changeset:5725/svn branch:trunk

src/com/itmill/toolkit/ui/BaseFieldFactory.java

index 3e9e3666f2c774e3e82974e8c0785fc8b42a5efe..aa46480261e3b13fbff63e0fb29b46591d019082 100644 (file)
@@ -91,7 +91,44 @@ public class BaseFieldFactory implements FieldFactory {
             final Field f = createField(item.getItemProperty(propertyId),
                     uiContext);
             if (f instanceof AbstractComponent) {
-                ((AbstractComponent) f).setCaption(propertyId.toString());
+                String name = propertyId.toString();
+                if (name.length() > 0) {
+
+                    // If name follows method naming conventions, convert the
+                    // name to spaced uppercased text. For example, convert
+                    // "firstName" to "First Name"
+                    if (name.indexOf(' ') < 0
+                            && name.charAt(0) == Character.toLowerCase(name
+                                    .charAt(0))
+                            && name.charAt(0) != Character.toUpperCase(name
+                                    .charAt(0))) {
+                        StringBuffer out = new StringBuffer();
+                        out.append(Character.toUpperCase(name.charAt(0)));
+                        int i = 1;
+
+                        while (i < name.length()) {
+                            int j = i;
+                            for (; j < name.length(); j++) {
+                                char c = name.charAt(j);
+                                if (Character.toLowerCase(c) != c
+                                        && Character.toUpperCase(c) == c) {
+                                    break;
+                                }
+                            }
+                            if (j == name.length()) {
+                                out.append(name.substring(i));
+                            } else {
+                                out.append(name.substring(i, j));
+                                out.append(" " + name.charAt(j));
+                            }
+                            i = j + 1;
+                        }
+
+                        name = out.toString();
+                    }
+
+                    ((AbstractComponent) f).setCaption(name);
+                }
             }
             return f;
         } else {