File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\ui-samples-plugin\src\main\java\jenkins\plugins\ui_samples\DynamicDropDownListBox.java.html

1 package jenkins.plugins.ui_samples;
2
3 import hudson.Extension;
4 import hudson.util.ListBoxModel;
5 import org.kohsuke.stapler.QueryParameter;
6
7 import static java.util.Arrays.asList;
8
9 /**
10 * Example of a dynamic drop-down list box that changes the contents dynamically based on the values of other controls.
11 *
12 * @author Kohsuke Kawaguchi
13 */
14 @Extension
15 public class DynamicDropDownListBox extends UISample {
16
17 @Override
18 public String getDescription() {
19 return "Updates the contents of a &lt;select> control dynamically based on selections of other controls";
20 }
21
22 // these getter methods should return the current value, which form the initial selection.
23
24 public String getCountry() {
25 return "USA";
26 }
27
28 public String getState() {
29 return "USA:B";
30 }
31
32 public String getCity() {
33 return "USA:B:Z";
34 }
35
36 @Extension
37 public static final class DescriptorImpl extends UISampleDescriptor {
38 public ListBoxModel doFillStateItems(@QueryParameter String country) {
39 ListBoxModel m = new ListBoxModel();
40 for (String s : asList("A","B","C"))
41 m.add(String.format("State %s in %s", s, country),
42 country+':'+s);
43 return m;
44 }
45
46 public ListBoxModel doFillCityItems(@QueryParameter String country, @QueryParameter String state) {
47 ListBoxModel m = new ListBoxModel();
48 for (String s : asList("X","Y","Z"))
49 m.add(String.format("City %s in %s %s", s, state, country),
50 state+':'+s);
51 return m;
52 }
53 }
54 }
55