01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.databinding.datagrid.runtime.config;
20:
21: import org.apache.beehive.netui.databinding.datagrid.api.sort.SortDirection;
22: import org.apache.beehive.netui.databinding.datagrid.api.sort.SortStrategy;
23: import org.apache.beehive.netui.util.Bundle;
24:
25: /**
26: * <p>
27: * Default implementation of a {@link SortStrategy}. This class is used by the default data grid config
28: * object to provide a very simple state machine for cycling through sort directions as they
29: * are changed via URLs from a JSP.
30: * </p>
31: */
32: class DefaultSortStrategy 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
67: throw new IllegalStateException(Bundle.getErrorString(
68: "SortStrategy_InvalidSortDirection",
69: new Object[] { direction }));
70: }
71: }
|