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

1 package jenkins.plugins.ui_samples;
2
3 import hudson.DescriptorExtensionList;
4 import hudson.Extension;
5 import hudson.ExtensionPoint;
6 import hudson.model.Describable;
7 import hudson.model.Descriptor;
8 import jenkins.model.Jenkins;
9 import hudson.util.XStream2;
10 import java.io.IOException;
11 import java.util.List;
12 import javax.servlet.ServletException;
13
14 import org.kohsuke.stapler.DataBoundConstructor;
15 import org.kohsuke.stapler.StaplerRequest;
16 import org.kohsuke.stapler.StaplerResponse;
17
18 /**
19 * @author Alan.Harder@oracle.com
20 */
21 @Extension
22 public class DropdownList extends UISample {
23
24 @Override
25 public String getDescription() {
26 return "Show different form elements based on choice in a &lt;select> control";
27 }
28
29 public Fruit getFruit() {
30 // Could return currently configured/saved item here to initialized form with this data
31 return null;
32 }
33
34 public DescriptorExtensionList<Fruit,Descriptor<Fruit>> getFruitDescriptors() {
35 return Jenkins.getInstance().<Fruit,Descriptor<Fruit>>getDescriptorList(Fruit.class);
36 }
37
38 // Process form data and show it as serialized XML
39 public void doSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
40 // stapler-class in form data tells Stapler which Fruit subclass to use
41 Fruit fruit = req.bindJSON(Fruit.class, req.getSubmittedForm().getJSONObject("fruit"));
42 rsp.setContentType("text/plain");
43 new XStream2().toXML(fruit, rsp.getWriter());
44 }
45
46 @Override
47 public List<SourceFile> getSourceFiles() {
48 List<SourceFile> list = new java.util.ArrayList<SourceFile>(super.getSourceFiles());
49 list.add(new SourceFile("Apple/config.jelly"));
50 list.add(new SourceFile("Banana/config.jelly"));
51 return list;
52 }
53
54 @Extension
55 public static final class DescriptorImpl extends UISampleDescriptor {
56 }
57
58 public static abstract class Fruit implements ExtensionPoint, Describable<Fruit> {
59 protected String name;
60 protected Fruit(String name) { this.name = name; }
61
62 public Descriptor<Fruit> getDescriptor() {
63 return Jenkins.getInstance().getDescriptor(getClass());
64 }
65 }
66
67 public static class FruitDescriptor extends Descriptor<Fruit> {
68 public FruitDescriptor(Class<? extends Fruit> clazz) {
69 super(clazz);
70 }
71 public String getDisplayName() {
72 return clazz.getSimpleName();
73 }
74 }
75
76 public static class Apple extends Fruit {
77 private int seeds;
78 @DataBoundConstructor public Apple(int seeds) {
79 super("Apple");
80 this.seeds = seeds;
81 }
82 @Extension public static final FruitDescriptor D = new FruitDescriptor(Apple.class);
83 }
84
85 public static class Banana extends Fruit {
86 private boolean yellow;
87 @DataBoundConstructor public Banana(boolean yellow) {
88 super("Banana");
89 this.yellow = yellow;
90 }
91 @Extension public static final FruitDescriptor D = new FruitDescriptor(Banana.class);
92 }
93 }
94