Source Code Cross Referenced for SortModel.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » databinding » datagrid » api » sort » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache beehive 1.0.2 src » org.apache.beehive.netui.databinding.datagrid.api.sort 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         *
017:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.databinding.datagrid.api.sort;
020:
021:        import java.util.List;
022:        import org.apache.beehive.netui.databinding.datagrid.api.sort.SortDirection;
023:
024:        /**
025:         * <p>
026:         * The SortModel class groups a set of {@link Sort} objects.  This class also provides a set of methods
027:         * for interacting with a group of {@link Sort} objects.
028:         * </p>
029:         * <p>
030:         * The list of {@link Sort} objects in a SortModel are ordered.  The first sort in group is known as the
031:         * "primary" sort and subsequent Sorts are "secondary".  The interpretation of using Sorts into
032:         * to order a data set is left to implementations of sort algoritms.  For example, one possible
033:         * sort implementation could order the sorts such that the secondary sort occurs inside the
034:         * data ordered by the primary sort and so on.
035:         * </p>
036:         * <p>
037:         * In addition to accessing the Sort objects, the SortModel provides a the ability to plug a simple state
038:         * machine that controls how to change a sort direction when cycling through the set of sort directions.
039:         * For example, when using a data grid to sort columns of data, a column may start off unsorted,
040:         * change to {@link SortDirection#ASCENDING}, to {@link SortDirection#DESCENDING}, and finally back to
041:         * {@link SortDirection#NONE}.  The {@link SortStrategy} allows this strategy to be changed so that the
042:         * sorts can change from {@link SortDirection#NONE} to {@link SortDirection#DESCENDING}, to
043:         * {@link SortDirection#ASCENDING}, and finally back to {@link SortDirection#NONE}.
044:         * </p>
045:         */
046:        public class SortModel implements  java.io.Serializable {
047:
048:            /* todo: consider exposing a Map getSortMap() that would be JSP 2.0 EL bindable */
049:            /* todo: expose a convenience method to change the direction of a sort */
050:
051:            private SortStrategy _sortStrategy = null;
052:            private List/*<Sort>*/_sorts = null;
053:
054:            /**
055:             * Construct the SortModel with a {@link List} of sorts.
056:             * @param sorts the sorts
057:             */
058:            public SortModel(List/*<Sort>*/sorts) {
059:                _sorts = sorts;
060:            }
061:
062:            /**
063:             * Get the {@link SortStrategy} used to cycle these {@link Sort} objects through various
064:             * {@link SortDirection}s.
065:             * @return the {@link SortStrategy}
066:             */
067:            public SortStrategy getSortStrategy() {
068:                return _sortStrategy;
069:            }
070:
071:            /**
072:             * Set the {@link SortStrategy}.
073:             * @param sortStrategy the new {@link SortStrategy}
074:             */
075:            public void setSortStrategy(SortStrategy sortStrategy) {
076:                _sortStrategy = sortStrategy;
077:            }
078:
079:            public List/*<Sort>*/getSorts() {
080:                if (_sorts == null)
081:                    return null;
082:                else
083:                    return _sorts;
084:            }
085:
086:            /**
087:             * Check to see if a sort expression is the first {@link Sort} in the {@link SortModel}.  If the
088:             * first {@link Sort} in the SortModel has a {@link Sort#getSortExpression()} that matches the
089:             * <code>sortExpression</code> parameter, the method returns <code>true</code>.  Otherwise, it
090:             * returns <code>false</code>.
091:             *
092:             * @param sortExpression the sort expression to use when checking the SortModel's first {@link Sort}
093:             * @return <code>true</code> if the first {@link Sort} has a sortExpression that matches the
094:             * sortExpression parameter.  <code>false</code> otherwise.
095:             */
096:            public boolean isPrimarySort(String sortExpression) {
097:                if (sortExpression == null)
098:                    return false;
099:
100:                /* optimizing for the case where the sortExpression *is* the primary sort */
101:                if (_sorts != null
102:                        && _sorts.size() > 0
103:                        && ((Sort) _sorts.get(0)).getSortExpression().equals(
104:                                sortExpression)) {
105:                    return true;
106:                } else
107:                    return false;
108:            }
109:
110:            /**
111:             * Check to see if the SortModel contains a {@link Sort} whose sort expression matches the given
112:             * <code>sortExpression</code>.
113:             *
114:             * @param sortExpression the sortExpression used to locate a {@link Sort}
115:             * @return <code>true</code> if a {@link Sort} is found whose {@link Sort#getSortExpression()} matches
116:             * the given <code>sortExpression</code>.  <code>false</code> otherwise.
117:             */
118:            public boolean isSorted(String sortExpression) {
119:                if (sortExpression == null)
120:                    return false;
121:
122:                Sort term = findSort(sortExpression);
123:                if (term == null || term.getDirection() == SortDirection.NONE)
124:                    return false;
125:                else
126:                    return true;
127:            }
128:
129:            /**
130:             * Get the {@link SortDirection} for a {@link Sort} given a sort expression.
131:             *
132:             * @param sortExpression the sort expression used to locate a {@link Sort} object.
133:             * @return a {@link Sort}'s {@link SortDirection} if one is found whose <code>sortExpression</code>
134:             * property matches the given <code>sortExpression</code>.  <code>null</code> otherwise. 
135:             */
136:            public SortDirection getSortDirection(String sortExpression) {
137:                Sort term = findSort(sortExpression);
138:                return term == null ? SortDirection.NONE : term.getDirection();
139:            }
140:
141:            /**
142:             * Lookup a {@link Sort} object whose {@link Sort#getSortExpression()} matches
143:             * the given <code>sortExpression</code>.
144:             *
145:             * @param sortExpression the sortExpression used to locate a {@link Sort}
146:             * @return a {@link Sort} if one is found whose <code>sortExpression</code> property matches
147:             * the given <code>sortExpression</code>.  <code>null</code> otherwise.
148:             */
149:            public Sort lookupSort(String sortExpression) {
150:                return findSort(sortExpression);
151:            }
152:
153:            private final Sort findSort(String sortExpression) {
154:                if (_sorts == null)
155:                    return null;
156:
157:                for (int i = 0; i < _sorts.size(); i++) {
158:                    assert _sorts.get(i) instanceof  Sort;
159:                    Sort sort = (Sort) _sorts.get(i);
160:                    if (sort.getSortExpression().equals(sortExpression))
161:                        return sort;
162:                }
163:
164:                return null;
165:            }
166:        }
w___ww._ja_v___a___2_s_._co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.