KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > vlib > components > ColumnSorter


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

15 package org.apache.tapestry.vlib.components;
16
17 import org.apache.tapestry.BaseComponent;
18 import org.apache.tapestry.IActionListener;
19 import org.apache.tapestry.IRequestCycle;
20 import org.apache.tapestry.Tapestry;
21 import org.apache.tapestry.vlib.ejb.SortColumn;
22
23 /**
24  * Comopnent for allowing a column to be sorted.
25  *
26  * @author Howard Lewis Ship
27  * @version $Id: ColumnSorter.java,v 1.7 2004/02/19 17:38:04 hlship Exp $
28  * @since 3.0
29  *
30  **/

31
32 public abstract class ColumnSorter extends BaseComponent
33 {
34     public abstract SortColumn getSortColumn();
35
36     public abstract SortColumn getSelected();
37     public abstract void setSelected(SortColumn selected);
38
39     public abstract boolean isDescending();
40     public abstract void setDescending(boolean descending);
41
42     public abstract IActionListener getListener();
43
44     public void handleClick(IRequestCycle cycle)
45     {
46         SortColumn selected = getSelected();
47         SortColumn sortColumn = getSortColumn();
48
49         if (selected != sortColumn)
50         {
51             setSelected(sortColumn);
52             setDescending(false);
53         }
54         else
55         {
56             boolean current = isDescending();
57             setDescending(!current);
58         }
59
60         IActionListener listener = getListener();
61         if (listener == null)
62             throw Tapestry.createRequiredParameterException(this, "listener");
63
64         listener.actionTriggered(this, cycle);
65     }
66 }
67
Popular Tags