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.component;
21  
22  import org.apache.myfaces.tobago.internal.util.Deprecation;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  
27  public enum LabelLayout {
28  
29    /**
30     * do not render the label - same behavior as component without label attribute
31     */
32    none,
33  
34    /**
35     * flex layout: let the label be on the left side
36     */
37    flexLeft,
38  
39    /**
40     * flex layout: let the label be on the right side
41     */
42    flexRight,
43  
44    /**
45     * let the label be on the top of the element
46     */
47    top,
48  
49    /**
50     * segment layout: let the label be on the left side
51     */
52    segmentLeft,
53  
54    /**
55     * segment layout: let the label be on the right side
56     */
57    segmentRight,
58  
59    /**
60     * flow layout: let the label be on the left side
61     */
62    flowLeft,
63  
64    /**
65     * flow layout: let the label be on the right side
66     */
67    flowRight,
68  
69    /**
70     * skip rendering the surrounding container.
71     *
72     * @deprecated since 5.0.0, not needed, because there is no surrounding container.
73     */
74    @Deprecated
75    skip,
76  
77    /**
78     * grid layout: let the label be on the left cell and the input on the right cell. It uses 2 cells instead of one.
79     */
80    gridLeft,
81  
82    /**
83     * grid layout: let the label be on the right cell and the input on the left cell. It uses 2 cells instead of one.
84     */
85    gridRight,
86  
87    /**
88     * grid layout: let the label be on the top cell and the input on the bottom cell. It uses 2 cells instead of one.
89     */
90    gridTop,
91  
92    /**
93     * grid layout: let the label be on the bottom cell and the input on the top cell. It uses 2 cells instead of one.
94     */
95    gridBottom;
96  
97    private static final String SEGMENT_TO_RENDER_KEY = LabelLayout.class.getName();
98  
99    public static boolean isSegment(final LabelLayout labelLayout) {
100     return labelLayout == segmentLeft || labelLayout == segmentRight;
101   }
102 
103   /**
104    * @deprecated since 5.0.0. Please use {@link SupportsLabelLayout#setNextToRenderIsLabel(boolean)}.
105    */
106   @Deprecated
107   public static void setSegment(final FacesContext facesContext, final LabelLayout labelLayout) {
108     Deprecation.LOG.error("not longer supported - see javadoc");
109   }
110 
111   /**
112    * @deprecated since 5.0.0. Please use {@link SupportsLabelLayout#isNextToRenderIsLabel()}.
113    */
114   @Deprecated
115   public static LabelLayout getSegment(final FacesContext facesContext) {
116     Deprecation.LOG.error("not longer supported - see javadoc");
117     return null;
118   }
119 
120   public static void removeSegment(final FacesContext facesContext) {
121     facesContext.getAttributes().remove(SEGMENT_TO_RENDER_KEY);
122   }
123 
124   public static boolean isGridLeft(final UIComponent component) {
125     return component instanceof SupportsLabelLayout
126         && ((SupportsLabelLayout) component).getLabelLayout() == LabelLayout.gridLeft;
127   }
128 
129   public static boolean isGridRight(final UIComponent component) {
130     return component instanceof SupportsLabelLayout
131         && ((SupportsLabelLayout) component).getLabelLayout() == LabelLayout.gridRight;
132   }
133 
134   public static boolean isGridTop(final UIComponent component) {
135     return component instanceof SupportsLabelLayout
136         && ((SupportsLabelLayout) component).getLabelLayout() == LabelLayout.gridTop;
137   }
138 
139   public static boolean isGridBottom(final UIComponent component) {
140     return component instanceof SupportsLabelLayout
141         && ((SupportsLabelLayout) component).getLabelLayout() == LabelLayout.gridBottom;
142   }
143 }