Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
When |
|
| 1.6;1.6 |
1 | // Copyright 2004, 2005 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.contrib.components; |
|
16 | ||
17 | import org.apache.hivemind.ApplicationRuntimeException; |
|
18 | import org.apache.tapestry.IMarkupWriter; |
|
19 | import org.apache.tapestry.IRequestCycle; |
|
20 | import org.apache.tapestry.Tapestry; |
|
21 | import org.apache.tapestry.components.Conditional; |
|
22 | ||
23 | /** |
|
24 | * Represents an alternative whithin a {@link Choose} component. |
|
25 | * The default alternative is described by the Otherwise component. |
|
26 | * |
|
27 | * [<a href="../../../../../../ComponentReference/contrib.When.html">Component Reference</a>] |
|
28 | * |
|
29 | * @author David Solis |
|
30 | * |
|
31 | **/ |
|
32 | 0 | public abstract class When extends Conditional |
33 | { |
|
34 | /** Parent of this component. */ |
|
35 | ||
36 | private Choose _choose; |
|
37 | ||
38 | /** |
|
39 | * Renders its wrapped components only if the condition is true and its parent {@link Choose} |
|
40 | * allows it. In addition, if element is specified, can emulate that HTML element. |
|
41 | * |
|
42 | **/ |
|
43 | ||
44 | protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
45 | { |
|
46 | 0 | Choose choose = getChoose(); |
47 | ||
48 | 0 | if (choose == null) |
49 | 0 | throw new ApplicationRuntimeException( |
50 | Tapestry.getMessage("When.must-be-contained-by-choose"), |
|
51 | this, |
|
52 | null, |
|
53 | null); |
|
54 | ||
55 | 0 | if (!choose.isConditionMet() && getCondition()) |
56 | { |
|
57 | 0 | choose.setConditionMet(true); |
58 | 0 | super.renderComponent(writer, cycle); |
59 | } |
|
60 | 0 | } |
61 | ||
62 | protected boolean evaluateCondition() |
|
63 | { |
|
64 | 0 | return true; |
65 | } |
|
66 | ||
67 | public boolean getInvert() |
|
68 | { |
|
69 | // This component doesn't require invert parameter. |
|
70 | 0 | return false; |
71 | } |
|
72 | ||
73 | /** |
|
74 | * @return Choose |
|
75 | */ |
|
76 | public Choose getChoose() |
|
77 | { |
|
78 | 0 | return _choose; |
79 | } |
|
80 | ||
81 | /** |
|
82 | * Sets the choose. |
|
83 | * @param value The choose to set |
|
84 | */ |
|
85 | public void setChoose(Choose value) |
|
86 | { |
|
87 | 0 | _choose = value; |
88 | 0 | } |
89 | ||
90 | } |