2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      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.shale.usecases.rolodex;
18  
19  import javax.faces.component.html.HtmlOutputText;
20  import javax.faces.context.FacesContext;
21  import javax.faces.el.ValueBinding;
22  
23  public class HeaderSorter extends HtmlOutputText {
24      private String sortBy = null;
25      private boolean sortAscending = true;
26      private String ascImage = null;
27      private String descImage = null;
28  
29  
30      /***
31       * <p>Sets the renderer type to "org.apache.shale.HeaderSorter".</p>
32       *
33       */
34      public HeaderSorter() {
35          setRendererType("org.apache.shale.HeaderSorter");
36      }
37      
38      /***
39       * <p>Sets the family to "org.apache.shale.Sorter".</p>
40       */
41      public String getFamily() {
42         return "org.apache.shale.Sorter";
43      }
44  
45      /***
46       * <p>Returns <code>true</code> if the component was selected.</p>
47       */
48      public boolean wasSelected() {
49          boolean selected = false;
50          if ((getId() != null) && getAttributes().get("defaultSort") != null) 
51              selected = (getAttributes().get("defaultSort").equals(getId()));
52          return selected;
53      }
54  
55      /***
56       * <p>Restores the component's state.</p>
57       */
58      public void restoreState(FacesContext facescontext, Object obj) {
59          Object[] sobj = (Object[]) obj;
60          super.restoreState(facescontext, sobj[0]);
61          
62          sortBy = (String) sobj[1];
63          ascImage = (String) sobj[2];
64          descImage = (String) sobj[3];
65          sortAscending = ((Boolean) sobj[4]).booleanValue();
66          sobj = null;
67  
68      }
69  
70      /***
71       * <p>Saves the component's state.</p>
72       */
73      public Object saveState(FacesContext facescontext) {
74  
75          Object aobj[] = new Object[5];
76          aobj[0] = super.saveState(facescontext);
77          aobj[1] = sortBy;
78          aobj[2] = ascImage;
79          aobj[3] = descImage;
80          aobj[4] = new Boolean(sortAscending);
81  
82          return aobj;
83      }
84  
85      /***
86       * <p>Returns a comma delimited list of properties to sort by.  The property names 
87       * are defined in the bean collection contained by the UIData model.</p>
88       */
89      public String getSortBy() {
90  
91          if (null != sortBy)
92              return sortBy;
93          ValueBinding valuebinding = getValueBinding("sortBy");
94          if (valuebinding != null)
95              return (String) valuebinding.getValue(getFacesContext());
96          else
97              return null;
98  
99      }
100 
101     /***
102      * <p>Sets a comma delimited list of properties to sort by.  The property names 
103      * are defined in the bean collection contained by the UIData model.</p>
104      */    
105     public void setSortBy(String s) {
106         sortBy = s;
107     }
108 
109     /***
110      * <p>Returns <code>true</code> if the model data is sorted in ascending order
111      * defined by the <code>sortBy</code> property.</p> 
112      */
113     public boolean isSortAscending() {
114         return sortAscending;
115     }
116 
117     /***
118      * <p>This setter toggles the collating sequence from ascending to descending.</p>
119      */
120     public void setSortAscending(boolean b) {
121         sortAscending = b;
122     }
123 
124     /***
125      * <p>Returns the acending image resource location that is relative to the
126      * context root.</p> 
127      */
128     public String getAscImage() {
129         return ascImage;
130     }
131 
132     /***
133      * <p>Returns the decending image resource location that is relative to the
134      * context root.</p> 
135      */   
136     public String getDescImage() {
137         return descImage;
138     }
139 
140     /***
141      * <p>Sets the acending image resource location that is relative to the
142      * context root.</p> 
143      */
144     public void setAscImage(String string) {
145         ascImage = string;
146     }
147 
148     /***
149      * <p>Sets the decending image resource location that is relative to the
150      * context root.</p> 
151      */   
152     public void setDescImage(String string) {
153         descImage = string;
154     }
155 
156 
157 }