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: package org.apache.wicket.extensions.markup.html.repeater.util;
18:
19: import org.apache.wicket.IClusterable;
20: import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState;
21:
22: /**
23: * Implementation of ISortState that can keep track of sort information for a
24: * single property.
25: *
26: * @author Igor Vaynberg (ivaynberg)
27: *
28: */
29: public class SingleSortState implements ISortState, IClusterable {
30: private static final long serialVersionUID = 1L;
31:
32: SortParam param;
33:
34: /**
35: * @see org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState#setPropertySortOrder(java.lang.String,
36: * int)
37: */
38: public void setPropertySortOrder(String property, int dir) {
39: if (property == null) {
40: throw new IllegalArgumentException(
41: "argument [property] cannot be null");
42: }
43:
44: param = new SortParam(property, dir == ISortState.ASCENDING);
45: }
46:
47: /**
48: * @see org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState#getPropertySortOrder(java.lang.String)
49: */
50: public int getPropertySortOrder(String property) {
51: if (property == null) {
52: throw new IllegalArgumentException(
53: "argument [property] cannot be null");
54: }
55:
56: if (param == null || !param.getProperty().equals(property)) {
57: return NONE;
58: } else if (param.isAscending()) {
59: return ASCENDING;
60: } else {
61: return DESCENDING;
62: }
63:
64: }
65:
66: /**
67: * @return current sort state
68: */
69: public SortParam getSort() {
70: return param;
71: }
72:
73: /**
74: * Sets the current sort state
75: *
76: * @param param
77: * parameter containing new sorting information
78: */
79: public void setSort(SortParam param) {
80: this .param = param;
81: }
82:
83: /**
84: * @see java.lang.Object#toString()
85: */
86: public String toString() {
87: return "[SingleSortState sort="
88: + ((param == null) ? "null" : param.toString()) + "]";
89: }
90:
91: }
|