use of io.jmix.dynattr.AttributeType in project jmix by jmix-framework.
the class CategoryAttrsEdit method getDataTypeOptions.
protected Map<String, AttributeType> getDataTypeOptions() {
Map<String, AttributeType> options = new TreeMap<>();
AttributeType[] types = AttributeType.values();
for (AttributeType attributeType : types) {
String key = AttributeType.class.getSimpleName() + "." + attributeType.toString();
options.put(messages.getMessage(AttributeType.class, key), attributeType);
}
return options;
}
use of io.jmix.dynattr.AttributeType in project jmix by jmix-framework.
the class CategoryAttrsFragment method categoryAttrsTableDefaultValueColumnGenerator.
@Install(to = "categoryAttrsTable.defaultValue", subject = "columnGenerator")
protected Label<String> categoryAttrsTableDefaultValueColumnGenerator(CategoryAttribute attribute) {
String defaultValue = "";
AttributeType dataType = attribute.getDataType();
switch(dataType) {
case BOOLEAN:
Boolean b = attribute.getDefaultBoolean();
if (b != null)
defaultValue = BooleanUtils.isTrue(b) ? messages.getMessage("trueString") : messages.getMessage("falseString");
break;
case DATE:
Date dateTime = attribute.getDefaultDate();
if (dateTime != null) {
String dateTimeFormat = formatStringsRegistry.getFormatStrings(currentAuthentication.getLocale()).getDateTimeFormat();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateTimeFormat);
defaultValue = simpleDateFormat.format(dateTime);
} else if (BooleanUtils.isTrue(attribute.getDefaultDateIsCurrent())) {
defaultValue = messages.getMessage(CategoryAttrsFragment.class, "categoryAttrsTable.currentDate");
}
break;
case DATE_WITHOUT_TIME:
LocalDate dateWoTime = attribute.getDefaultDateWithoutTime();
if (dateWoTime != null) {
String dateWoTimeFormat = formatStringsRegistry.getFormatStrings(currentAuthentication.getLocale()).getDateFormat();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateWoTimeFormat);
defaultValue = dateWoTime.format(formatter);
} else if (BooleanUtils.isTrue(attribute.getDefaultDateIsCurrent())) {
defaultValue = messages.getMessage(CategoryAttrsFragment.class, "categoryAttrsTable.currentDate");
}
break;
case DECIMAL:
BigDecimal defaultDecimal = attribute.getDefaultDecimal();
if (defaultDecimal != null) {
defaultValue = defaultDecimal.toString();
}
break;
case DOUBLE:
Double defaultDouble = attribute.getDefaultDouble();
if (defaultDouble != null) {
defaultValue = defaultDouble.toString();
}
break;
case ENTITY:
Class<?> entityClass = attribute.getJavaType();
if (entityClass != null) {
defaultValue = "";
if (attribute.getObjectDefaultEntityId() != null) {
MetaClass metaClass = metadata.getClass(entityClass);
LoadContext<?> lc = new LoadContext<>(metadata.getClass(attribute.getJavaType()));
FetchPlan fetchPlan = fetchPlanRepository.getFetchPlan(metaClass, FetchPlan.INSTANCE_NAME);
lc.setFetchPlan(fetchPlan);
String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass);
lc.setQueryString(String.format("select e from %s e where e.%s = :entityId", metaClass.getName(), pkName)).setParameter("entityId", attribute.getObjectDefaultEntityId());
Object entity = dataManager.load(lc);
if (entity != null) {
defaultValue = metadataTools.getInstanceName(entity);
}
}
} else {
defaultValue = messages.getMessage(CategoryAttrsFragment.class, "categoryAttrsTable.entityNotFound");
}
break;
case ENUMERATION:
case STRING:
defaultValue = attribute.getDefaultString();
break;
case INTEGER:
Integer defaultInt = attribute.getDefaultInt();
if (defaultInt != null) {
defaultValue = defaultInt.toString();
}
break;
}
Label<String> defaultValueLabel = uiComponents.create(Label.TYPE_STRING);
defaultValueLabel.setValue(defaultValue);
return defaultValueLabel;
}
use of io.jmix.dynattr.AttributeType in project jmix by jmix-framework.
the class DynAttrComponentGenerationStrategy method initValuesSelectActionByAttribute.
protected void initValuesSelectActionByAttribute(ValuesSelectAction selectAction, AttributeDefinition attribute) {
AttributeType attributeType = attribute.getDataType();
switch(attributeType) {
case DATE:
selectAction.setJavaClass(Date.class);
selectAction.setResolution(DateField.Resolution.MIN);
break;
case DATE_WITHOUT_TIME:
selectAction.setJavaClass(LocalDate.class);
selectAction.setResolution(DateField.Resolution.DAY);
break;
case STRING:
selectAction.setJavaClass(String.class);
break;
case ENUMERATION:
selectAction.setJavaClass(String.class);
selectAction.setOptions(new MapOptions(getLocalizedEnumerationMap(attribute)));
break;
case DOUBLE:
selectAction.setJavaClass(Double.class);
break;
case DECIMAL:
selectAction.setJavaClass(BigDecimal.class);
break;
case INTEGER:
selectAction.setJavaClass(Integer.class);
break;
case BOOLEAN:
selectAction.setJavaClass(Boolean.class);
break;
case ENTITY:
Class<?> javaType = attribute.getJavaType();
if (javaType != null) {
MetaClass metaClass = metadata.getClass(javaType);
selectAction.setEntityName(metaClass.getName());
}
selectAction.setLookupScreenId(attribute.getConfiguration().getLookupScreen());
selectAction.setUseComboBox(attribute.getConfiguration().isLookup());
break;
}
}
use of io.jmix.dynattr.AttributeType in project jmix by jmix-framework.
the class CategoryAttrsEdit method refreshAttributesValues.
protected void refreshAttributesValues() {
AttributeType attributeType = dataTypeField.getValue();
CategoryAttribute categoryAttribute = getEditedEntity();
CategoryAttributeConfiguration configuration = categoryAttribute.getConfiguration();
if (ENTITY.equals(attributeType)) {
if (!Strings.isNullOrEmpty(categoryAttribute.getEntityClass())) {
Map<String, String> options = ((MapOptions<String>) screenField.getOptions()).getItemsCollection();
categoryAttribute.setScreen(options.containsValue(categoryAttribute.getScreen()) ? categoryAttribute.getScreen() : null);
}
if (configuration.getOptionsLoaderType() == SQL) {
configuration.setOptionsLoaderType(JPQL);
}
} else if (configuration.getOptionsLoaderType() == JPQL) {
configuration.setOptionsLoaderType(null);
}
if (DATE.equals(attributeType)) {
if (Boolean.TRUE.equals(categoryAttribute.getDefaultDateIsCurrent())) {
categoryAttribute.setDefaultDate(null);
}
}
if (DATE_WITHOUT_TIME.equals(attributeType)) {
if (Boolean.TRUE.equals(categoryAttribute.getDefaultDateIsCurrent())) {
categoryAttribute.setDefaultDateWithoutTime(null);
}
}
if (BOOLEAN.equals(attributeType)) {
categoryAttribute.setIsCollection(null);
}
if (categoryAttribute.getDataType() == null || !SUPPORTED_OPTIONS_TYPES.contains(categoryAttribute.getDataType())) {
categoryAttribute.setLookup(false);
}
if (!Boolean.TRUE.equals(categoryAttribute.getLookup())) {
configuration.setOptionsLoaderType(null);
configuration.setOptionsLoaderScript(null);
categoryAttribute.setWhereClause(null);
categoryAttribute.setJoinClause(null);
} else {
OptionsLoaderType optionsType = configuration.getOptionsLoaderType();
if (optionsType == JPQL) {
configuration.setOptionsLoaderScript(null);
} else if (optionsType == GROOVY || optionsType == SQL) {
categoryAttribute.setWhereClause(null);
categoryAttribute.setJoinClause(null);
} else if (optionsType == null) {
configuration.setOptionsLoaderScript(null);
categoryAttribute.setWhereClause(null);
categoryAttribute.setJoinClause(null);
if (categoryAttribute.getDataType() == ENTITY) {
configuration.setOptionsLoaderType(JPQL);
}
}
}
}
use of io.jmix.dynattr.AttributeType in project jmix by jmix-framework.
the class CategoryAttrsEdit method onValidation.
@Subscribe
protected void onValidation(ValidationEvent event) {
ValidationErrors validationErrors = new ValidationErrors();
CategoryAttribute attribute = getEditedEntity();
AttributeType dataType = attribute.getDataType();
CategoryAttributeConfiguration configuration = attribute.getConfiguration();
if (INTEGER.equals(dataType)) {
ValidationErrors errors = validateNumbers(INTEGER, configuration.getMinInt(), configuration.getMaxInt(), attribute.getDefaultInt());
validationErrors.addAll(errors);
} else if (DOUBLE.equals(dataType)) {
ValidationErrors errors = validateNumbers(DOUBLE, configuration.getMinDouble(), configuration.getMaxDouble(), attribute.getDefaultDouble());
validationErrors.addAll(errors);
} else if (DECIMAL.equals(dataType)) {
ValidationErrors errors = validateNumbers(DECIMAL, configuration.getMinDecimal(), configuration.getMaxDecimal(), attribute.getDefaultDecimal());
validationErrors.addAll(errors);
} else if (ENUMERATION.equals(dataType)) {
ValidationErrors errors = validateEnumeration(attribute.getEnumeration(), attribute.getDefaultString());
validationErrors.addAll(errors);
}
Category category = getEditedEntity().getCategory();
if (category != null && category.getCategoryAttrs() != null) {
for (CategoryAttribute categoryAttribute : category.getCategoryAttrs()) {
if (!categoryAttribute.equals(attribute)) {
if (categoryAttribute.getName().equals(attribute.getName())) {
validationErrors.add(messages.getMessage(CategoryAttrsEdit.class, "uniqueName"));
return;
} else if (categoryAttribute.getCode().equals(attribute.getCode())) {
validationErrors.add(messages.getMessage(CategoryAttrsEdit.class, "uniqueCode"));
return;
}
}
}
}
event.addErrors(validationErrors);
}
Aggregations