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  
20  package org.apache.myfaces.tobago.internal.component;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  import org.apache.myfaces.tobago.component.Facets;
24  import org.apache.myfaces.tobago.model.CollapseMode;
25  
26  import javax.el.ValueExpression;
27  import javax.faces.component.UIComponent;
28  import javax.faces.context.FacesContext;
29  
30  /**
31   * Base class for collapsible panels.
32   */
33  public abstract class AbstractUICollapsiblePanel extends AbstractUIPanelBase {
34  
35    private transient Boolean submittedCollapsed;
36  
37    @Override
38    public void processDecodes(final FacesContext facesContext) {
39      if (isNormalLifecycle()) {
40        super.processDecodes(facesContext);
41      } else {
42        decode(facesContext);
43        final UIComponent bar = getFacet(Facets.BAR); // XXX is from Box or Section
44        if (bar != null) {
45          bar.processDecodes(facesContext);
46        }
47        final UIComponent label = getFacet(Facets.LABEL); // XXX is from Box or Section
48        if (label != null) {
49          label.processDecodes(facesContext);
50        }
51      }
52    }
53  
54    @Override
55    public void processValidators(final FacesContext facesContext) {
56      if (isNormalLifecycle()) {
57        super.processValidators(facesContext);
58      } else {
59        final UIComponent bar = getFacet(Facets.BAR); // XXX is from Box or Section
60        if (bar != null) {
61          bar.processValidators(facesContext);
62        }
63        final UIComponent label = getFacet(Facets.LABEL); // XXX is from Box or Section
64        if (label != null) {
65          label.processValidators(facesContext);
66        }
67      }
68    }
69  
70    @Override
71    public void processUpdates(final FacesContext facesContext) {
72      if (isNormalLifecycle()) {
73        super.processUpdates(facesContext);
74      } else {
75        final UIComponent bar = getFacet(Facets.BAR); // XXX is from Box or Section
76        if (bar != null) {
77          bar.processUpdates(facesContext);
78        }
79        final UIComponent label = getFacet(Facets.LABEL); // XXX is from Box or Section
80        if (label != null) {
81          label.processUpdates(facesContext);
82        }
83      }
84    }
85  
86    public boolean isNormalLifecycle() {
87      return getCollapsedMode() == CollapseMode.hidden || !isCollapsed();
88    }
89  
90    public abstract boolean isCollapsed();
91  
92    public abstract void setCollapsed(final boolean collapsed);
93  
94    public abstract CollapseMode getCollapsedMode();
95  
96    public void setSubmittedCollapsed(final Boolean submittedCollapsed) {
97      this.submittedCollapsed = submittedCollapsed;
98    }
99  
100   public void processState() {
101     if (submittedCollapsed != null) {
102       final ValueExpression valueExpression = getValueExpression(Attributes.collapsed.name());
103       if (valueExpression != null) {
104         valueExpression.setValue(FacesContext.getCurrentInstance().getELContext(), submittedCollapsed);
105       } else {
106         setCollapsed(submittedCollapsed);
107       }
108       submittedCollapsed = null;
109     }
110   }
111 }