Tony CHEMIT pushed to branch develop-9.3.x at ultreiaio / ird-observe

Commits:

5 changed files:

Changes:

  • client/core/src/main/java/fr/ird/observe/client/util/table/JXTableUtil.java
    ... ... @@ -24,6 +24,7 @@ package fr.ird.observe.client.util.table;
    24 24
     
    
    25 25
     import fr.ird.observe.client.ClientUIContextApplicationComponent;
    
    26 26
     import fr.ird.observe.client.util.UIHelper;
    
    27
    +import fr.ird.observe.client.util.table.renderer.DecoratorTableRenderer;
    
    27 28
     import fr.ird.observe.dto.I18nDecoratorHelper;
    
    28 29
     import io.ultreia.java4all.decoration.Decorated;
    
    29 30
     import io.ultreia.java4all.decoration.Decorator;
    
    ... ... @@ -106,15 +107,7 @@ public class JXTableUtil {
    106 107
         }
    
    107 108
     
    
    108 109
         public static TableCellRenderer newDecoratedRenderer(Decorator decorator) {
    
    109
    -        StringValue sv = value -> {
    
    110
    -            if (value == null) {
    
    111
    -                return null;
    
    112
    -            }
    
    113
    -            Decorated reference = (Decorated) value;
    
    114
    -            reference.registerDecorator(decorator);
    
    115
    -            return reference.decorate();
    
    116
    -        };
    
    117
    -        return getDefaultTableRenderer(sv, true);
    
    110
    +        return new DecoratorTableRenderer(decorator);
    
    118 111
         }
    
    119 112
     
    
    120 113
         public static TableCellRenderer newEmptyNumberTableCellRenderer() {
    

  • client/core/src/main/java/fr/ird/observe/client/util/table/renderer/DecoratorTableRenderer.java
    1
    +package fr.ird.observe.client.util.table.renderer;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Client :: Core
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import io.ultreia.java4all.decoration.Decorated;
    
    26
    +import io.ultreia.java4all.decoration.Decorator;
    
    27
    +import org.jdesktop.swingx.renderer.DefaultTableRenderer;
    
    28
    +import org.jdesktop.swingx.renderer.LabelProvider;
    
    29
    +import org.jdesktop.swingx.renderer.StringValue;
    
    30
    +
    
    31
    +import javax.swing.JComponent;
    
    32
    +import javax.swing.JTable;
    
    33
    +import java.awt.Component;
    
    34
    +
    
    35
    +/**
    
    36
    + * Created at 11/09/2024.
    
    37
    + *
    
    38
    + * @author Tony Chemit - dev@tchemit.fr
    
    39
    + * @since 9.3.7
    
    40
    + */
    
    41
    +public class DecoratorTableRenderer extends DefaultTableRenderer {
    
    42
    +
    
    43
    +    public DecoratorTableRenderer(Decorator decorator) {
    
    44
    +        super(new DecoratorLabelProvider(decorator));
    
    45
    +    }
    
    46
    +
    
    47
    +    @Override
    
    48
    +    public DecoratorLabelProvider getComponentProvider() {
    
    49
    +        return (DecoratorLabelProvider) super.getComponentProvider();
    
    50
    +    }
    
    51
    +    public Decorator getDecorator() {
    
    52
    +        return getComponentProvider().getStringValue().getDecorator();
    
    53
    +    }
    
    54
    +    @Override
    
    55
    +    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    
    56
    +        JComponent tableCellRendererComponent = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    
    57
    +        String toolTipText = getString(value);
    
    58
    +        tableCellRendererComponent.setToolTipText(toolTipText);
    
    59
    +        return tableCellRendererComponent;
    
    60
    +    }
    
    61
    +
    
    62
    +    public static class DecoratorStringValue implements StringValue {
    
    63
    +
    
    64
    +        private final Decorator decorator;
    
    65
    +
    
    66
    +        private DecoratorStringValue(Decorator decorator) {
    
    67
    +            this.decorator = decorator;
    
    68
    +        }
    
    69
    +
    
    70
    +        @Override
    
    71
    +        public String getString(Object value) {
    
    72
    +            if (value == null) {
    
    73
    +                return null;
    
    74
    +            }
    
    75
    +            Decorated reference = (Decorated) value;
    
    76
    +            reference.registerDecorator(decorator);
    
    77
    +            return reference.decorate();
    
    78
    +        }
    
    79
    +
    
    80
    +        public Decorator getDecorator() {
    
    81
    +            return decorator;
    
    82
    +        }
    
    83
    +    }
    
    84
    +
    
    85
    +    public static class DecoratorLabelProvider extends LabelProvider {
    
    86
    +
    
    87
    +
    
    88
    +        public DecoratorLabelProvider(Decorator decorator) {
    
    89
    +            super(new DecoratorStringValue(decorator));
    
    90
    +        }
    
    91
    +
    
    92
    +        @Override
    
    93
    +        public DecoratorStringValue getStringValue() {
    
    94
    +            return (DecoratorStringValue) super.getStringValue();
    
    95
    +        }
    
    96
    +    }
    
    97
    +}

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIHandler.java
    ... ... @@ -173,6 +173,10 @@ public abstract class ContentUIHandler<U extends ContentUI> implements ObserveSe
    173 173
                     container = (Container) ui.getObjectById(DefaultUIInitializer.MAIN_TABBED_PANE);
    
    174 174
                     if (withSubTab) {
    
    175 175
                         container = (Container) ui.getObjectById(DefaultUIInitializer.SUB_TABBED_PANE);
    
    176
    +                    if (!container.isShowing()) {
    
    177
    +                        // stay on main tabbed pane
    
    178
    +                        container = (Container) ui.getObjectById(DefaultUIInitializer.MAIN_TABBED_PANE);
    
    179
    +                    }
    
    176 180
                     }
    
    177 181
                 } else {
    
    178 182
                     container = ui.getContentBody();
    
    ... ... @@ -183,11 +187,19 @@ public abstract class ContentUIHandler<U extends ContentUI> implements ObserveSe
    183 187
         }
    
    184 188
     
    
    185 189
         public Component computeFocusOwner() {
    
    190
    +        //FIXME Review this on Focus clean session
    
    186 191
             Container container = computeFocusOwnerContainer();
    
    187 192
             if (container instanceof JTabbedPane) {
    
    188 193
                 container = (Container) ((JTabbedPane) container).getSelectedComponent();
    
    189 194
             }
    
    190
    -        return ui.getFocusTraversalPolicy().getFirstComponent(container);
    
    195
    +        Component result = ui.getFocusTraversalPolicy().getFirstComponent(container);
    
    196
    +        if (ui.getModel().getStates().isReadingMode()) {
    
    197
    +            return result;
    
    198
    +        }
    
    199
    +        if (result instanceof JTabbedPane) {
    
    200
    +            result = ((JTabbedPane) result).getSelectedComponent();
    
    201
    +        }
    
    202
    +        return ui.getFocusTraversalPolicy().getFirstComponent((Container) result);
    
    191 203
         }
    
    192 204
     
    
    193 205
         public void onModeChanged(ContentMode newMode) {
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/table/ContentTableUIHandler.java
    ... ... @@ -45,6 +45,7 @@ import fr.ird.observe.client.datasource.editor.api.content.data.table.actions.en
    45 45
     import fr.ird.observe.client.datasource.editor.api.content.data.table.actions.entry.select.SelectNext;
    
    46 46
     import fr.ird.observe.client.datasource.editor.api.content.data.table.actions.entry.select.SelectPrevious;
    
    47 47
     import fr.ird.observe.client.datasource.editor.api.content.data.table.sortable.AutoSelectWithMoveUpAndDownShowPopupAction;
    
    48
    +import fr.ird.observe.client.datasource.editor.api.focus.ContentZone;
    
    48 49
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode;
    
    49 50
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationScope;
    
    50 51
     import fr.ird.observe.client.main.focus.FocusDispatcher;
    
    ... ... @@ -64,6 +65,7 @@ import java.awt.BorderLayout;
    64 65
     import java.awt.Component;
    
    65 66
     import java.awt.Container;
    
    66 67
     import java.awt.Rectangle;
    
    68
    +import java.util.Objects;
    
    67 69
     import java.util.function.Function;
    
    68 70
     
    
    69 71
     /**
    
    ... ... @@ -376,7 +378,7 @@ public abstract class ContentTableUIHandler<D extends DataDto, C extends Contain
    376 378
                         if (focusComponent instanceof JComponent) {
    
    377 379
                             focusComponent = focusDispatcher.dispatchFocus((JComponent) focusComponent);
    
    378 380
                         }
    
    379
    -                    SwingUtilities.invokeLater(focusComponent::requestFocusInWindow);
    
    381
    +//                    SwingUtilities.invokeLater(focusComponent::requestFocusInWindow);
    
    380 382
                     }
    
    381 383
                 }
    
    382 384
     
    
    ... ... @@ -385,11 +387,13 @@ public abstract class ContentTableUIHandler<D extends DataDto, C extends Contain
    385 387
                 SwingUtilities.invokeLater(() -> {
    
    386 388
                     if (getFocusModel() != null) {
    
    387 389
                         unblockFocus();
    
    388
    -                    ui.getHandler().grabFocusOnForm();
    
    389
    -                    if (finalFocusComponent != null) {
    
    390
    -                        SwingUtilities.invokeLater(finalFocusComponent::requestFocusInWindow);
    
    390
    +                    //FIXME Review this on Focus clean session (the blockFocus does not work!!!)
    
    391
    +                    if (Objects.equals(getFocusModel().getFocusOwnerZone(), ContentZone.ZONE_NAME)) {
    
    392
    +                        ui.getHandler().grabFocusOnForm();
    
    393
    +                        if (finalFocusComponent != null) {
    
    394
    +                            SwingUtilities.invokeLater(finalFocusComponent::requestFocusInWindow);
    
    395
    +                        }
    
    391 396
                         }
    
    392
    -                    ;
    
    393 397
                     }
    
    394 398
                 });
    
    395 399
             }
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/table/ContentTableUITableModel.java
    ... ... @@ -194,7 +194,7 @@ public abstract class ContentTableUITableModel<D extends DataDto, C extends Cont
    194 194
             if (getColumnMeta(0).getType().equals(int.class)) {
    
    195 195
                 sorter.setComparator(0, Comparator.comparingInt(v -> (int) v));
    
    196 196
             }
    
    197
    -        int index=-1;
    
    197
    +        int index = -1;
    
    198 198
             for (ContentTableMeta<C> meta : metas) {
    
    199 199
                 index++;
    
    200 200
                 Class<?> type = meta.getType();
    
    ... ... @@ -205,6 +205,12 @@ public abstract class ContentTableUITableModel<D extends DataDto, C extends Cont
    205 205
                     DecoratedSorter<?> decoratedSorter = decorator.definition().sorter();
    
    206 206
                     Comparator<?> comparator = decoratedSorter.getComparator((DecoratorDefinition) decorator.definition(), decoratorService.getReferentialLocale().getLocale(), decoratorIndex);
    
    207 207
                     sorter.setComparator(index, comparator);
    
    208
    +            } else if (boolean.class.equals(type)) {
    
    209
    +                sorter.setComparator(index, Comparator.comparingInt(v -> (boolean) v ? 1 : 0));
    
    210
    +            } else if (Boolean.class.equals(type)) {
    
    211
    +                sorter.setComparator(index, Comparator.nullsLast(Comparator.comparingInt(v -> (Boolean) v ? 1 : 0)));
    
    212
    +            } else if (Enum.class.isAssignableFrom(type)) {
    
    213
    +                sorter.setComparator(index, Comparator.comparing(Object::toString));
    
    208 214
                 }
    
    209 215
             }
    
    210 216