Skip to content

Commit 8e374ac

Browse files
Set default icons, make icon label matching safer (#620)
* set default icons, make icon label matching safer * nicer code, handle deletion of box value
1 parent 04ecddc commit 8e374ac

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

user-interface/src/main/java/life/qbic/datamanager/views/projects/create/BioIconComboboxFactory.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
import com.vaadin.flow.data.renderer.ComponentRenderer;
88
import java.util.List;
99
import life.qbic.datamanager.views.projects.project.experiments.experiment.ExperimentDetailsComponent.BioIcon;
10+
import life.qbic.datamanager.views.projects.project.experiments.experiment.ExperimentDetailsComponent.SampleSourceType;
1011

1112
/**
1213
* Factory class for creating ComboBoxes allowing the selection of icons for species and specimen.
1314
*/
1415
public class BioIconComboboxFactory {
1516

16-
public ComboBox<BioIcon> iconBox(List<BioIcon> options, String title) {
17+
public ComboBox<BioIcon> iconBox(SampleSourceType type, String title) {
18+
BioIcon defaultIcon = BioIcon.getDefaultBioIcon(type);
19+
1720
ComboBox<BioIcon> comboBox = new ComboBox<>(title);
18-
comboBox.setItems(options);
21+
comboBox.setItems(BioIcon.getOptionsForType(type));
1922
comboBox.setWidth("150px");
2023
comboBox.setItemLabelGenerator(
2124
BioIcon::getLabel);
@@ -26,8 +29,15 @@ public ComboBox<BioIcon> iconBox(List<BioIcon> options, String title) {
2629

2730
return element;
2831
}));
29-
comboBox.addValueChangeListener(valueChanged -> valueChanged.getSource()
30-
.setPrefixComponent(styleIcon(valueChanged.getValue())));
32+
comboBox.addValueChangeListener(valueChanged -> {
33+
Object val = valueChanged.getValue();
34+
if(val==null) {
35+
comboBox.setValue(defaultIcon);
36+
} else {
37+
valueChanged.getSource().setPrefixComponent(styleIcon((BioIcon) val));
38+
}
39+
});
40+
comboBox.setValue(defaultIcon);
3141
return comboBox;
3242
}
3343

user-interface/src/main/java/life/qbic/datamanager/views/projects/create/ExperimentalInformationLayout.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public ExperimentalInformationLayout(
5252

5353
experimentalInformationBinder = new Binder<>(ExperimentalInformation.class);
5454

55-
ComboBox<BioIcon> speciesIconBox = bioIconComboboxFactory.iconBox(
56-
BioIcon.getOptionsForType(SampleSourceType.SPECIES), "Species icon");
55+
ComboBox<BioIcon> speciesIconBox = bioIconComboboxFactory.iconBox(SampleSourceType.SPECIES,
56+
"Species icon");
5757
experimentalInformationBinder.forField(speciesIconBox)
5858
.bind(ExperimentalInformation::getSpeciesIcon,
5959
ExperimentalInformation::setSpeciesIcon);
6060

61-
ComboBox<BioIcon> specimenIconBox = bioIconComboboxFactory.iconBox(
62-
BioIcon.getOptionsForType(SampleSourceType.SPECIMEN), "Specimen icon");
61+
ComboBox<BioIcon> specimenIconBox = bioIconComboboxFactory.iconBox(SampleSourceType.SPECIMEN,
62+
"Specimen icon");
6363
experimentalInformationBinder.forField(specimenIconBox)
6464
.bind(ExperimentalInformation::getSpecimenIcon,
6565
ExperimentalInformation::setSpecimenIcon);

user-interface/src/main/java/life/qbic/datamanager/views/projects/project/experiments/experiment/ExperimentDetailsComponent.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,15 @@ public static BioIcon getTypeWithNameOrDefault(SampleSourceType sampleSourceType
659659
String iconName) {
660660
Optional<BioIcon> searchResult = getOptionsForType(sampleSourceType).stream()
661661
.filter(icon -> icon.label.equals(iconName)).findFirst();
662-
return searchResult.orElseGet(() -> getOptionsForType(sampleSourceType).stream()
663-
.filter(icon -> icon.label.equals("default")).findFirst().get());
662+
return searchResult.orElseGet(() -> getDefaultBioIcon(sampleSourceType));
663+
}
664+
665+
public static BioIcon getDefaultBioIcon(SampleSourceType sampleSourceType) {
666+
return switch (sampleSourceType) {
667+
case SPECIES -> DEFAULT_SPECIES;
668+
case SPECIMEN -> DEFAULT_SPECIMEN;
669+
case ANALYTE -> DEFAULT_ANALYTE;
670+
};
664671
}
665672

666673
public String getLabel() {

user-interface/src/main/java/life/qbic/datamanager/views/projects/project/experiments/experiment/create/AddExperimentDialog.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ public AddExperimentDialog(
8484
.bind(experimentDraft -> new HashSet<>(experimentDraft.getAnalytes()),
8585
ExperimentDraft::setAnalytes);
8686

87-
ComboBox<BioIcon> speciesIconBox = bioIconComboboxFactory.iconBox(
88-
BioIcon.getOptionsForType(SampleSourceType.SPECIES), "Species icon");
87+
ComboBox<BioIcon> speciesIconBox = bioIconComboboxFactory.iconBox(SampleSourceType.SPECIES,
88+
"Species icon");
8989
binder.forField(speciesIconBox)
9090
.bind(ExperimentDraft::getSpeciesIcon,
9191
ExperimentDraft::setSpeciesIcon);
9292

93-
ComboBox<BioIcon> specimenIconBox = bioIconComboboxFactory.iconBox(
94-
BioIcon.getOptionsForType(SampleSourceType.SPECIMEN), "Specimen icon");
93+
94+
ComboBox<BioIcon> specimenIconBox = bioIconComboboxFactory.iconBox(SampleSourceType.SPECIMEN,
95+
"Specimen icon");
9596
binder.forField(specimenIconBox)
9697
.bind(ExperimentDraft::getSpecimenIcon,
9798
ExperimentDraft::setSpecimenIcon);

user-interface/src/main/java/life/qbic/datamanager/views/projects/project/experiments/experiment/update/EditExperimentDialog.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public EditExperimentDialog(OntologyLookupService ontologyTermInformationService
6666
.bind(experimentDraft -> new HashSet<>(experimentDraft.getSpecies()),
6767
ExperimentDraft::setSpecies);
6868

69-
ComboBox<BioIcon> speciesIconBox = bioIconComboboxFactory.iconBox(
70-
BioIcon.getOptionsForType(SampleSourceType.SPECIES), "Species icon");
69+
ComboBox<BioIcon> speciesIconBox = bioIconComboboxFactory.iconBox(SampleSourceType.SPECIES,
70+
"Species icon");
7171
binder.forField(speciesIconBox)
7272
.bind(ExperimentDraft::getSpeciesIcon,
7373
ExperimentDraft::setSpeciesIcon);
@@ -79,8 +79,8 @@ public EditExperimentDialog(OntologyLookupService ontologyTermInformationService
7979
.bind(experimentDraft -> new HashSet<>(experimentDraft.getSpecimens()),
8080
ExperimentDraft::setSpecimens);
8181

82-
ComboBox<BioIcon> specimenIconBox = bioIconComboboxFactory.iconBox(
83-
BioIcon.getOptionsForType(SampleSourceType.SPECIMEN), "Specimen icon");
82+
ComboBox<BioIcon> specimenIconBox = bioIconComboboxFactory.iconBox(SampleSourceType.SPECIMEN,
83+
"Specimen icon");
8484
binder.forField(specimenIconBox)
8585
.bind(ExperimentDraft::getSpecimenIcon,
8686
ExperimentDraft::setSpecimenIcon);

0 commit comments

Comments
 (0)