Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
d16efe06
by Tony Chemit at 2024-09-06T12:42:50+02:00
-
9daea82d
by Tony Chemit at 2024-09-06T12:52:39+02:00
-
62e6eeaf
by Tony Chemit at 2024-09-06T12:52:39+02:00
-
e78ff0dd
by Tony Chemit at 2024-09-06T12:53:14+02:00
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:
| ... | ... | @@ -26,11 +26,16 @@ import fr.ird.observe.client.datasource.editor.api.content.data.table.actions.en |
| 26 | 26 | import fr.ird.observe.client.datasource.editor.api.content.ui.table.EditableTable;
|
| 27 | 27 | import fr.ird.observe.client.util.UIHelper;
|
| 28 | 28 | import fr.ird.observe.client.util.table.EditableTableModelWithCache;
|
| 29 | +import fr.ird.observe.decoration.DecoratorService;
|
|
| 29 | 30 | import fr.ird.observe.dto.IdDto;
|
| 30 | 31 | import fr.ird.observe.dto.data.ContainerChildDto;
|
| 31 | 32 | import fr.ird.observe.dto.data.DataDto;
|
| 32 | 33 | import fr.ird.observe.dto.data.WithIndex;
|
| 33 | 34 | import io.ultreia.java4all.bean.JavaBean;
|
| 35 | +import io.ultreia.java4all.decoration.Decorated;
|
|
| 36 | +import io.ultreia.java4all.decoration.DecoratedSorter;
|
|
| 37 | +import io.ultreia.java4all.decoration.Decorator;
|
|
| 38 | +import io.ultreia.java4all.decoration.DecoratorDefinition;
|
|
| 34 | 39 | import io.ultreia.java4all.i18n.I18n;
|
| 35 | 40 | import org.apache.logging.log4j.LogManager;
|
| 36 | 41 | import org.apache.logging.log4j.Logger;
|
| ... | ... | @@ -189,6 +194,20 @@ public abstract class ContentTableUITableModel<D extends DataDto, C extends Cont |
| 189 | 194 | if (getColumnMeta(0).getType().equals(int.class)) {
|
| 190 | 195 | sorter.setComparator(0, Comparator.comparingInt(v -> (int) v));
|
| 191 | 196 | }
|
| 197 | + int index=-1;
|
|
| 198 | + for (ContentTableMeta<C> meta : metas) {
|
|
| 199 | + index++;
|
|
| 200 | + Class<?> type = meta.getType();
|
|
| 201 | + if (Decorated.class.isAssignableFrom(type)) {
|
|
| 202 | + DecoratorService decoratorService = getContext().getModel().getDecoratorService();
|
|
| 203 | + Decorator decorator = decoratorService.getDecoratorByType(type);
|
|
| 204 | + int decoratorIndex = decorator.configuration().getIndex();
|
|
| 205 | + DecoratedSorter<?> decoratedSorter = decorator.definition().sorter();
|
|
| 206 | + Comparator<?> comparator = decoratedSorter.getComparator((DecoratorDefinition) decorator.definition(), decoratorService.getReferentialLocale().getLocale(), decoratorIndex);
|
|
| 207 | + sorter.setComparator(index, comparator);
|
|
| 208 | + }
|
|
| 209 | + }
|
|
| 210 | + |
|
| 192 | 211 | table.setSortable(true);
|
| 193 | 212 | }
|
| 194 | 213 |
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | <parent>
|
| 24 | 24 | <groupId>io.ultreia.maven</groupId>
|
| 25 | 25 | <artifactId>pom</artifactId>
|
| 26 | - <version>2024.34</version>
|
|
| 26 | + <version>2024.36-SNAPSHOT</version>
|
|
| 27 | 27 | </parent>
|
| 28 | 28 | <groupId>fr.ird.observe</groupId>
|
| 29 | 29 | <artifactId>ird-observe</artifactId>
|
| ... | ... | @@ -144,4 +144,8 @@ public class DefaultDecoratorRenderer<O> extends DecoratorRenderer<O> { |
| 144 | 144 | return propertyName.toLowerCase().contains("timestamp");
|
| 145 | 145 | }
|
| 146 | 146 | |
| 147 | + protected boolean isTemporal(String propertyName) {
|
|
| 148 | + return isDate(propertyName) || isTimestamp(propertyName) || propertyName.toLowerCase().contains("time");
|
|
| 149 | + }
|
|
| 150 | + |
|
| 147 | 151 | } |
| ... | ... | @@ -34,6 +34,7 @@ import io.ultreia.java4all.lang.Strings; |
| 34 | 34 | |
| 35 | 35 | import java.util.ArrayList;
|
| 36 | 36 | import java.util.Collection;
|
| 37 | +import java.util.Comparator;
|
|
| 37 | 38 | import java.util.Date;
|
| 38 | 39 | import java.util.List;
|
| 39 | 40 | import java.util.Locale;
|
| ... | ... | @@ -96,6 +97,36 @@ public class JavaBeanDecoratorRenderer<O extends JavaBean> extends DefaultDecora |
| 96 | 97 | defaultSort(propertyName, definition, locale, pos, dataList);
|
| 97 | 98 | }
|
| 98 | 99 | |
| 100 | + @Override
|
|
| 101 | + public Comparator<O> getComparator(DecoratorDefinition<O, ?> definition, Locale locale, int pos) {
|
|
| 102 | + String propertyName = definition.properties().get(pos);
|
|
| 103 | + if (getCodeProperties().contains(propertyName)) {
|
|
| 104 | + return Comparator.comparing(d -> {
|
|
| 105 | + Object context = d.get(propertyName);
|
|
| 106 | + if (context == null) {
|
|
| 107 | + return null;
|
|
| 108 | + }
|
|
| 109 | + String text = String.valueOf(context);
|
|
| 110 | + return sortByCodeFunction(text);
|
|
| 111 | + });
|
|
| 112 | + }
|
|
| 113 | + if (isTemporal(propertyName)) {
|
|
| 114 | + // sort on date, can not use toString render to sort (wrong order when using date pattern dd/MM/yyyy)
|
|
| 115 | + return Comparator.comparing(d -> ((Date) d.get(propertyName)).getTime());
|
|
| 116 | + }
|
|
| 117 | + JavaBeanPropertyDefinition<JavaBean, Object> propertyDefinition = getJavaBeanDefinition().readProperty(propertyName);
|
|
| 118 | + if (Number.class.isAssignableFrom(propertyDefinition.type()) ||
|
|
| 119 | + int.class.isAssignableFrom(propertyDefinition.type()) ||
|
|
| 120 | + float.class.isAssignableFrom(propertyDefinition.type()) ||
|
|
| 121 | + long.class.isAssignableFrom(propertyDefinition.type())) {
|
|
| 122 | + return Comparator.comparing(d -> d.get(propertyName));
|
|
| 123 | + }
|
|
| 124 | + if (StatisticValue.class.isAssignableFrom(propertyDefinition.type())) {
|
|
| 125 | + return Comparator.comparingLong(d -> ((StatisticValue) d.get(propertyName)).getValue());
|
|
| 126 | + }
|
|
| 127 | + return Comparator.comparing(d -> definition.decorate(locale, d, pos));
|
|
| 128 | + }
|
|
| 129 | + |
|
| 99 | 130 | protected void defaultSort(String propertyName, DecoratorDefinition<O, ?> definition, Locale locale, int pos, List<O> dataList) {
|
| 100 | 131 | super.sort(definition, locale, pos, dataList);
|
| 101 | 132 | }
|
| ... | ... | @@ -32,6 +32,7 @@ import org.apache.logging.log4j.Logger; |
| 32 | 32 | |
| 33 | 33 | import java.text.ParseException;
|
| 34 | 34 | import java.text.SimpleDateFormat;
|
| 35 | +import java.util.Comparator;
|
|
| 35 | 36 | import java.util.List;
|
| 36 | 37 | import java.util.Locale;
|
| 37 | 38 | import java.util.Set;
|
| ... | ... | @@ -71,6 +72,43 @@ public class ToolkitIdLabelDecoratorRenderer extends JavaBeanDecoratorRenderer<T |
| 71 | 72 | sortByCode(pos, dataList);
|
| 72 | 73 | }
|
| 73 | 74 | |
| 75 | + @Override
|
|
| 76 | + public Comparator<ToolkitIdLabel> getComparator(DecoratorDefinition<ToolkitIdLabel, ?> definition, Locale locale, int pos) {
|
|
| 77 | + String propertyName = definition.properties().get(pos);
|
|
| 78 | + if (isDate(propertyName)) {
|
|
| 79 | + |
|
| 80 | + // sort on date, can not use toString render to sort (wrong order when using date pattern dd/MM/yyyy)
|
|
| 81 | + SimpleDateFormat dateFormat = I18nDecoratorHelper.newDateFormat(locale);
|
|
| 82 | + return Comparator.comparingLong(d -> {
|
|
| 83 | + String o = d.getText(pos);
|
|
| 84 | + try {
|
|
| 85 | + return dateFormat.parse(o).getTime();
|
|
| 86 | + } catch (ParseException e) {
|
|
| 87 | + return 0;
|
|
| 88 | + }
|
|
| 89 | + |
|
| 90 | + });
|
|
| 91 | + }
|
|
| 92 | + if (isTimestamp(propertyName)) {
|
|
| 93 | + // sort on timestamp, can not use toString render to sort (wrong order when using date pattern dd/MM/yyyy HH:mm)
|
|
| 94 | + SimpleDateFormat dateFormat = I18nDecoratorHelper.newTimestampFormat(locale);
|
|
| 95 | + return Comparator.comparingLong(d -> {
|
|
| 96 | + String o = d.getText(pos);
|
|
| 97 | + try {
|
|
| 98 | + return dateFormat.parse(o).getTime();
|
|
| 99 | + } catch (ParseException e) {
|
|
| 100 | + return 0;
|
|
| 101 | + }
|
|
| 102 | + |
|
| 103 | + });
|
|
| 104 | + }
|
|
| 105 | + return Comparator.comparing(d -> {
|
|
| 106 | + String o = d.getText(pos);
|
|
| 107 | + return sortByCodeFunction(o);
|
|
| 108 | + |
|
| 109 | + });
|
|
| 110 | + }
|
|
| 111 | + |
|
| 74 | 112 | protected void sortByDate(int pos, SimpleDateFormat dateFormat, List<ToolkitIdLabel> dataList) {
|
| 75 | 113 | Multimap<Long, ToolkitIdLabel> dataToDate = ArrayListMultimap.create();
|
| 76 | 114 | for (ToolkitIdLabel data : dataList) {
|