You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/09/10 07:31:23 UTC

svn commit: r574132 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/beaneditor/ main/java/org/apache/tapestry/internal/beaneditor/ test/java/org/apache/tapestry/internal/services/

Author: hlship
Date: Sun Sep  9 22:31:22 2007
New Revision: 574132

URL: http://svn.apache.org/viewvc?rev=574132&view=rev
Log:
TAPESTRY-1471: Controlling the order of properties within a BeanModel is too complex and needs an improved API

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/BeanModel.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/BeanModelImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/BeanModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/BeanModel.java?rev=574132&r1=574131&r2=574132&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/BeanModel.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/BeanModel.java Sun Sep  9 22:31:22 2007
@@ -119,4 +119,14 @@
      * @return the model for further modifications
      */
     BeanModel remove(String... propertyName);
+
+    /**
+     * Re-orders the properties of the model into the specified order. Existing properties that are
+     * not indicated are retained, but ordered to the end of the list.
+     * 
+     * @param propertyName
+     *            property names in order they should be displayed (case insensitive)
+     * @return the model for further modifications
+     */
+    BeanModel reorder(String... propertyName);
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/BeanModelImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/BeanModelImpl.java?rev=574132&r1=574131&r2=574132&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/BeanModelImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/BeanModelImpl.java Sun Sep  9 22:31:22 2007
@@ -15,6 +15,7 @@
 package org.apache.tapestry.internal.beaneditor;
 
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newCaseInsensitiveMap;
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
 import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
 import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
 
@@ -168,6 +169,32 @@
 
             _properties.remove(propertyName);
         }
+
+        return this;
+    }
+
+    public BeanModel reorder(String... propertyName)
+    {
+        List<String> remainingPropertyNames = newList(_propertyNames);
+        List<String> reorderedPropertyNames = newList();
+
+        for (String name : propertyName)
+        {
+            PropertyModel model = get(name);
+
+            // Get the canonical form (which may differ from name in terms of case)
+            String canonical = model.getPropertyName();
+
+            reorderedPropertyNames.add(canonical);
+
+            remainingPropertyNames.remove(canonical);
+        }
+
+        _propertyNames.clear();
+        _propertyNames.addAll(reorderedPropertyNames);
+
+        // Any unspecified names are ordered to the end. Don't want them? Remove them instead.
+        _propertyNames.addAll(remainingPropertyNames);
 
         return this;
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java?rev=574132&r1=574131&r2=574132&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java Sun Sep  9 22:31:22 2007
@@ -545,4 +545,34 @@
 
         verify();
     }
+
+    @Test
+    public void reorder()
+    {
+        ComponentResources resources = mockComponentResources();
+        Messages messages = mockMessages();
+
+        train_getMessages(resources, messages);
+        stub_contains(messages, false);
+
+        replay();
+
+        BeanModel model = _source.create(SimpleBean.class, true, resources);
+
+        assertSame(model.getBeanType(), SimpleBean.class);
+
+        // Based on order of the getter methods (no longer alphabetical)
+
+        assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
+
+        // Testing a couple of things here:
+        // 1) case insensitive
+        // 2) unreferenced property names added to the end.
+        
+        model.reorder("lastname", "AGE");
+
+        assertEquals(model.getPropertyNames(), Arrays.asList("lastName", "age", "firstName"));
+
+        verify();
+    }
 }