diff --git a/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/DropdownList.java b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/DropdownList.java new file mode 100644 index 0000000000..15040a8a26 --- /dev/null +++ b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/DropdownList.java @@ -0,0 +1,92 @@ +package hudson.plugins.ui_samples; + +import hudson.DescriptorExtensionList; +import hudson.Extension; +import hudson.ExtensionPoint; +import hudson.model.Describable; +import hudson.model.Descriptor; +import hudson.model.Hudson; +import hudson.util.XStream2; +import java.io.IOException; +import java.util.List; +import javax.servlet.ServletException; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; + +/** + * @author Alan.Harder@oracle.com + */ +@Extension +public class DropdownList extends UISample { + + @Override + public String getDescription() { + return "Show different form elements based on choice in a <select> control"; + } + + public Fruit getFruit() { + // Could return currently configured/saved item here to initialized form with this data + return null; + } + + public DescriptorExtensionList> getFruitDescriptors() { + return Hudson.getInstance().getDescriptorList(Fruit.class); + } + + // Process form data and show it as serialized XML + public void doSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException { + // stapler-class in form data tells Stapler which Fruit subclass to use + Fruit fruit = req.bindJSON(Fruit.class, req.getSubmittedForm().getJSONObject("fruit")); + rsp.setContentType("text/plain"); + new XStream2().toXML(fruit, rsp.getWriter()); + } + + @Override + public List getSourceFiles() { + List list = new java.util.ArrayList(super.getSourceFiles()); + list.add(new SourceFile("Apple/config.jelly")); + list.add(new SourceFile("Banana/config.jelly")); + return list; + } + + @Extension + public static final class DescriptorImpl extends UISampleDescriptor { + } + + public static class Fruit implements ExtensionPoint, Describable { + protected String name; + private Fruit(String name) { this.name = name; } + + public Descriptor getDescriptor() { + return Hudson.getInstance().getDescriptor(getClass()); + } + } + + public static class FruitDescriptor extends Descriptor { + public FruitDescriptor(Class clazz) { + super(clazz); + } + public String getDisplayName() { + return clazz.getSimpleName(); + } + } + + public static class Apple extends Fruit { + private int seeds; + @DataBoundConstructor public Apple(int seeds) { + super("Apple"); + this.seeds = seeds; + } + @Extension public static final FruitDescriptor D = new FruitDescriptor(Apple.class); + } + + public static class Banana extends Fruit { + private boolean yellow; + @DataBoundConstructor public Banana(boolean yellow) { + super("Banana"); + this.yellow = yellow; + } + @Extension public static final FruitDescriptor D = new FruitDescriptor(Banana.class); + } +} diff --git a/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/DynamicComboBox.java b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/DynamicComboBox.java index 1c4a805846..6611eb3081 100644 --- a/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/DynamicComboBox.java +++ b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/DynamicComboBox.java @@ -4,9 +4,6 @@ import hudson.Extension; import hudson.util.ListBoxModel; import org.kohsuke.stapler.QueryParameter; -import java.util.Arrays; -import java.util.Collection; - import static java.util.Arrays.asList; /** diff --git a/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/UISample.java b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/UISample.java index b18e98d298..8736ddcd87 100644 --- a/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/UISample.java +++ b/ui-samples-plugin/src/main/java/hudson/plugins/ui_samples/UISample.java @@ -5,6 +5,7 @@ import hudson.ExtensionPoint; import hudson.model.Action; import hudson.model.Describable; import hudson.model.Hudson; +import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import java.io.IOException; @@ -44,11 +45,14 @@ public abstract class UISample implements ExtensionPoint, Action, Describable - -

Source Files

- + + + + diff --git a/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DropdownList/Banana/config.jelly b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DropdownList/Banana/config.jelly new file mode 100644 index 0000000000..0792f815e6 --- /dev/null +++ b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DropdownList/Banana/config.jelly @@ -0,0 +1,29 @@ + + + + + Yellow? + + diff --git a/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DropdownList/index.jelly b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DropdownList/index.jelly new file mode 100644 index 0000000000..c2f6b05a75 --- /dev/null +++ b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DropdownList/index.jelly @@ -0,0 +1,50 @@ + + + + +
+ + + + + + + + + + + + + + + + + + +
+
+
+
diff --git a/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DynamicComboBox/index.jelly b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DynamicComboBox/index.jelly index 753128c92e..c1193ce33d 100644 --- a/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DynamicComboBox/index.jelly +++ b/ui-samples-plugin/src/main/resources/hudson/plugins/ui_samples/DynamicComboBox/index.jelly @@ -22,33 +22,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> - - - -

Dynamic ComboBox Sample

- -

- -

- - - - -
- - - - - - - - - - -
-
-
-
-
+ + +
+ + + + + + + + + + +
+
+
diff --git a/ui-samples-plugin/src/main/resources/lib/samples/sample.jelly b/ui-samples-plugin/src/main/resources/lib/samples/sample.jelly index 8126459365..3d9078e98a 100644 --- a/ui-samples-plugin/src/main/resources/lib/samples/sample.jelly +++ b/ui-samples-plugin/src/main/resources/lib/samples/sample.jelly @@ -1,7 +1,7 @@ - - Set up variable bindings that emulate the form environment. - + Page layout for UI samples and variable bindings that emulate the form environment. + + Page title + - + + +

${title}

+

+ +

+

Source Files

+ +

Sample

+ +
+