com.netgrif.application.engine.petrinet.domain.dataset.MultichoiceField.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of application-engine Show documentation
Show all versions of application-engine Show documentation
System provides workflow management functions including user, role and data management.
package com.netgrif.application.engine.petrinet.domain.dataset
import com.netgrif.application.engine.petrinet.domain.I18nString
import org.springframework.data.mongodb.core.mapping.Document
@Document
class MultichoiceField extends ChoiceField> {
MultichoiceField() {
super()
super.setValue(new LinkedHashSet())
super.setDefaultValue(new LinkedHashSet())
}
MultichoiceField(List values) {
super(values)
super.setValue(new LinkedHashSet())
super.setDefaultValue(new LinkedHashSet())
}
@Override
FieldType getType() {
return FieldType.MULTICHOICE
}
void setDefaultValue(String value) {
if (value == null) {
this.defaultValue = null
} else {
String[] vls = value.split(",")
def defaults = new LinkedHashSet()
vls.each { s ->
defaults << choices.find { it ->
it.defaultValue == s.trim()
}
}
super.setDefaultValue(defaults)
}
}
void setDefaultValues(List inits) {
if (inits == null || inits.isEmpty()) {
this.defaultValue = null
} else {
Set defaults = new LinkedHashSet<>()
inits.forEach { initValue ->
defaults << choices.find { choice ->
choice.defaultValue == initValue.trim()
}
}
super.setDefaultValue(defaults)
}
}
void setValue(String value) {
I18nString i18n = choices.find { it.contains(value) }
if (i18n == null && value != null)
i18n = new I18nString(value)
//TODO: case save choices
// throw new IllegalArgumentException("Value $value is not a choice")
super.setValue([i18n] as Set)
}
void setValue(Collection values) {
def newValues = [] as Set
for (String value : values) {
I18nString i18n = choices.find { it.contains(value) }
if (i18n == null && value != null)
i18n = new I18nString(value)
//TODO: case save choices
// throw new IllegalArgumentException("Value $value is not a choice")
newValues << i18n
}
super.setValue(newValues)
}
@Override
void setValue(LinkedHashSet value) {
super.setValue(value)
}
@Override
Field clone() {
MultichoiceField clone = new MultichoiceField()
super.clone(clone)
clone.choices = this.choices
clone.choicesExpression = this.choicesExpression
return clone
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy