Repository: incubator-juneau
Updated Branches:
  refs/heads/master 14f6d2fbe -> 9b3949297


Improvements to PojoQuery and QueryWidget.

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/9b394929
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/9b394929
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/9b394929

Branch: refs/heads/master
Commit: 9b3949297a409988d3a8fb1c741a9cf93fc02d12
Parents: 14f6d2f
Author: JamesBognar <[email protected]>
Authored: Mon Jun 19 14:58:51 2017 -0400
Committer: JamesBognar <[email protected]>
Committed: Mon Jun 19 15:01:16 2017 -0400

----------------------------------------------------------------------
 .../java/org/apache/juneau/utils/PojoQuery.java | 33 +++++++++++++++++++-
 .../apache/juneau/rest/widget/QueryWidget.html  | 15 +++++----
 2 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9b394929/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java 
b/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java
index a4566e5..737fb32 100644
--- a/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java
+++ b/juneau-core/src/main/java/org/apache/juneau/utils/PojoQuery.java
@@ -15,6 +15,7 @@ package org.apache.juneau.utils;
 import static java.util.Calendar.*;
 import static org.apache.juneau.internal.StringUtils.*;
 
+import java.lang.reflect.*;
 import java.text.*;
 import java.util.*;
 import java.util.regex.*;
@@ -300,7 +301,7 @@ public final class PojoQuery {
                        Comparator comp = new Comparator<Map>() {
                                @Override /* Comparator */
                                public int compare(Map m1, Map m2) {
-                                       Comparable v1 = (Comparable)m1.get(c), 
v2 = (Comparable)m2.get(c);
+                                       Comparable v1 = 
toComparable(m1.get(c)), v2 = toComparable(m2.get(c));
                                        if (v1 == null && v2 == null)
                                                return 0;
                                        if (v1 == null)
@@ -314,6 +315,18 @@ public final class PojoQuery {
                }
        }
 
+       private static Comparable toComparable(Object o) {
+               if (o == null)
+                       return null;
+               if (o instanceof Comparable)
+                       return (Comparable)o;
+               if (o instanceof Map)
+                       return ((Map)o).size();
+               if (o.getClass().isArray())
+                       return Array.getLength(o);
+               return o.toString();
+       }
+
        /*
         * Filters all but the specified view columns on all entries in the 
specified list.
         */
@@ -423,6 +436,24 @@ public final class PojoQuery {
 
                @Override /* IMatcher */
                public boolean matches(Object o) {
+                       if (o instanceof Collection) {
+                               for (Object o2 : (Collection)o)
+                                       if (matches(o2))
+                                               return true;
+                               return false;
+                       }
+                       if (o != null && o.getClass().isArray()) {
+                               for (int i = 0; i < Array.getLength(o); i++)
+                                       if (matches(Array.get(o, i)))
+                                               return true;
+                               return false;
+                       }
+                       if (o instanceof Map) {
+                               for (Object o2 : ((Map)o).values())
+                                       if (matches(o2))
+                                               return true;
+                               return false;
+                       }
                        if (o instanceof Number)
                                return getNumberMatcher().matches(o);
                        if (o instanceof Date || o instanceof Calendar)

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9b394929/juneau-rest/src/main/resources/org/apache/juneau/rest/widget/QueryWidget.html
----------------------------------------------------------------------
diff --git 
a/juneau-rest/src/main/resources/org/apache/juneau/rest/widget/QueryWidget.html 
b/juneau-rest/src/main/resources/org/apache/juneau/rest/widget/QueryWidget.html
index 66ae23a..02c4adf 100644
--- 
a/juneau-rest/src/main/resources/org/apache/juneau/rest/widget/QueryWidget.html
+++ 
b/juneau-rest/src/main/resources/org/apache/juneau/rest/widget/QueryWidget.html
@@ -26,7 +26,7 @@
        color: #26343F;
        white-space: nowrap;
        text-align: left;
-       margin:20px;
+       margin:70px 50px;
        }
 
        .hidden {
@@ -64,8 +64,6 @@
                white-space: nowrap;
                float: left;
        }
-}
-
 </style>
 <form id='queryForm' style='display:inline'>
        <table id='query' class='queryInput hidden'>
@@ -83,7 +81,7 @@
                                </div>
                        </th>
                        <td>
-                               <input name="s" size="50">
+                               <input name="s" size="50" value='$R{query.s}'>
                        </td>
                </tr>
                <tr>
@@ -97,7 +95,7 @@
                                </div>
                        </th>
                        <td>
-                               <input name="v" size="50">
+                               <input name="v" size="50" value='$R{query.v}'>
                        </td>
                </tr>
                <tr>
@@ -112,7 +110,7 @@
                                </div>
                        </th>
                        <td>
-                               <input name="o" size="50">
+                               <input name="o" size="50" value='$R{query.o}'>
                        </td>
                </tr>
                <tr>
@@ -120,8 +118,8 @@
                                Page:
                        </th>
                        <td>
-                               Position: <input name='p' type='number' 
style='width:50px' step=20 min=0 value='0'>
-                               Limit: <input name='l' type='number' 
style='width:50px' step=20 min=0 value='0'>
+                               Position: <input name='p' type='number' 
style='width:50px' step=20 min=0 value='$R{query.p}'>
+                               Limit: <input name='l' type='number' 
style='width:50px' step=20 min=0 value='$R{query.l}'>
                                Ignore-case: <input name='i' type='checkbox' 
value='true'>
                        </td>
                </tr>
@@ -130,6 +128,7 @@
                                &nbsp;
                        </th>
                        <td style='float:right'>
+                               <input type='reset' value='Reset'>
                                <input type='button' value='Cancel' 
onclick='getElementById("query").classList.add("hidden")'>
                                <input type="submit" value='Submit'>
                        </td>

Reply via email to