KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tag > panel > ShowTag


1 /**
2  * May 1, 2006
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.tag.panel;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21
22 import net.sf.uitags.tag.AbstractUiTag;
23 import net.sf.uitags.tagutil.TaglibProperties;
24 import net.sf.uitags.tagutil.validation.DeferredValidationException;
25 import net.sf.uitags.tagutil.validation.RuntimeValidator;
26 import net.sf.uitags.util.StringUtils;
27 import net.sf.uitags.util.Template;
28
29 /**
30  * Injects panel hide capability in response to a certain event.
31  *
32  * @author hgani
33  * @version $Id$
34  */

35 public class ShowTag extends AbstractUiTag {
36
37   ///////////////////////////////
38
////////// Constants //////////
39
///////////////////////////////
40

41   /**
42    * Serial Version UID.
43    */

44   private static final long serialVersionUID = 100L;
45
46
47   ///////////////////////////////////////////////
48
////////// Property keys (constants) //////////
49
///////////////////////////////////////////////
50

51   private static final String JavaDoc PROP_EVENT = "panel.show.on";
52   private static final String JavaDoc PROP_DELAY = "panel.show.delay";
53   private static final String JavaDoc PROP_POSITION = "panel.show.position";
54
55
56   ////////////////////////////
57
////////// Fields //////////
58
////////////////////////////
59

60   /**
61    * The 'injectTo' tag attribute.
62    */

63   private String JavaDoc injectTo;
64
65   /**
66    * The 'injectToName' tag attribute.
67    */

68   private String JavaDoc injectToName;
69
70   /**
71    * The "on" tag attribute
72    */

73   private String JavaDoc on;
74
75   /**
76    * The "delay" tag attribute
77    */

78   private Integer JavaDoc delayInMillis;
79
80   /**
81    * The "position" tag attribute
82    */

83   private String JavaDoc position;
84
85
86   ///////////////////////////////////////////
87
////////// Tag attribute setters //////////
88
///////////////////////////////////////////
89

90   /**
91    * Tag attribute setter.
92    *
93    * @param val value of the tag attribute
94    */

95   public void setInjectTo(String JavaDoc val) {
96     this.injectTo = val;
97   }
98
99   /**
100    * Tag attribute setter.
101    *
102    * @param val value of the tag attribute
103    */

104   public void setInjectToName(String JavaDoc val) {
105     this.injectToName = val;
106   }
107
108   /**
109    * Tag attribute setter.
110    *
111    * @param val value of the tag attribute
112    */

113   public void setOn(String JavaDoc val) {
114     this.on = val;
115   }
116
117   /**
118    * Tag attribute setter.
119    *
120    * @param val value of the tag attribute
121    */

122   public void setDelay(Integer JavaDoc val) {
123     this.delayInMillis = val;
124   }
125
126   /**
127    * Tag attribute setter.
128    *
129    * @param val value of the tag attribute
130    */

131   public void setPosition(String JavaDoc position) {
132     this.position = position;
133   }
134
135
136   ///////////////////////////////
137
////////// Tag logic //////////
138
///////////////////////////////
139

140   /**
141    * Instructs web container to skip the tag's body.
142    *
143    * @see javax.servlet.jsp.tagext.Tag#doStartTag()
144    * @return <code>SKIP_BODY</code>
145    * @throws JspException to communicate error
146    */

147   public int doStartTag() throws JspException JavaDoc {
148     return SKIP_BODY;
149   }
150
151   /**
152    * Renders the HTML code for showing a panel.
153    *
154    * @see javax.servlet.jsp.tagext.Tag#doEndTag()
155    * @return <code>EVAL_PAGE</code>
156    * @throws JspException to communicate error
157    */

158   public int doEndTag() throws JspException JavaDoc {
159     RuntimeValidator.assertAttributeExclusive(
160         "injectTo", this.injectTo, "injectToName", this.injectToName);
161     RuntimeValidator.assertEitherSpecified(
162         "injectTo", this.injectTo, "injectToName", this.injectToName);
163
164     TaglibProperties props = TaglibProperties.getInstance();
165     props.setRuntimeProperty(PROP_EVENT, this.on);
166     props.setRuntimeProperty(PROP_DELAY, StringUtils.toStringOrNull(this.delayInMillis));
167     props.setRuntimeProperty(PROP_POSITION, this.position);
168
169     Template tpl = Template.forName(Template.PANEL_SHOW);
170     tpl.map("triggerId", this.injectTo);
171     tpl.map("triggerName", this.injectToName);
172     tpl.map("triggerEvent", props.get(PROP_EVENT));
173     tpl.map("delayInMillis", Integer.valueOf(props.get(PROP_DELAY)));
174     tpl.map("attachedToMouse", isAttachedToMouse(props.get(PROP_POSITION)));
175
176     PanelTag parent = (PanelTag) findParent(PanelTag.class);
177     parent.addChildJsCode(tpl.evalToString());
178
179     return EVAL_PAGE;
180   }
181   
182   private Boolean JavaDoc isAttachedToMouse(String JavaDoc positionValue) {
183     if ("auto".equals(positionValue)) {
184       return Boolean.FALSE;
185     }
186     else if ("mouse".equals(positionValue)) {
187       return Boolean.TRUE;
188     }
189     else {
190       throw new DeferredValidationException(
191           "Position attribute must be either 'auto' or 'mouse'. Provided: '" +
192           positionValue + "'.");
193     }
194   }
195 }
196
Popular Tags