Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe WARNING: The push did not contain any new commits, but force pushed to delete the commits and changes below. Deleted commits: d16efe06 by Tony Chemit at 2024-09-06T12:42:50+02:00 update decorator and pom - - - - - 9daea82d by Tony Chemit at 2024-09-06T12:52:39+02:00 override DecoratorSorted.getComparator - - - - - 62e6eeaf by Tony Chemit at 2024-09-06T12:52:39+02:00 use Decorator comparator in RowSorter - - - - - e78ff0dd by Tony Chemit at 2024-09-06T12:53:14+02:00 Merge branch 'feature/issue_1203' into develop Tableaux de saisie (captures, échantillons, équipements...) - Classement en cliquant sur les en-têtes de colonnes - Closes #1203 - - - - - 5 changed files: - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/table/ContentTableUITableModel.java - pom.xml - toolkit/api-decoration/src/main/java/fr/ird/observe/decoration/DefaultDecoratorRenderer.java - toolkit/api-decoration/src/main/java/fr/ird/observe/decoration/JavaBeanDecoratorRenderer.java - toolkit/api-decoration/src/main/java/fr/ird/observe/decoration/ToolkitIdLabelDecoratorRenderer.java Changes: ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/table/ContentTableUITableModel.java ===================================== @@ -26,11 +26,16 @@ import fr.ird.observe.client.datasource.editor.api.content.data.table.actions.en import fr.ird.observe.client.datasource.editor.api.content.ui.table.EditableTable; import fr.ird.observe.client.util.UIHelper; import fr.ird.observe.client.util.table.EditableTableModelWithCache; +import fr.ird.observe.decoration.DecoratorService; import fr.ird.observe.dto.IdDto; import fr.ird.observe.dto.data.ContainerChildDto; import fr.ird.observe.dto.data.DataDto; import fr.ird.observe.dto.data.WithIndex; import io.ultreia.java4all.bean.JavaBean; +import io.ultreia.java4all.decoration.Decorated; +import io.ultreia.java4all.decoration.DecoratedSorter; +import io.ultreia.java4all.decoration.Decorator; +import io.ultreia.java4all.decoration.DecoratorDefinition; import io.ultreia.java4all.i18n.I18n; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -189,6 +194,20 @@ public abstract class ContentTableUITableModel<D extends DataDto, C extends Cont if (getColumnMeta(0).getType().equals(int.class)) { sorter.setComparator(0, Comparator.comparingInt(v -> (int) v)); } + int index=-1; + for (ContentTableMeta<C> meta : metas) { + index++; + Class<?> type = meta.getType(); + if (Decorated.class.isAssignableFrom(type)) { + DecoratorService decoratorService = getContext().getModel().getDecoratorService(); + Decorator decorator = decoratorService.getDecoratorByType(type); + int decoratorIndex = decorator.configuration().getIndex(); + DecoratedSorter<?> decoratedSorter = decorator.definition().sorter(); + Comparator<?> comparator = decoratedSorter.getComparator((DecoratorDefinition) decorator.definition(), decoratorService.getReferentialLocale().getLocale(), decoratorIndex); + sorter.setComparator(index, comparator); + } + } + table.setSortable(true); } ===================================== pom.xml ===================================== @@ -23,7 +23,7 @@ <parent> <groupId>io.ultreia.maven</groupId> <artifactId>pom</artifactId> - <version>2024.34</version> + <version>2024.36-SNAPSHOT</version> </parent> <groupId>fr.ird.observe</groupId> <artifactId>ird-observe</artifactId> ===================================== toolkit/api-decoration/src/main/java/fr/ird/observe/decoration/DefaultDecoratorRenderer.java ===================================== @@ -144,4 +144,8 @@ public class DefaultDecoratorRenderer<O> extends DecoratorRenderer<O> { return propertyName.toLowerCase().contains("timestamp"); } + protected boolean isTemporal(String propertyName) { + return isDate(propertyName) || isTimestamp(propertyName) || propertyName.toLowerCase().contains("time"); + } + } ===================================== toolkit/api-decoration/src/main/java/fr/ird/observe/decoration/JavaBeanDecoratorRenderer.java ===================================== @@ -34,6 +34,7 @@ import io.ultreia.java4all.lang.Strings; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Locale; @@ -96,6 +97,36 @@ public class JavaBeanDecoratorRenderer<O extends JavaBean> extends DefaultDecora defaultSort(propertyName, definition, locale, pos, dataList); } + @Override + public Comparator<O> getComparator(DecoratorDefinition<O, ?> definition, Locale locale, int pos) { + String propertyName = definition.properties().get(pos); + if (getCodeProperties().contains(propertyName)) { + return Comparator.comparing(d -> { + Object context = d.get(propertyName); + if (context == null) { + return null; + } + String text = String.valueOf(context); + return sortByCodeFunction(text); + }); + } + if (isTemporal(propertyName)) { + // sort on date, can not use toString render to sort (wrong order when using date pattern dd/MM/yyyy) + return Comparator.comparing(d -> ((Date) d.get(propertyName)).getTime()); + } + JavaBeanPropertyDefinition<JavaBean, Object> propertyDefinition = getJavaBeanDefinition().readProperty(propertyName); + if (Number.class.isAssignableFrom(propertyDefinition.type()) || + int.class.isAssignableFrom(propertyDefinition.type()) || + float.class.isAssignableFrom(propertyDefinition.type()) || + long.class.isAssignableFrom(propertyDefinition.type())) { + return Comparator.comparing(d -> d.get(propertyName)); + } + if (StatisticValue.class.isAssignableFrom(propertyDefinition.type())) { + return Comparator.comparingLong(d -> ((StatisticValue) d.get(propertyName)).getValue()); + } + return Comparator.comparing(d -> definition.decorate(locale, d, pos)); + } + protected void defaultSort(String propertyName, DecoratorDefinition<O, ?> definition, Locale locale, int pos, List<O> dataList) { super.sort(definition, locale, pos, dataList); } ===================================== toolkit/api-decoration/src/main/java/fr/ird/observe/decoration/ToolkitIdLabelDecoratorRenderer.java ===================================== @@ -32,6 +32,7 @@ import org.apache.logging.log4j.Logger; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.Set; @@ -71,6 +72,43 @@ public class ToolkitIdLabelDecoratorRenderer extends JavaBeanDecoratorRenderer<T sortByCode(pos, dataList); } + @Override + public Comparator<ToolkitIdLabel> getComparator(DecoratorDefinition<ToolkitIdLabel, ?> definition, Locale locale, int pos) { + String propertyName = definition.properties().get(pos); + if (isDate(propertyName)) { + + // sort on date, can not use toString render to sort (wrong order when using date pattern dd/MM/yyyy) + SimpleDateFormat dateFormat = I18nDecoratorHelper.newDateFormat(locale); + return Comparator.comparingLong(d -> { + String o = d.getText(pos); + try { + return dateFormat.parse(o).getTime(); + } catch (ParseException e) { + return 0; + } + + }); + } + if (isTimestamp(propertyName)) { + // sort on timestamp, can not use toString render to sort (wrong order when using date pattern dd/MM/yyyy HH:mm) + SimpleDateFormat dateFormat = I18nDecoratorHelper.newTimestampFormat(locale); + return Comparator.comparingLong(d -> { + String o = d.getText(pos); + try { + return dateFormat.parse(o).getTime(); + } catch (ParseException e) { + return 0; + } + + }); + } + return Comparator.comparing(d -> { + String o = d.getText(pos); + return sortByCodeFunction(o); + + }); + } + protected void sortByDate(int pos, SimpleDateFormat dateFormat, List<ToolkitIdLabel> dataList) { Multimap<Long, ToolkitIdLabel> dataToDate = ArrayListMultimap.create(); for (ToolkitIdLabel data : dataList) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/f518f0e1541d1ce0fa340e81a... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/f518f0e1541d1ce0fa340e81a... You're receiving this email because of your account on gitlab.com.