Skip to content

Commit 078e93e

Browse files
committed
Add documentation for enum based selects
enums are an easy way to select from a fixed set of choices that don't need configuration.
1 parent 6dec02c commit 078e93e

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

src/main/java/io/jenkins/plugins/designlibrary/Select.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public Fruit getFruit() {
3434
return null;
3535
}
3636

37+
private Unit unit;
38+
public Unit getUnit() {
39+
return unit;
40+
}
41+
3742
public DescriptorExtensionList<Fruit, Descriptor<Fruit>> getFruitDescriptors() {
3843
return Jenkins.get().getDescriptorList(Fruit.class);
3944
}
@@ -182,4 +187,22 @@ public static final class DescriptorImpl extends FruitDescriptor {}
182187
"Wisconsin",
183188
"Wyoming"
184189
};
190+
191+
public enum Unit {
192+
MILLISECONDS("Milliseconds"),
193+
SECONDS("Seconds"),
194+
MINUTES("Minutes"),
195+
HOURS("Hours"),
196+
DAYS("Days");
197+
198+
private final String description;
199+
200+
Unit(String description) {
201+
this.description = description;
202+
}
203+
204+
public String getDescription() {
205+
return description;
206+
}
207+
}
185208
}

src/main/resources/io/jenkins/plugins/designlibrary/Select/index.jelly

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ THE SOFTWARE.
4242
</s:group>
4343
</s:section>
4444

45+
<s:section title="${%Enum select}" description="${%usage.enum}">
46+
<s:group>
47+
<s:preview>
48+
<f:entry title="Unit" field="unit">
49+
<f:enum default="SECONDS">
50+
${it.description}
51+
</f:enum>
52+
</f:entry>
53+
</s:preview>
54+
<s:code-panes>
55+
<s:code-pane title="Jelly">
56+
<s:code file="enum.jelly"/>
57+
</s:code-pane>
58+
<s:code-pane title="Java">
59+
<s:code language="java" file="Enum.java"/>
60+
</s:code-pane>
61+
</s:code-panes>
62+
</s:group>
63+
</s:section>
64+
4565
<s:section title="Advanced select" description="${%usage.1}">
4666
<s:group>
4767
<s:preview>

src/main/resources/io/jenkins/plugins/designlibrary/Select/index.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ searchable=Autocomplete
88
searchable.description=Allows users to quickly browse a select by typing to filter the available choices. Start typing a U.S. state for results to appear.
99
combobox=Using <code>combobox</code> forces the user to select an option from the available choices, it''ll also display all choices on focus.
1010
textbox=Using <code>textbox</code> on the other hand allows the user to enter free text if they so desire.
11+
usage.enum=With <code>f:enum</code> you can create a select that is based on an <code>enum</code> in Java.

src/main/webapp/Select/Enum.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class UnitHolder {
2+
3+
private Unit unit;
4+
5+
public Unit getUnit() {
6+
return unit;
7+
}
8+
9+
@DataBoundSetter
10+
public void setUnit(Unit unit) {
11+
this.unit = unit
12+
}
13+
14+
public enum Unit {
15+
MILLISECONDS("Milliseconds"),
16+
SECONDS("Seconds"),
17+
MINUTES("Minutes"),
18+
HOURS("Hours"),
19+
DAYS("Days");
20+
21+
private final String description;
22+
23+
Unit(String description) {
24+
this.description = description;
25+
}
26+
27+
public String getDescription() {
28+
return description;
29+
}
30+
}
31+
}

src/main/webapp/Select/enum.jelly

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<f:entry title="Unit" field="unit">
2+
<f:enum default="SECONDS">
3+
${it.description}
4+
</f:enum>
5+
</f:entry>

0 commit comments

Comments
 (0)