You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by th...@apache.org on 2014/05/24 21:18:39 UTC

[2/4] git commit: Closes #2305: @Sortable annotation

Closes #2305: @Sortable annotation


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/bc3f56fc
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/bc3f56fc
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/bc3f56fc

Branch: refs/heads/5.3
Commit: bc3f56fc3c8857276fa9908a09010acff8437178
Parents: 985675b
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Mon Mar 24 17:34:45 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
Committed: Sat May 24 15:52:13 2014 -0300

----------------------------------------------------------------------
 .../internal/beaneditor/PropertyModelImpl.java  | 22 +++++---
 .../services/BeanModelSourceImplTest.java       | 58 ++++++++++++++++++++
 2 files changed, 73 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bc3f56fc/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java
index e9ee3ec..3edfaff 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/beaneditor/PropertyModelImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2010, 2011 The Apache Software Foundation
+// Copyright 2007, 2008, 2010, 2011, 2014 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package org.apache.tapestry5.internal.beaneditor;
 import org.apache.tapestry5.PropertyConduit;
 import org.apache.tapestry5.beaneditor.BeanModel;
 import org.apache.tapestry5.beaneditor.PropertyModel;
+import org.apache.tapestry5.beaneditor.Sortable;
 import org.apache.tapestry5.internal.TapestryInternalUtils;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
@@ -51,12 +52,19 @@ public class PropertyModelImpl implements PropertyModel
 
         label = TapestryInternalUtils.defaultLabel(id, messages, name);
 
-        // Primitive types need to be converted to wrapper types before checking to see
-        // if they are sortable.
-
-        Class wrapperType = PlasticUtils.toWrapperType(getPropertyType());
-
-        sortable = Comparable.class.isAssignableFrom(wrapperType);
+        // TAP5-2305
+        Sortable sortableAnnotation = conduit.getAnnotation(Sortable.class);
+        if (sortableAnnotation != null) 
+        {
+            sortable = sortableAnnotation.value();
+        }
+        else
+        {
+            // Primitive types need to be converted to wrapper types before checking to see
+            // if they are sortable.
+            Class wrapperType = PlasticUtils.toWrapperType(getPropertyType());
+            sortable = Comparable.class.isAssignableFrom(wrapperType);
+        }
     }
 
     public String getId()

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bc3f56fc/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java
index 40300ed..17c9480 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BeanModelSourceImplTest.java
@@ -18,6 +18,7 @@ import org.apache.tapestry5.PropertyConduit;
 import org.apache.tapestry5.beaneditor.BeanModel;
 import org.apache.tapestry5.beaneditor.PropertyModel;
 import org.apache.tapestry5.beaneditor.RelativePosition;
+import org.apache.tapestry5.beaneditor.Sortable;
 import org.apache.tapestry5.internal.PropertyOrderBean;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.internal.transform.pages.ReadOnlyBean;
@@ -693,4 +694,61 @@ public class BeanModelSourceImplTest extends InternalBaseTestCase
 
         verify();
     }
+    
+    // https://issues.apache.org/jira/browse/TAP5-2305
+    @Test
+    public void sortable_annotation() 
+    {
+        Messages messages = mockMessages();
+
+        stub_contains(messages, false);
+
+        replay();
+
+        BeanModel<SortableBean> model = source.createDisplayModel(SortableBean.class,  messages);
+        model.add("nonSortableByDefault");
+        model.add("sortable");
+        
+        // checking whether non-@Sortable annotated properties still behave in the old ways
+        assertTrue(model.get("sortableByDefault").isSortable());
+        assertFalse(model.get("nonSortableByDefault").isSortable());
+        
+        // checking @Sortable itself
+        assertFalse(model.get("nonSortable").isSortable());
+        assertTrue(model.get("sortable").isSortable());
+
+        verify();
+    }
+    
+    final private static class SortableBean
+    {
+        private int sortableByDefault;
+        private int nonSortable;
+        private SimpleBean sortable;
+        private SimpleBean nonSortableByDefault;
+        
+        public int getSortableByDefault()
+        {
+            return sortableByDefault;
+        }
+        
+        @Sortable(false)
+        public int getNonSortable()
+        {
+            return nonSortable;
+        }
+        
+        @Sortable(true)
+        public SimpleBean getSortable()
+        {
+            return sortable;
+        }
+        
+        public SimpleBean getNonSortableByDefault()
+        {
+            return nonSortableByDefault;
+        }
+        
+    }
+    
 }