KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > databinding > datagrid > runtime > config > DefaultSortStrategy


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.databinding.datagrid.runtime.config;
19
20 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortDirection;
21 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortStrategy;
22 import org.apache.beehive.netui.util.Bundle;
23
24 /**
25  * <p>
26  * Default implementation of a {@link SortStrategy}. This class is used by the default data grid config
27  * object to provide a very simple state machine for cycling through sort directions as they
28  * are changed via URLs from a JSP.
29  * </p>
30  */

31 class DefaultSortStrategy
32     extends SortStrategy {
33
34     /**
35      * Package protected constructor.
36      */

37     DefaultSortStrategy() {
38     }
39
40     /**
41      * Get the default sort direction -- {@link SortDirection#ASCENDING}
42      * @return the default sort direction
43      */

44     public SortDirection getDefaultDirection() {
45         return SortDirection.ASCENDING;
46     }
47
48     /**
49      * <p>
50      * Given a sort direction, get the next sort direction. This implements a simple sort machine
51      * that cycles through the sort directions in the following order:
52      * <pre>
53      * SortDirection.NONE > SortDirection.ASCENDING > SortDirection.DESCENDING > repeat
54      * </pre>
55      * </p>
56      * @param direction the current {@link SortDirection}
57      * @return the next {@link SortDirection}
58      */

59     public SortDirection nextDirection(SortDirection direction) {
60         if(direction == SortDirection.NONE)
61             return SortDirection.ASCENDING;
62         else if(direction == SortDirection.ASCENDING)
63             return SortDirection.DESCENDING;
64         else if(direction == SortDirection.DESCENDING)
65             return SortDirection.NONE;
66         else throw new IllegalStateException JavaDoc(Bundle.getErrorString("SortStrategy_InvalidSortDirection", new Object JavaDoc[]{direction}));
67     }
68 }
69
Popular Tags