View Javadoc

1   /*
2       Jiffie Plugin for Jameleon - An Internet Explorer plug-in for Jameleon
3       Copyright (C) 2004-2006 Christian W. Hargraves (engrean@hotmail.com) and
4                          Matthias Marschall (matthias@marschalls.de)
5   
6       This program is free software; you can redistribute it and/or modify
7       it under the terms of the GNU General Public License as published by
8       the Free Software Foundation; either version 2 of the License, or
9       (at your option) any later version.
10  
11      This program is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14      GNU General Public License for more details.
15  
16      You should have received a copy of the GNU General Public License
17      along with this program; if not, write to the Free Software
18      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  package net.sf.jameleon.plugin.jiffie.tags;
21  import net.sf.jiffie.IHTMLInputElement;
22  
23  /***
24   * This action point checks any checkbox in a form or not.
25   * 
26   * Some example uses might be:
27   * 
28   * Checking <input type="checkbox" name="checkBox1" value="one"</a>
29   * <pre><source>
30   *  &lt;ie-set-checkbox functionId="Set a checkbox in a given form to checked" 
31   *       name="checkBox1" 
32   *       checked="true"
33   *       form="testForm"/&gt;
34   * </source></pre>
35   *
36   * Checking &lt;input type="checkbox" name="checkBox1" value="one"&lt;/a&gt; that doesn't exist in a form
37   * <pre><source>
38   *  &lt;ie-set-checkbox functionId="Set a checkbox in a given form to checked" 
39   *       name="checkBox1" 
40   *       checked="true"/&gt;
41   * </source></pre>
42   *
43   * Unchecking &lt;input type="checkbox" name="checkBox3"&lt;/a&gt;
44   * <pre><source>
45   *  &lt;ie-set-checkbox functionId="Uncheck a given checkbox" 
46   *       name="checkBox3" 
47   *       checked="false"
48           form="testForm"/&gt;
49   * </source></pre>
50   *
51   * Checking a checkbox with the same name, but different value: 
52   * &lt;input type="checkbox" name="cb1" value="1"&lt;/a&gt;&lt;input type="checkbox" name="cb1" value="2"&lt;/a&gt;
53   * <pre><source>
54   *  &lt;ie-set-checkbox functionId="Ckeck a checkbox 'cb1' with the value '1'. Notice that two checkboxes have the same name." 
55   *       name="cb1" 
56   *       value="1"
57   *       checked="true"
58   *       form="testForm"/&gt;
59   * </source></pre>
60   * NOTE: <b>This tag does not currently support the xpath attribute nor the nested ie-attribute tags.</b>
61   * @jameleon.function name="ie-set-checkbox" type="action"
62   * @jameleon.step Find the given form and set it as the working form
63   * @jameleon.step Find the given checkbox and set it to checked (checked=true) or unchecked (checked=false)
64   */
65  public class IESetCheckboxTag extends IEFireEventTag {
66  
67      /***
68       * The name of the checkbox field
69       * @jameleon.attribute required="true" contextName="ieSetCheckboxName"
70       */
71      protected String name;
72      /***
73       * The value of the checkbox field. If set, then the name and value are used to 
74       * identify the checkbox to check or uncheck
75       * @jameleon.attribute required="false" contextName="ieSetCheckboxValue"
76       */
77      protected String value;
78      /***
79       * Check the checkbox if set to true; uncheck the checkbox if set to false.
80       * @jameleon.attribute required="true" contextName="ieSetCheckboxValue"
81       */
82      protected boolean checked;
83      /***
84       * The name, id or index of the field
85       * @jameleon.attribute contextName="ieSetCheckboxForm"
86       */
87      protected String form;
88  
89      public void testBlock() {
90          if (htmlElement != null ||
91              xpath != null ||
92              getParamLength() > 0) {
93              throw new RuntimeException("htmlElement, xpath and ie-attribute are not supported by this tag");
94          }
95          setWorkingForm(form);
96          IHTMLInputElement checkbox = null;
97          if ( value != null ) {
98              checkbox = setCheckboxWithNameAndValue(name, value, checked);
99          }else{
100             checkbox = setCheckbox(name, checked);
101         }
102         fireEvent(checkbox);
103     }
104 }