Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predictable property order for both grid & form #130

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions add-on/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<vaadin.version>24.0.5</vaadin.version>
<vaadin.version>24.3.8</vaadin.version>

<drivers.dir>${project.basedir}/drivers</drivers.dir>
<maven.deploy.skip>true</maven.deploy.skip>
Expand Down Expand Up @@ -52,10 +52,6 @@
<id>Vaadin Directory</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>Vaadin prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</repository>
</repositories>

<dependencyManagement>
Expand All @@ -81,10 +77,15 @@
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
</dependency>
<dependency>
<groupId>in.virit</groupId>
<artifactId>viritin</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>3.0.6</version>
<version>3.2.2</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.Column;
import com.vaadin.flow.component.icon.VaadinIcon;
import org.vaadin.firitin.components.grid.VGrid;

/**
* @author Alejandro Duarte
Expand Down Expand Up @@ -49,7 +50,12 @@ public GridCrud(Class<T> domainType, CrudLayout crudLayout, CrudFormFactory<T> c

@Override
protected Grid<T> createGrid() {
return new Grid<T>(domainType);
return new VGrid<T>(domainType);
}

@Override
public VGrid<T> getGrid() {
return (VGrid<T>) super.getGrid();
}

public void refreshGrid() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
package org.vaadin.crudui.form;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.vaadin.crudui.crud.CrudOperation;
import org.vaadin.crudui.crud.CrudOperationException;
import org.vaadin.crudui.form.impl.field.provider.DefaultFieldProvider;
import org.vaadin.data.converter.StringToByteConverter;
import org.vaadin.data.converter.StringToCharacterConverter;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.BasicBeanDescription;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEventListener;
Expand Down Expand Up @@ -49,12 +31,31 @@
import com.vaadin.flow.function.SerializableSupplier;
import com.vaadin.flow.internal.BeanUtil;
import com.vaadin.flow.shared.util.SharedUtil;
import org.vaadin.crudui.crud.CrudOperation;
import org.vaadin.crudui.crud.CrudOperationException;
import org.vaadin.crudui.form.impl.field.provider.DefaultFieldProvider;
import org.vaadin.data.converter.StringToByteConverter;
import org.vaadin.data.converter.StringToCharacterConverter;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @author Alejandro Duarte.
*/
public abstract class AbstractAutoGeneratedCrudFormFactory<T> extends AbstractCrudFormFactory<T> {

private static ObjectMapper jack = new ObjectMapper();

protected Map<CrudOperation, String> buttonCaptions = new HashMap<>();
protected Map<CrudOperation, Icon> buttonIcons = new HashMap<>();
protected Map<CrudOperation, Set<String>> buttonStyleNames = new HashMap<>();
Expand Down Expand Up @@ -134,12 +135,9 @@ public void setValidationErrorMessage(String validationErrorMessage) {
}

protected List<String> discoverProperties() {
try {
List<PropertyDescriptor> descriptors = BeanUtil.getBeanPropertyDescriptors(domainType);
return descriptors.stream().filter(d -> !d.getName().equals("class")).map(d -> d.getName()).collect(Collectors.toList());
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
JavaType javaType = jack.getTypeFactory().constructType(domainType);
var beanDescription = (BasicBeanDescription) jack.getSerializationConfig().introspect(javaType);
return beanDescription.findProperties().stream().map(bpd -> bpd.getName()).toList();
}

protected List<HasValueAndElement> buildFields(CrudOperation operation, T domainObject, boolean readOnly) {
Expand Down Expand Up @@ -267,21 +265,12 @@ protected void bindField(HasValue field, String property, Class<?> propertyType,
if(configuration.getConverters().containsKey(property)) {
bindingBuilder = bindingBuilder.withConverter(configuration.getConverters().get(property));

} else if (Double.class.isAssignableFrom(propertyType) || double.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToDoubleConverter(null, "Must be a number"));

} else if (Long.class.isAssignableFrom(propertyType) || long.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToLongConverter(null, "Must be a number"));

} else if (BigDecimal.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToBigDecimalConverter(null, "Must be a number"));

} else if (BigInteger.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToBigIntegerConverter(null, "Must be a number"));

} else if (Integer.class.isAssignableFrom(propertyType) || int.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToIntegerConverter(null, "Must be a number"));

} else if (Byte.class.isAssignableFrom(propertyType) || byte.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToByteConverter(null, "Must be a number"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.vaadin.flow.function.SerializableConsumer;
import org.vaadin.crudui.crud.CrudOperation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -31,6 +32,21 @@ public void setVisibleProperties(String... properties) {
Arrays.stream(CrudOperation.values()).forEach(operation -> setVisibleProperties(operation, properties));
}

@Override
public void hideProperties(CrudOperation operation, String... hiddenProps) {
CrudFormConfiguration configuration = getConfiguration(operation);
ArrayList<String> visibleProps = new ArrayList<>(configuration.getVisibleProperties());
for (String prop : hiddenProps) {
visibleProps.remove(prop);
}
configuration.setVisibleProperties(visibleProps);
}

@Override
public void hideProperties(String... hiddenProps) {
Arrays.stream(CrudOperation.values()).forEach(operation -> hideProperties(operation, hiddenProps));
}

@Override
public void setDisabledProperties(CrudOperation operation, String... properties) {
getConfiguration(operation).setDisabledProperties(Arrays.asList(properties));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public interface CrudFormFactory<T> extends Serializable {

void setVisibleProperties(String... properties);

void hideProperties(String... properties);

void hideProperties(CrudOperation operation, String... properties);

void setDisabledProperties(CrudOperation operation, String... properties);

void setDisabledProperties(String... properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.datetimepicker.DateTimePicker;
import com.vaadin.flow.component.textfield.BigDecimalField;
import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.NumberField;
import com.vaadin.flow.component.textfield.TextField;
import org.vaadin.crudui.form.FieldProvider;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

Expand All @@ -32,6 +38,22 @@ public HasValueAndElement buildField(Object t) {
return new DatePicker();
}

if (LocalDateTime.class.isAssignableFrom(type)) {
return new DateTimePicker();
}

if (Double.class.isAssignableFrom(type) || type == double.class) {
return new NumberField();
}

if (Integer.class.isAssignableFrom(type) || type == int.class) {
return new IntegerField();
}

if (BigDecimal.class.isAssignableFrom(type)) {
return new BigDecimalField();
}

if (Enum.class.isAssignableFrom(type)) {
Object[] values = type.getEnumConstants();
ComboBox comboBox = new ComboBox<>();
Expand Down
32 changes: 0 additions & 32 deletions crud-ui-demo/frontend/generated/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions crud-ui-demo/frontend/generated/vaadin-featureflags.ts

This file was deleted.

5 changes: 0 additions & 5 deletions crud-ui-demo/frontend/generated/vaadin.ts

This file was deleted.

31 changes: 0 additions & 31 deletions crud-ui-demo/frontend/generated/vite-devmode.ts

This file was deleted.

23 changes: 0 additions & 23 deletions crud-ui-demo/frontend/index.html

This file was deleted.

Loading