View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.custom.accordion;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import javax.faces.context.FacesContext;
25  
26  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
27  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
28  import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
29  
30  
31  /**
32   * A group of panels, which can be opened and closed. See attribute layout for 
33   * further description on how opening and closing works. 
34   * 
35   * Extends standard panelGroup by user role support.
36   * 
37   *   
38   * @author Martin Marinschek
39   * @version $Revision: 663481 $ $Date: 2008-06-05 02:00:34 -0500 (jue, 05 jun 2008) $
40   *          <p/>
41   */
42  @JSFComponent(
43     name = "s:accordionPanel",
44     clazz = "org.apache.myfaces.custom.accordion.HtmlAccordionPanel",
45     tagClass = "org.apache.myfaces.custom.accordion.HtmlAccordionPanelTag")
46  public abstract class AbstractHtmlAccordionPanel extends HtmlPanelGroup
47  {
48      public static String ACCORDION_LAYOUT = "accordion";
49      public static String TOGGLING_LAYOUT = "toggling";
50  
51      public static String EXPANDED_BACK_COLOR = "expandedBg";
52      public static String EXPANDED_TEXT_COLOR = "expandedTextColor";
53      public static String EXPANDED_FONT_WEIGHT = "expandedFontWeight";
54      public static String COLLAPSED_BACK_COLOR = "collapsedBg";
55      public static String COLLAPSED_TEXT_COLOR = "collapsedTextColor";
56      public static String COLLAPSED_FONT_WEIGHT = "collapsedFontWeight";
57      public static String HOVER_BACK_COLOR = "hoverBg";
58      public static String HOVER_TEXT_COLOR = "hoverTextColor";
59      public static String BORDER_COLOR = "borderColor";
60  
61      public static String EXPAND_STATEHOLDER_ID = "_STATEHOLDER";
62  
63      public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlAccordionPanel";
64      public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.AccordionPanel";
65  
66      //expansionstate of children
67      private List _childExpanded;
68  
69      public Object saveState(FacesContext context)
70      {
71          Object[] values = new Object[2];
72          values[0] = super.saveState(context);
73          values[1] = _childExpanded;
74  
75          return values;
76      }
77  
78      public void restoreState(FacesContext context, Object state)
79      {
80          Object values[] = (Object[])state;
81          super.restoreState(context, values[0]);
82          _childExpanded = (List) values[1];
83      }
84  
85      /**
86       * Defines the layout of this accordionPanel. If you set this to 
87       * 'accordion', opening a panel will close all other panels. 
88       * If you set this to 'toggling', opening a panel doesn't 
89       * affect the state of the other panels. You can close 
90       * a panel by clicking on the header of this panel a second time.
91       * 
92       */
93      @JSFProperty(defaultValue="accordion")
94      public abstract String getLayout();
95  
96      /**
97       * Defines the background color for expanded state.
98       * 
99       */
100     @JSFProperty
101     public abstract String getExpandedBackColor();
102 
103     /**
104      * Defines the text color for expanded state.
105      * 
106      */
107     @JSFProperty
108     public abstract String getExpandedTextColor();
109 
110     /**
111      * Defines the font weight for expanded state.
112      * 
113      */
114     @JSFProperty
115     public abstract String getExpandedFontWeight();
116 
117     /**
118      * Defines the background color for collapsed state.
119      * 
120      */
121     @JSFProperty
122     public abstract String getCollapsedBackColor();
123 
124     /**
125      * Defines the text color for collapsed state.
126      * 
127      */
128     @JSFProperty
129     public abstract String getCollapsedTextColor();
130 
131     /**
132      * Defines the font weight for collapsed state.
133      * 
134      */
135     @JSFProperty
136     public abstract String getCollapsedFontWeight();
137 
138     /**
139      * Defines the background color on hover.
140      * 
141      */
142     @JSFProperty
143     public abstract String getHoverBackColor();
144 
145     /**
146      * Defines the text color on hover.
147      * 
148      */
149     @JSFProperty
150     public abstract String getHoverTextColor();
151 
152     /**
153      * Defines the color of the border.
154      * 
155      */
156     @JSFProperty
157     public abstract String getBorderColor();
158 
159     //TODO
160     public List getChildExpanded()
161     {
162         if(_childExpanded == null)
163         {
164             _childExpanded = new ArrayList(getChildCount());
165             for(int i = 0; i < getChildCount(); i++)
166             {
167                 Integer curState = new Integer(i == 0 ? 1 : 0);
168                 _childExpanded.add(curState);
169             }
170         }
171         return _childExpanded;
172     }
173 
174 
175     public void setChildExpanded(List childExpanded)
176     {
177         _childExpanded = childExpanded;
178     }
179 }