Skip to content

Commit 194a7ea

Browse files
authored
Merge pull request #230 from rdebusscher/issue177
Specifications by default unselected, additional links to "Select All"
2 parents d9c4a3e + 9701df4 commit 194a7ea

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/main/java/org/eclipse/microprofile/starter/view/GeneratorDataBean.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@
5252
import java.io.IOException;
5353
import java.io.OutputStream;
5454
import java.io.Serializable;
55-
import java.util.*;
55+
import java.util.ArrayList;
56+
import java.util.Iterator;
57+
import java.util.LinkedHashMap;
58+
import java.util.List;
59+
import java.util.Map;
60+
import java.util.Random;
5661
import java.util.stream.Collectors;
5762
import java.util.stream.IntStream;
5863

@@ -111,12 +116,17 @@ private void defineMPVersionValue() {
111116

112117
private void defineExampleSpecs(MicroProfileVersion version) {
113118
specs = new ArrayList<>();
119+
List<String> currentSelected = new ArrayList<>(selectedSpecs);
114120
selectedSpecs.clear();
115121

116122
for (MicroprofileSpec microprofileSpec : MicroprofileSpec.values()) {
117123
if (microprofileSpec.getMpVersions().contains(version)) {
118124
specs.add(new SelectItem(microprofileSpec.getCode(), microprofileSpec.getLabel()));
119-
selectedSpecs.add(microprofileSpec.getCode());
125+
if (currentSelected.contains(microprofileSpec.getCode())) {
126+
// If the spec is currently selected, keep it selected.
127+
// But if it is not listed anymore in the MP version, it has to go.
128+
selectedSpecs.add(microprofileSpec.getCode());
129+
}
120130
}
121131
}
122132

@@ -247,4 +257,11 @@ public void setSelectedSpecs(List<String> selectedSpecs) {
247257
this.selectedSpecs = selectedSpecs;
248258
}
249259

260+
public void selectAll() {
261+
selectedSpecs = specs.stream().map(si -> si.getValue().toString()).collect(Collectors.toList());
262+
}
263+
264+
public void unselectAll() {
265+
selectedSpecs.clear();
266+
}
250267
}

src/main/webapp/index.xhtml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,20 @@
120120
</p:selectOneMenu>
121121
</p:panelGrid>
122122
<h:panelGroup>
123-
<p:outputLabel value="Examples for specifications" for="microprofileSpecs"/>
123+
<p:outputLabel value="Examples for specifications" for="microprofileSpecs"/> <h:outputText value="&#160;" />
124+
<p:commandLink value="Select All" actionListener="#{generatorDataBean.selectAll}" update="microprofileSpecs"
125+
ajax="true" process="@this"
126+
rendered="#{not empty generatorDataBean.engineData.mpVersion}"/>
127+
<h:outputText value="&#160;" /><h:outputText value="&#160;" />
128+
<p:commandLink value="Clear All" actionListener="#{generatorDataBean.unselectAll}" update="microprofileSpecs"
129+
ajax="true" process="@this"
130+
rendered="#{not empty generatorDataBean.engineData.mpVersion}"/>
124131
<p:selectManyCheckbox id="microprofileSpecs" value="#{generatorDataBean.selectedSpecs}"
125132
layout="responsive" styleClass="specifications"
126133
columns="2" disabled="#{empty generatorDataBean.engineData.mpVersion}">
127134
<f:selectItems value="#{generatorDataBean.specs}" var="spec" itemLabel="#{spec}"
128135
itemValue="#{spec}"/>
136+
<p:ajax process="@this" />
129137
</p:selectManyCheckbox>
130138
</h:panelGroup>
131139

0 commit comments

Comments
 (0)