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

Commits:

8 changed files:

Changes:

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/edit/actions/DeleteEdit.java
    ... ... @@ -104,7 +104,7 @@ public final class DeleteEdit<D extends EditableDto, U extends ContentEditUI<D,
    104 104
                         JOptionPane.WARNING_MESSAGE,
    
    105 105
                         new Object[]{t("observe.ui.choice.confirm.delete"),
    
    106 106
                                 t("observe.ui.choice.cancel")},
    
    107
    -                    1);
    
    107
    +                    0);
    
    108 108
             } finally {
    
    109 109
                 busyModel.popTask();
    
    110 110
             }
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/referential/ContentReferentialUI.jaxx
    ... ... @@ -41,6 +41,7 @@
    41 41
     
    
    42 42
             javax.swing.DefaultListModel
    
    43 43
             javax.swing.ListSelectionModel
    
    44
    +        javax.swing.DefaultListSelectionModel
    
    44 45
             javax.swing.JTable
    
    45 46
             javax.swing.JTextField
    
    46 47
             javax.swing.UIManager
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/referential/ContentReferentialUI.jcss
    ... ... @@ -35,7 +35,8 @@ JLabel {
    35 35
     }
    
    36 36
     
    
    37 37
     #list {
    
    38
    -  selectionMode:{ListSelectionModel.SINGLE_SELECTION};
    
    38
    +  selectionMode:{DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION};
    
    39
    +  selectionModel:{new DefaultListSelectionModel()};
    
    39 40
       model:{new DefaultListModel()};
    
    40 41
     }
    
    41 42
     
    
    ... ... @@ -61,11 +62,11 @@ JLabel {
    61 62
     }
    
    62 63
     
    
    63 64
     #modify {
    
    64
    -  enabled:{states.isSelectedBean()};
    
    65
    +  enabled:{states.isSelectionSingle()};
    
    65 66
     }
    
    66 67
     
    
    67 68
     #detail {
    
    68
    -  enabled:{states.isSelectedBean()};
    
    69
    +  enabled:{states.isSelectionSingle()};
    
    69 70
     }
    
    70 71
     
    
    71 72
     #editTable {
    
    ... ... @@ -91,11 +92,11 @@ JLabel {
    91 92
     }
    
    92 93
     
    
    93 94
     #delete {
    
    94
    -  enabled:{states.isEditable() && states.isSelectedBean()};
    
    95
    +  enabled:{states.isEditable() && !states.isSelectionEmpty()};
    
    95 96
     }
    
    96 97
     
    
    97 98
     #showTechnicalInformations {
    
    98
    -  enabled:{!states.isCreatingMode() && (states.isEditing() || states.isSelectedBean())};
    
    99
    +  enabled:{!states.isCreatingMode() && (states.isEditing() || states.isSelectionSingle())};
    
    99 100
     }
    
    100 101
     
    
    101 102
     #showUniqueKeys {
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/referential/ContentReferentialUIHandler.java
    ... ... @@ -115,7 +115,7 @@ public class ContentReferentialUIHandler<D extends ReferentialDto, R extends Ref
    115 115
             list.setFixedCellWidth(200);
    
    116 116
             list.addListSelectionListener(e -> {
    
    117 117
                 if (!e.getValueIsAdjusting()) {
    
    118
    -                selectBean(list.getSelectedValue());
    
    118
    +                selectBean(list.getSelectedValuesList());
    
    119 119
                 }
    
    120 120
             });
    
    121 121
             list.addMouseListener(new MouseAdapter() {
    
    ... ... @@ -315,17 +315,18 @@ public class ContentReferentialUIHandler<D extends ReferentialDto, R extends Ref
    315 315
             getClientValidationContext().setEditingReferentielList(data);
    
    316 316
         }
    
    317 317
     
    
    318
    -    final void selectBean(R selectedReference) {
    
    318
    +    final void selectBean(List<R> selectedReference) {
    
    319 319
             ContentReferentialUIModel<D, R> model = getModel();
    
    320
    -        log.info(String.format("%sWill select entity [%s]", prefix, selectedReference));
    
    321
    -        if (selectedReference == null) {
    
    322
    -            model.getStates().setSelectedBeanReference(null);
    
    323
    -        } else {
    
    324
    -            model.getStates().setSelectedBeanReference(selectedReference);
    
    325
    -
    
    326
    -            //TODO update data cache
    
    327
    -            log.debug("Need update referential cache");
    
    328
    -        }
    
    320
    +        log.info(String.format("%sWill select entity(ies) [%s]", prefix, selectedReference));
    
    321
    +        model.getStates().setSelection(selectedReference);
    
    322
    +//        if (selectedReference == null) {
    
    323
    +//            model.getStates().setSelectedBeanReference(null);
    
    324
    +//        } else {
    
    325
    +//            model.getStates().setSelectedBeanReference(selectedReference);
    
    326
    +//
    
    327
    +//            //TODO update data cache
    
    328
    +//            log.debug("Need update referential cache");
    
    329
    +//        }
    
    329 330
             if (!model.getStates().isResetEdit()) {
    
    330 331
                 getContentOpen().selectFirstTab();
    
    331 332
             }
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/referential/ContentReferentialUIModelStates.java
    ... ... @@ -52,7 +52,6 @@ import java.util.Objects;
    52 52
      */
    
    53 53
     public abstract class ContentReferentialUIModelStates<D extends ReferentialDto, R extends ReferentialDtoReference> extends ContentUIModelStates {
    
    54 54
         public static final String PROPERTY_SELECTED_BEAN_REFERENCE = "selectedBeanReference";
    
    55
    -    public static final String PROPERTY_SELECTED_BEAN = "selectedBean";
    
    56 55
         /**
    
    57 56
          * Reference cache.
    
    58 57
          */
    
    ... ... @@ -64,13 +63,11 @@ public abstract class ContentReferentialUIModelStates<D extends ReferentialDto,
    64 63
         private final Class<D> mainType;
    
    65 64
         private final Class<R> mainReferenceType;
    
    66 65
         private final ContentReferentialUINavigationNode source;
    
    67
    -    private R selectedBeanReference;
    
    66
    +    private List<R> selection;
    
    68 67
         private Form<D> form;
    
    69 68
         private ToolkitIdLabel replaceReference;
    
    70 69
         private ContentReferentialUI<D, R, ?> ui;
    
    71 70
     
    
    72
    -    public abstract R toReference(D bean, ReferentialLocale referentialLocale);
    
    73
    -
    
    74 71
         public ContentReferentialUIModelStates(ContentReferentialUIModel<D, R> model, D bean) {
    
    75 72
             source = Objects.requireNonNull(model).getSource();
    
    76 73
             this.referenceCache = source.getContext().newReferenceCache();
    
    ... ... @@ -80,6 +77,8 @@ public abstract class ContentReferentialUIModelStates<D extends ReferentialDto,
    80 77
             model.getDecoratorService().installDecorator(bean);
    
    81 78
         }
    
    82 79
     
    
    80
    +    public abstract R toReference(D bean, ReferentialLocale referentialLocale);
    
    81
    +
    
    83 82
         public ContentReferentialUINavigationNode source() {
    
    84 83
             return source;
    
    85 84
         }
    
    ... ... @@ -101,7 +100,7 @@ public abstract class ContentReferentialUIModelStates<D extends ReferentialDto,
    101 100
             super.open(model);
    
    102 101
             ListModel<R> listModel = ui.getList().getModel();
    
    103 102
             if (listModel.getSize() > 0) {
    
    104
    -            setSelectedBeanReference(listModel.getElementAt(0));
    
    103
    +            setSelection(List.of(listModel.getElementAt(0)));
    
    105 104
             }
    
    106 105
         }
    
    107 106
     
    
    ... ... @@ -128,14 +127,37 @@ public abstract class ContentReferentialUIModelStates<D extends ReferentialDto,
    128 127
         }
    
    129 128
     
    
    130 129
         public R getSelectedBeanReference() {
    
    131
    -        return selectedBeanReference;
    
    130
    +        return isSelectionSingle() ? getSelection().get(0) : null;
    
    131
    +    }
    
    132
    +
    
    133
    +    public boolean isSelectionEmpty() {
    
    134
    +        return getSelection() == null || getSelection().isEmpty();
    
    135
    +    }
    
    136
    +
    
    137
    +    public boolean isSelectionSingle() {
    
    138
    +        return getSelection() != null && getSelection().size() == 1;
    
    139
    +    }
    
    140
    +
    
    141
    +    public boolean isSelectionMultiple() {
    
    142
    +        return getSelection() != null && getSelection().size() > 1;
    
    132 143
         }
    
    133 144
     
    
    134
    -    public void setSelectedBeanReference(R selectedBeanReference) {
    
    135
    -        R oldValue = getSelectedBeanReference();
    
    136
    -        this.selectedBeanReference = selectedBeanReference;
    
    137
    -        firePropertyChange(PROPERTY_SELECTED_BEAN_REFERENCE, oldValue, selectedBeanReference);
    
    138
    -        firePropertyChange(PROPERTY_SELECTED_BEAN, isSelectedBean());
    
    145
    +    public List<R> getSelection() {
    
    146
    +        return selection;
    
    147
    +    }
    
    148
    +
    
    149
    +    public void setSelection(List<R> selection) {
    
    150
    +        List<R> oldValue = getSelection();
    
    151
    +        R oldSelectionBean = getSelectedBeanReference();
    
    152
    +        boolean oldSelectionEmpty = isSelectionEmpty();
    
    153
    +        boolean oldSelectionSingle = isSelectionSingle();
    
    154
    +        boolean oldSelectionMultiple = isSelectionMultiple();
    
    155
    +        this.selection = selection;
    
    156
    +        firePropertyChange("selection", oldValue, selection);
    
    157
    +        firePropertyChange("selectionEmpty", oldSelectionEmpty, isSelectionEmpty());
    
    158
    +        firePropertyChange("selectionSingle", oldSelectionSingle, isSelectionSingle());
    
    159
    +        firePropertyChange("selectionMultiple", oldSelectionMultiple, isSelectionMultiple());
    
    160
    +        firePropertyChange(PROPERTY_SELECTED_BEAN_REFERENCE, oldSelectionBean, getSelectedBeanReference());
    
    139 161
         }
    
    140 162
     
    
    141 163
         public ToolkitIdLabel getReplaceReference() {
    
    ... ... @@ -157,10 +179,6 @@ public abstract class ContentReferentialUIModelStates<D extends ReferentialDto,
    157 179
             return referenceCache;
    
    158 180
         }
    
    159 181
     
    
    160
    -    public boolean isSelectedBean() {
    
    161
    -        return getSelectedBeanReference() != null;
    
    162
    -    }
    
    163
    -
    
    164 182
         public final List<R> getReferentialReferences(String... ids) {
    
    165 183
             ObserveSwingDataSource mainDataSource = getDataSourcesManager().getMainDataSource();
    
    166 184
             LinkedList<R> result = new LinkedList<>(mainDataSource.getReferentialReferences(mainReferenceType, ids));
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/referential/actions/DeleteReferential.java
    ... ... @@ -29,7 +29,6 @@ import fr.ird.observe.client.datasource.editor.api.content.referential.ContentRe
    29 29
     import fr.ird.observe.client.datasource.editor.api.content.referential.ContentReferentialUIModel;
    
    30 30
     import fr.ird.observe.client.datasource.editor.api.content.referential.usage.UsageForDeleteUIHandler;
    
    31 31
     import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTree;
    
    32
    -import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTreeModel;
    
    33 32
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode;
    
    34 33
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationNode;
    
    35 34
     import fr.ird.observe.dto.I18nDecoratorHelper;
    
    ... ... @@ -46,7 +45,9 @@ import org.apache.logging.log4j.LogManager;
    46 45
     import org.apache.logging.log4j.Logger;
    
    47 46
     
    
    48 47
     import java.awt.event.ActionEvent;
    
    48
    +import java.util.LinkedHashSet;
    
    49 49
     import java.util.List;
    
    50
    +import java.util.Set;
    
    50 51
     import java.util.stream.Collectors;
    
    51 52
     
    
    52 53
     import static io.ultreia.java4all.i18n.I18n.n;
    
    ... ... @@ -63,39 +64,42 @@ public final class DeleteReferential<D extends ReferentialDto, R extends Referen
    63 64
     
    
    64 65
         private ToolkitIdLabel replaceReference;
    
    65 66
     
    
    67
    +    public DeleteReferential(Class<D> dataType) {
    
    68
    +        super(dataType, n("observe.Common.action.delete"), I18n.t("observe.referential.Referential.action.delete.tip", I18nDecoratorHelper.getType(dataType)), "content-delete-16", ObserveKeyStrokesEditorApi.KEY_STROKE_DELETE_DATA_GLOBAL);
    
    69
    +    }
    
    70
    +
    
    66 71
         public static <D extends ReferentialDto, R extends ReferentialDtoReference, U extends ContentReferentialUI<D, R, U>> void installAction(U ui) {
    
    67 72
             DeleteReferential<D, R, U> action = new DeleteReferential<>(ui.getModel().getScope().getMainType());
    
    68 73
             init(ui, ui.getDelete(), action);
    
    69 74
         }
    
    70 75
     
    
    71
    -    public DeleteReferential(Class<D> dataType) {
    
    72
    -        super(dataType, n("observe.Common.action.delete"), I18n.t("observe.referential.Referential.action.delete.tip", I18nDecoratorHelper.getType(dataType)), "content-delete-16", ObserveKeyStrokesEditorApi.KEY_STROKE_DELETE_DATA_GLOBAL);
    
    73
    -    }
    
    74
    -
    
    75 76
         @Override
    
    76 77
         protected void doActionPerformed(ActionEvent event, U ui) {
    
    77 78
             ContentReferentialUIModel<D, R> model = ui.getModel();
    
    78
    -        R selectedBeanReference = model.getStates().getSelectedBeanReference();
    
    79
    -        boolean canDelete = askToDelete(ui, selectedBeanReference);
    
    80
    -        if (canDelete) {
    
    81
    -            doDelete(ui, selectedBeanReference, replaceReference);
    
    82
    -            afterDelete(ui, selectedBeanReference);
    
    79
    +        List<R> selection = model.getStates().getSelection();
    
    80
    +        Set<R> deleted = new LinkedHashSet<>(selection.size());
    
    81
    +        Class<D> beanType = ui.getModel().getScope().getMainType();
    
    82
    +        Class<R> referenceType = model.getScope().getMainReferenceType();
    
    83
    +        ReferentialService referentialService = getServicesProvider().getReferentialService();
    
    84
    +        UsageService usageService = getServicesProvider().getUsageService();
    
    85
    +        for (R selectedBeanReference : selection) {
    
    86
    +            boolean canDelete = askToDelete(ui, model, beanType, referenceType, usageService, selectedBeanReference);
    
    87
    +            if (canDelete) {
    
    88
    +                doDelete(beanType, referentialService, selectedBeanReference, replaceReference);
    
    89
    +                deleted.add(selectedBeanReference);
    
    90
    +            }
    
    83 91
             }
    
    92
    +        afterDelete(ui, deleted);
    
    84 93
         }
    
    85 94
     
    
    86
    -    private boolean askToDelete(U ui, R bean) {
    
    87
    -
    
    88
    -        ContentReferentialUIModel<D, R> model = ui.getModel();
    
    95
    +    private boolean askToDelete(U ui, ContentReferentialUIModel<D, R> model, Class<D> beanType, Class<R> referenceType, UsageService usageService, R bean) {
    
    89 96
     
    
    90 97
             // recherche des utilisation du bean dans la base
    
    91
    -        UsageService usageService = getServicesProvider().getUsageService();
    
    92 98
             ToolkitIdDtoBean request = model.getStates().toUsageRequest(bean.getId());
    
    93 99
             UsageCount usages = usageService.countReferential(request);
    
    94 100
     
    
    95 101
             replaceReference = null;
    
    96 102
     
    
    97
    -        Class<D> beanType = model.getScope().getMainType();
    
    98
    -        Class<R> referenceType = model.getScope().getMainReferenceType();
    
    99 103
             if (!usages.isEmpty()) {
    
    100 104
     
    
    101 105
                 // some usages were found
    
    ... ... @@ -126,42 +130,46 @@ public final class DeleteReferential<D extends ReferentialDto, R extends Referen
    126 130
             return DeleteEdit.confirmForEntityDelete(ui, bean);
    
    127 131
         }
    
    128 132
     
    
    129
    -    private void doDelete(U ui, ReferentialDtoReference bean, ToolkitIdLabel replaceReference) {
    
    133
    +    private void doDelete(Class<D> beanType, ReferentialService referentialService, ReferentialDtoReference bean, ToolkitIdLabel replaceReference) {
    
    130 134
     
    
    131 135
             String id = bean.getId();
    
    132
    -        Class<D> beanType = ui.getModel().getScope().getMainType();
    
    133
    -        ReferentialService referentialService = getServicesProvider().getReferentialService();
    
    134 136
             if (replaceReference != null) {
    
    135 137
                 String replaceId = replaceReference.getId();
    
    136 138
                 log.info(String.format("Do replace reference before delete (%s → %s)", id, replaceId));
    
    137 139
                 referentialService.replaceReference(beanType, id, replaceId);
    
    138 140
             }
    
    139 141
             referentialService.delete(beanType, id);
    
    140
    -
    
    141 142
         }
    
    142 143
     
    
    143
    -    private void afterDelete(U ui, ReferentialDtoReference bean) {
    
    144
    +    private void afterDelete(U ui, Set<R> deleted) {
    
    145
    +        ui.getModel().getStates().setSelection(null);
    
    144 146
             ui.stopEdit();
    
    145 147
     
    
    146 148
             DataSourceEditor dataSourceEditor = getDataSourceEditor();
    
    147 149
             NavigationTree tree = dataSourceEditor.getNavigationUI().getTree();
    
    148
    -        updateNavigationTreeStructure(tree, bean.getId());
    
    150
    +        boolean needUpdateNavigationResult = isNeedUpdateNavigationResult(tree.getRootNode(), deleted);
    
    151
    +        if (needUpdateNavigationResult) {
    
    152
    +            // update navigation result
    
    153
    +            tree.getModel().updateNavigationResult();
    
    154
    +        }
    
    149 155
             NavigationNode selectedNode = tree.getSelectedNode();
    
    150 156
             selectedNode.reloadNodeData();
    
    151 157
             tree.reSelectSafeNodeThen(selectedNode, () -> dataSourceEditor.getModel().resetFromPreviousUi(ui));
    
    152 158
         }
    
    153 159
     
    
    154
    -    private void updateNavigationTreeStructure(NavigationTree tree, String id) {
    
    155
    -        NavigationTreeModel model = tree.getModel();
    
    156
    -        RootNavigationNode rootNode = tree.getRootNode();
    
    160
    +    private boolean isNeedUpdateNavigationResult(RootNavigationNode rootNode, Set<R> deleted) {
    
    161
    +        boolean needUpdateNavigationResult = false;
    
    157 162
             if (rootNode.getInitializer().getRequest().isLoadData()) {
    
    158
    -            NavigationNode groupByNode = rootNode.findChildById(id);
    
    159
    -            if (groupByNode != null) {
    
    160
    -                // remove node from tree
    
    161
    -                rootNode.remove(groupByNode);
    
    162
    -                // update navigation result
    
    163
    -                model.updateNavigationResult();
    
    163
    +            for (R r : deleted) {
    
    164
    +                String id = r.getId();
    
    165
    +                NavigationNode groupByNode = rootNode.findChildById(id);
    
    166
    +                if (groupByNode != null) {
    
    167
    +                    // remove node from tree
    
    168
    +                    rootNode.remove(groupByNode);
    
    169
    +                    needUpdateNavigationResult = true;
    
    170
    +                }
    
    164 171
                 }
    
    165 172
             }
    
    173
    +        return needUpdateNavigationResult;
    
    166 174
         }
    
    167 175
     }

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/referential/actions/ReferentialResetAdapter.java
    ... ... @@ -28,6 +28,8 @@ import fr.ird.observe.client.datasource.editor.api.content.referential.ContentRe
    28 28
     import fr.ird.observe.dto.reference.ReferentialDtoReference;
    
    29 29
     import fr.ird.observe.dto.referential.ReferentialDto;
    
    30 30
     
    
    31
    +import java.util.List;
    
    32
    +
    
    31 33
     /**
    
    32 34
      * Created on 19/10/2020.
    
    33 35
      *
    
    ... ... @@ -52,7 +54,7 @@ public class ReferentialResetAdapter<D extends ReferentialDto, R extends Referen
    52 54
             model.getStates().setResetEdit(true);
    
    53 55
             try {
    
    54 56
                 ui.getList().setSelectedValue(selectedBean, false);
    
    55
    -            model.getStates().setSelectedBeanReference(selectedBean);
    
    57
    +            model.getStates().setSelection(List.of(selectedBean));
    
    56 58
                 ui.getModify().doClick();
    
    57 59
             } finally {
    
    58 60
                 model.getStates().setResetEdit(false);
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/referential/actions/SaveContentReferentialUIAdapter.java
    ... ... @@ -34,6 +34,8 @@ import fr.ird.observe.dto.reference.ReferentialDtoReference;
    34 34
     import fr.ird.observe.dto.referential.ReferentialDto;
    
    35 35
     import fr.ird.observe.navigation.tree.io.request.ToolkitTreeFlatModelRootRequest;
    
    36 36
     
    
    37
    +import java.util.List;
    
    38
    +
    
    37 39
     /**
    
    38 40
      * Created on 19/10/2020.
    
    39 41
      *
    
    ... ... @@ -53,7 +55,7 @@ public class SaveContentReferentialUIAdapter<D extends ReferentialDto, R extends
    53 55
     
    
    54 56
             ContentReferentialUIModelStates<D, R> states = ui.getModel().getStates();
    
    55 57
             R reference = states.toReference(bean, dataSourceEditor.getConfig().getReferentialLocale());
    
    56
    -        states.setSelectedBeanReference(reference);
    
    58
    +        states.setSelection(List.of(reference));
    
    57 59
     
    
    58 60
             updateNavigationTreeStructure(notPersisted, bean, tree, states);
    
    59 61
             tree.reSelectSafeNodeThen(selectedNode, () -> dataSourceEditor.getModel().resetFromPreviousUi(ui));