Skip to content

Commit 6ce482a

Browse files
Add documentation for enum based selects (#414)
Co-authored-by: Kris Stern <krisstern@outlook.com>
1 parent 6dec02c commit 6ce482a

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

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

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

37+
public Unit getUnit() {
38+
return Unit.SECONDS;
39+
}
40+
3741
public DescriptorExtensionList<Fruit, Descriptor<Fruit>> getFruitDescriptors() {
3842
return Jenkins.get().getDescriptorList(Fruit.class);
3943
}
@@ -182,4 +186,22 @@ public static final class DescriptorImpl extends FruitDescriptor {}
182186
"Wisconsin",
183187
"Wyoming"
184188
};
189+
190+
public enum Unit {
191+
MILLISECONDS("Milliseconds"),
192+
SECONDS("Seconds"),
193+
MINUTES("Minutes"),
194+
HOURS("Hours"),
195+
DAYS("Days");
196+
197+
private final String description;
198+
199+
Unit(String description) {
200+
this.description = description;
201+
}
202+
203+
public String getDescription() {
204+
return description;
205+
}
206+
}
185207
}

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)