tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thiag...@apache.org
Subject [1/5] git commit: Closes #2305: @Sortable annotation
Date Wed, 30 Apr 2014 18:54:44 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 4458dc3aa -> 6f827cb98


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/da14f361
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/da14f361
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/da14f361

Branch: refs/heads/master
Commit: da14f36161a53e0fa4a673e17f7d3509379bdb72
Parents: 19b3960
Author: Thiago H. de Paula Figueiredo <thiagohp@apache.org>
Authored: Mon Mar 24 17:34:45 2014 -0300
Committer: Thiago H. de Paula Figueiredo <thiagohp@apache.org>
Committed: Mon Mar 24 17:34:45 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/da14f361/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/da14f361/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;
+        }
+        
+    }
+    
 }


Mime
View raw message