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

Commits:

17 changed files:

Changes:

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/data/tree/actions/DataSourceInformation.java
    ... ... @@ -40,7 +40,7 @@ import static io.ultreia.java4all.i18n.I18n.t;
    40 40
     public class DataSourceInformation extends DataSelectionTreePaneActionSupport {
    
    41 41
     
    
    42 42
         public DataSourceInformation() {
    
    43
    -        super("", t("observe.action.info.storage.tip"), "information", ObserveKeyStrokesSupport.KEY_STROKE_DATA_SOURCE_INFORMATION);
    
    43
    +        super("", t("observe.action.info.storage.tip"), "information", ObserveKeyStrokesSupport.KEY_STROKE_CONFIGURE_LOCAL_SOURCE);
    
    44 44
         }
    
    45 45
     
    
    46 46
         @Override
    
    ... ... @@ -55,4 +55,12 @@ public class DataSourceInformation extends DataSelectionTreePaneActionSupport {
    55 55
                     JOptionPane.INFORMATION_MESSAGE);
    
    56 56
     
    
    57 57
         }
    
    58
    +
    
    59
    +    @Override
    
    60
    +    public void init() {
    
    61
    +        if (ui.isRight()) {
    
    62
    +            setKeyStroke(ObserveKeyStrokesSupport.KEY_STROKE_CONFIGURE_REMOTE_SOURCE);
    
    63
    +        }
    
    64
    +        defaultInit(getInputMap(ui, getInputMapCondition()), getActionMap(ui));
    
    65
    +    }
    
    58 66
     }

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/ReferentialSynchroUIHandler.java
    ... ... @@ -26,7 +26,6 @@ import fr.ird.observe.client.datasource.actions.AdminStep;
    26 26
     import fr.ird.observe.client.datasource.actions.AdminTabUIHandler;
    
    27 27
     import fr.ird.observe.client.datasource.actions.AdminUIModel;
    
    28 28
     import fr.ird.observe.client.datasource.actions.config.ConfigUI;
    
    29
    -import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.actions.SelectUnselect;
    
    30 29
     import fr.ird.observe.client.datasource.editor.wizard.StorageUIModel;
    
    31 30
     import fr.ird.observe.client.util.UIHelper;
    
    32 31
     import fr.ird.observe.services.configuration.ObserveDataSourceInformation;
    
    ... ... @@ -66,7 +65,7 @@ public class ReferentialSynchroUIHandler extends AdminTabUIHandler<ReferentialSy
    66 65
             configUI.getStepModel().addPropertyChangeListener(StorageUIModel.VALID_PROPERTY_NAME, evt -> updateSynchroModes());
    
    67 66
             configUI.getExtraConfig().add(extraConfig);
    
    68 67
             super.afterInit(ui);
    
    69
    -        SelectUnselect.init(ui.getLeftTreePane(), null, new SelectUnselect(ui.getRightTreePane()));
    
    68
    +//        SelectUnselect.init(ui.getLeftTreePane(), null, new SelectUnselect(ui.getRightTreePane()));
    
    70 69
             ui.getLeftTreePane().init();
    
    71 70
             ui.getRightTreePane().init();
    
    72 71
         }
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/actions/Start.java
    ... ... @@ -134,25 +134,25 @@ public class Start extends ReferentialSynchroUIActionSupport {
    134 134
     
    
    135 135
             sendMessage(message);
    
    136 136
     
    
    137
    -        tree.addMouseListener(new MouseAdapter() {
    
    138
    -            @Override
    
    139
    -            public void mouseReleased(MouseEvent e) {
    
    140
    -                if (e.getClickCount() == 2) {
    
    141
    -                    TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
    
    142
    -                    Object lastPathComponent = path.getLastPathComponent();
    
    143
    -                    if (lastPathComponent instanceof SynchroNodeSupport) {
    
    144
    -                        SynchroNodeSupport node = (SynchroNodeSupport) lastPathComponent;
    
    145
    -                        if(node instanceof ReferentialPropertyUpdatedNode && !node.getRoot().isShowProperties()) {
    
    146
    -                            // we can not modify property to update or revert in such mode
    
    147
    -                            return;
    
    148
    -                        }
    
    149
    -                        boolean newValue = !node.isSelected();
    
    150
    -                        log.info(String.format("Node: %s - new selected value: %s", node, newValue));
    
    151
    -                        tree.getTreeModel().setValueAt(node, newValue);
    
    152
    -                    }
    
    153
    -                }
    
    154
    -            }
    
    155
    -        });
    
    137
    +//        tree.addMouseListener(new MouseAdapter() {
    
    138
    +//            @Override
    
    139
    +//            public void mouseReleased(MouseEvent e) {
    
    140
    +//                if (e.getClickCount() == 2) {
    
    141
    +//                    TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
    
    142
    +//                    Object lastPathComponent = path.getLastPathComponent();
    
    143
    +//                    if (lastPathComponent instanceof SynchroNodeSupport) {
    
    144
    +//                        SynchroNodeSupport node = (SynchroNodeSupport) lastPathComponent;
    
    145
    +//                        if(node instanceof ReferentialPropertyUpdatedNode && !node.getRoot().isShowProperties()) {
    
    146
    +//                            // we can not modify property to update or revert in such mode
    
    147
    +//                            return;
    
    148
    +//                        }
    
    149
    +//                        boolean newValue = !node.isSelected();
    
    150
    +//                        log.info(String.format("Node: %s - new selected value: %s", node, newValue));
    
    151
    +//                        tree.getTreeModel().setValueAt(node, newValue);
    
    152
    +//                    }
    
    153
    +//                }
    
    154
    +//            }
    
    155
    +//        });
    
    156 156
         }
    
    157 157
     
    
    158 158
     
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/ReferentialSelectionTree.java
    ... ... @@ -22,12 +22,17 @@ package fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    +import com.google.common.collect.ImmutableSet;
    
    25 26
     import com.google.common.collect.ImmutableSetMultimap;
    
    26 27
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.RootSynchroNode;
    
    28
    +import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.SynchroNodeSupport;
    
    27 29
     import fr.ird.observe.client.util.UIHelper;
    
    28 30
     import org.jdesktop.swingx.JXTree;
    
    29 31
     
    
    32
    +import javax.swing.tree.TreePath;
    
    30 33
     import javax.swing.tree.TreeSelectionModel;
    
    34
    +import java.util.Collections;
    
    35
    +import java.util.Set;
    
    31 36
     
    
    32 37
     /**
    
    33 38
      * @author Tony Chemit - dev@tchemit.fr
    
    ... ... @@ -52,4 +57,16 @@ public class ReferentialSelectionTree extends JXTree {
    52 57
             return (ReferentialSynchronizeTreeModel) getModel();
    
    53 58
         }
    
    54 59
     
    
    60
    +    public Set<SynchroNodeSupport> getSelectedNodes() {
    
    61
    +        TreePath[] selectedRow = getSelectionPaths();
    
    62
    +        if (selectedRow == null || selectedRow.length == 0) {
    
    63
    +            return Collections.emptySet();
    
    64
    +        }
    
    65
    +        ImmutableSet.Builder<SynchroNodeSupport> resultBuilder = ImmutableSet.builder();
    
    66
    +        for (TreePath treePath : selectedRow) {
    
    67
    +            SynchroNodeSupport node = (SynchroNodeSupport) treePath.getLastPathComponent();
    
    68
    +            resultBuilder.add(node);
    
    69
    +        }
    
    70
    +        return resultBuilder.build();
    
    71
    +    }
    
    55 72
     }

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/ReferentialSelectionTreeCellRenderer.java
    ... ... @@ -35,8 +35,6 @@ import javax.swing.UIManager;
    35 35
     import java.awt.BorderLayout;
    
    36 36
     import java.awt.Component;
    
    37 37
     import java.awt.Dimension;
    
    38
    -import java.text.DateFormat;
    
    39
    -import java.text.SimpleDateFormat;
    
    40 38
     import java.util.Objects;
    
    41 39
     
    
    42 40
     /**
    
    ... ... @@ -45,12 +43,10 @@ import java.util.Objects;
    45 43
      */
    
    46 44
     public class ReferentialSelectionTreeCellRenderer extends DefaultXTreeCellRenderer implements WithDecoratorService {
    
    47 45
     
    
    48
    -    private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyy HH:mm");
    
    49
    -
    
    50 46
         private final JPanel panel;
    
    51 47
         private final JCheckBox selected;
    
    52 48
         private final Icon unselectedIcon;
    
    53
    -    private Icon partialIcon;
    
    49
    +    private final Icon partialIcon;
    
    54 50
     
    
    55 51
         ReferentialSelectionTreeCellRenderer() {
    
    56 52
             selected = new JCheckBox();
    
    ... ... @@ -60,10 +56,11 @@ public class ReferentialSelectionTreeCellRenderer extends DefaultXTreeCellRender
    60 56
             panel.add(this, BorderLayout.CENTER);
    
    61 57
             partialIcon = Objects.requireNonNull(UIManager.getIcon("checkbox.partial"));
    
    62 58
             unselectedIcon = Objects.requireNonNull(UIManager.getIcon("checkbox.empty"));
    
    63
    -        selected.setIcon(unselectedIcon);
    
    59
    +//        selected.setIcon(unselectedIcon);
    
    64 60
             Icon selectedIcon = Objects.requireNonNull(UIManager.getIcon("checkbox.selected"));
    
    65 61
             selected.setSelectedIcon(selectedIcon);
    
    66 62
         }
    
    63
    +
    
    67 64
         @Override
    
    68 65
         public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    
    69 66
     
    
    ... ... @@ -79,15 +76,21 @@ public class ReferentialSelectionTreeCellRenderer extends DefaultXTreeCellRender
    79 76
     
    
    80 77
             setIcon(icon);
    
    81 78
             setToolTipText(text);
    
    82
    -
    
    83
    -        if (!(node instanceof ReferentialPropertyUpdatedNode) || node.getRoot().isShowProperties()) {
    
    84
    -            boolean selected = node.isSelected();
    
    85
    -            this.selected.setSelected(selected);
    
    86
    -            panel.add(this.selected, BorderLayout.WEST);
    
    87
    -            this.selected.setIcon(selected || !node.isPartialSelected() ? unselectedIcon : partialIcon);
    
    79
    +        boolean selectedState;
    
    80
    +        Icon selectedIcon = unselectedIcon;
    
    81
    +        if (node.isLeaf()) {
    
    82
    +            selectedState = node.isSelected();
    
    88 83
             } else {
    
    89
    -            panel.remove(this.selected);
    
    84
    +            // node is selected (says has the icon selected) only if all his children are selected
    
    85
    +            selectedState = node.isFullySelected();
    
    86
    +            if (!selectedState && node.isPartialSelected()) {
    
    87
    +                // use partial icon, only if node is partial selected
    
    88
    +                 selectedIcon = partialIcon;
    
    89
    +            }
    
    90 90
             }
    
    91
    +        selected.setSelected(selectedState);
    
    92
    +        selected.setIcon(selectedIcon);
    
    93
    +        selected.setEnabled(!(node instanceof ReferentialPropertyUpdatedNode) || node.getRoot().isShowProperties());
    
    91 94
             panel.setPreferredSize(new Dimension(getPreferredSize().width + 20, getPreferredSize().height + 2));
    
    92 95
             return panel;
    
    93 96
         }
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/ReferentialSelectionTreePaneHandler.java
    ... ... @@ -32,6 +32,7 @@ import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.
    32 32
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.actions.RegisterDelete;
    
    33 33
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.actions.RegisterRevert;
    
    34 34
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.actions.RegisterSkip;
    
    35
    +import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.actions.SelectUnselect;
    
    35 36
     import org.nuiton.jaxx.runtime.spi.UIHandler;
    
    36 37
     
    
    37 38
     import java.awt.BorderLayout;
    
    ... ... @@ -53,7 +54,7 @@ public class ReferentialSelectionTreePaneHandler implements UIHandler<Referentia
    53 54
             RegisterDeactivateWithReplacement.init(ui, ui.deactivateWithReplace, new RegisterDeactivateWithReplacement(ui, isLeft));
    
    54 55
             RegisterDelete.init(ui, ui.delete, new RegisterDelete(ui, isLeft));
    
    55 56
             RegisterSkip.init(ui, ui.skip, new RegisterSkip(ui, isLeft));
    
    56
    -
    
    57
    +        SelectUnselect.init(ui, null, new SelectUnselect(ui));
    
    57 58
             if (!isLeft) {
    
    58 59
                 ui.remove(ui.getMiddleActions());
    
    59 60
                 ui.add(ui.getMiddleActions(), BorderLayout.WEST);
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/ReferentialSynchronizeTreeModel.java
    ... ... @@ -33,13 +33,13 @@ import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.
    33 33
     import fr.ird.observe.dto.referential.ReferentialDto;
    
    34 34
     
    
    35 35
     import javax.swing.tree.DefaultTreeModel;
    
    36
    +import javax.swing.tree.TreeNode;
    
    36 37
     import java.beans.PropertyChangeListener;
    
    37 38
     import java.beans.PropertyChangeSupport;
    
    38 39
     import java.util.Collection;
    
    39 40
     import java.util.Enumeration;
    
    40 41
     import java.util.LinkedList;
    
    41 42
     import java.util.List;
    
    42
    -import java.util.Optional;
    
    43 43
     import java.util.function.Predicate;
    
    44 44
     
    
    45 45
     /**
    
    ... ... @@ -50,8 +50,6 @@ import java.util.function.Predicate;
    50 50
     public class ReferentialSynchronizeTreeModel extends DefaultTreeModel {
    
    51 51
     
    
    52 52
         public static final String SELECTED_COUNT = "selectedCount";
    
    53
    -
    
    54
    -//    private static final Logger log = LogManager.getLogger(ReferentialSynchronizeTreeModel.class);
    
    55 53
         public static final String SELECTED = "selected";
    
    56 54
         private static final long serialVersionUID = 1L;
    
    57 55
         private static final String SELECTION_EMPTY = "selectionEmpty";
    
    ... ... @@ -59,13 +57,19 @@ public class ReferentialSynchronizeTreeModel extends DefaultTreeModel {
    59 57
     
    
    60 58
         private final ImmutableSetMultimap<Class<? extends ReferentialDto>, String> idsOnlyExistOnThisSide;
    
    61 59
     
    
    60
    +    /**
    
    61
    +     * List of selected referential nodes.
    
    62
    +     *
    
    63
    +     * <b>Be ware, a node present here means it is selected or partial selected!</b>
    
    64
    +     */
    
    65
    +    private final List<ReferentialSynchroNodeSupport> selected;
    
    62 66
         private boolean canAdd;
    
    63 67
         private boolean canUpdate;
    
    64 68
         private boolean canDelete;
    
    65 69
         private boolean canRevert;
    
    66
    -    private List<ReferentialSynchroNodeSupport> selected;
    
    67 70
     
    
    68 71
         private boolean adjusting;
    
    72
    +    private int oldSelectedCount;
    
    69 73
     
    
    70 74
         ReferentialSynchronizeTreeModel(RootSynchroNode root,
    
    71 75
                                         ImmutableSetMultimap<Class<? extends ReferentialDto>, String> idsOnlyExistOnThisSide) {
    
    ... ... @@ -75,50 +79,33 @@ public class ReferentialSynchronizeTreeModel extends DefaultTreeModel {
    75 79
         }
    
    76 80
     
    
    77 81
         public void setValueAt(SynchroNodeSupport node, boolean value) {
    
    78
    -        node.setSelected(value);
    
    79
    -        boolean oldSelectionEmpty = isSelectionEmpty();
    
    80
    -        int oldSelectedCount = getSelectedCount();
    
    81
    -
    
    82
    -        if (node instanceof ReferentialPropertyUpdatedNode) {
    
    83
    -            // this node can not be selected
    
    84
    -            if (!adjusting) {
    
    85
    -                updateSelectedActions();
    
    86
    -                nodeChanged(node);
    
    87
    -            }
    
    88
    -            return;
    
    82
    +        boolean wasAdjusting = adjusting;
    
    83
    +        if (!wasAdjusting) {
    
    84
    +            setAdjusting(true);
    
    89 85
             }
    
    90
    -        if (node instanceof ReferentialSynchroNodeSupport) {
    
    91
    -            if (value) {
    
    92
    -                selected.add((ReferentialSynchroNodeSupport) node);
    
    93
    -            } else {
    
    94
    -                selected.remove(node);
    
    95
    -            }
    
    96
    -            if (!adjusting) {
    
    97
    -                nodeChanged(node.getParent());
    
    98
    -                nodeChanged(node);
    
    99
    -            }
    
    100
    -        } else {
    
    101
    -            if (!adjusting) {
    
    102
    -                nodeChanged(node);
    
    103
    -            }
    
    104
    -            Enumeration<?> children = node.children();
    
    105
    -            while (children.hasMoreElements()) {
    
    106
    -                ReferentialSynchroNodeSupport child = (ReferentialSynchroNodeSupport) children.nextElement();
    
    107
    -                if (value) {
    
    108
    -                    selected.add(child);
    
    109
    -                } else {
    
    110
    -                    selected.remove(child);
    
    111
    -                }
    
    112
    -                if (!adjusting) {
    
    113
    -                    nodeChanged(child);
    
    86
    +        try {
    
    87
    +            if (node instanceof ReferentialTypeSynchroNode) {
    
    88
    +                ReferentialTypeSynchroNode node1 = (ReferentialTypeSynchroNode) node;
    
    89
    +                node1.updateSelect(value);
    
    90
    +                Enumeration<? extends TreeNode> children = node1.children();
    
    91
    +                while (children.hasMoreElements()) {
    
    92
    +                    ReferentialSynchroNodeSupport childNode = (ReferentialSynchroNodeSupport) children.nextElement();
    
    93
    +                    updateSelected(value, childNode);
    
    114 94
                     }
    
    95
    +            } else if (node instanceof ReferentialSynchroNodeSupport) {
    
    96
    +                ReferentialSynchroNodeSupport node1 = (ReferentialSynchroNodeSupport) node;
    
    97
    +                node1.updateSelect(value);
    
    98
    +                updateSelected(value, node1);
    
    99
    +            } else if (node instanceof ReferentialPropertyUpdatedNode) {
    
    100
    +                ReferentialPropertyUpdatedNode node1 = (ReferentialPropertyUpdatedNode) node;
    
    101
    +                node1.updateSelect(value);
    
    102
    +                updateSelected(node1.getParent().isSelected(), node1.getParent());
    
    103
    +            }
    
    104
    +        } finally {
    
    105
    +            if (!wasAdjusting) {
    
    106
    +                setAdjusting(false);
    
    115 107
                 }
    
    116 108
             }
    
    117
    -
    
    118
    -        if (!adjusting) {
    
    119
    -            fireSelectedChanged(oldSelectionEmpty, oldSelectedCount);
    
    120
    -        }
    
    121
    -
    
    122 109
         }
    
    123 110
     
    
    124 111
         public int getSelectedCount() {
    
    ... ... @@ -129,7 +116,6 @@ public class ReferentialSynchronizeTreeModel extends DefaultTreeModel {
    129 116
             return selected.isEmpty();
    
    130 117
         }
    
    131 118
     
    
    132
    -
    
    133 119
         public List<ReferentialSynchroNodeSupport> getSelected() {
    
    134 120
             return selected;
    
    135 121
         }
    
    ... ... @@ -145,10 +131,9 @@ public class ReferentialSynchronizeTreeModel extends DefaultTreeModel {
    145 131
                 canDelete |= node.isCanDelete();
    
    146 132
                 boolean canUpdate = node.isCanUpdate();
    
    147 133
                 boolean canRevert = node.isCanRevert();
    
    148
    -            if ((canUpdate || canRevert) && getRoot().isShowProperties() && node instanceof ReferentialUpdatedSynchroNode) {
    
    149
    -                ReferentialUpdatedSynchroNode node1 = (ReferentialUpdatedSynchroNode) node;
    
    150
    -                Optional<ImmutableSet<String>> selectedPropertyNames = node1.getPropertyNamesSelected();
    
    151
    -                canUpdate = canRevert = selectedPropertyNames.map(t -> t.size() > 0).orElse(false);
    
    134
    +            if ((canUpdate || canRevert) && node instanceof ReferentialUpdatedSynchroNode) {
    
    135
    +                // in this special cas, ask if node is really selected (means not without selected children)
    
    136
    +                canUpdate = canRevert = !node.isNotSelected();
    
    152 137
                 }
    
    153 138
                 this.canUpdate |= canUpdate;
    
    154 139
                 this.canRevert |= canRevert;
    
    ... ... @@ -192,23 +177,44 @@ public class ReferentialSynchronizeTreeModel extends DefaultTreeModel {
    192 177
         }
    
    193 178
     
    
    194 179
         public void clearSelection() {
    
    195
    -
    
    196
    -        boolean oldSelectionEmpty = isSelectionEmpty();
    
    197
    -        int oldSelectedCount = getSelectedCount();
    
    198
    -
    
    199
    -        for (ReferentialSynchroNodeSupport node : selected) {
    
    200
    -            node.setSelected(false);
    
    201
    -            nodeChanged(node);
    
    202
    -            nodeChanged(node.getParent());
    
    180
    +        setAdjusting(true);
    
    181
    +        try {
    
    182
    +            for (ReferentialSynchroNodeSupport node : selected) {
    
    183
    +                node.updateSelect(false);
    
    184
    +                nodeChanged(node);
    
    185
    +                nodeChanged(node.getParent());
    
    186
    +            }
    
    187
    +            selected.clear();
    
    188
    +        } finally {
    
    189
    +            setAdjusting(false);
    
    203 190
             }
    
    191
    +    }
    
    204 192
     
    
    205
    -        selected.clear();
    
    206
    -
    
    207
    -        pcs.firePropertyChange(SELECTION_EMPTY, oldSelectionEmpty, isSelectionEmpty());
    
    208
    -        pcs.firePropertyChange(SELECTED_COUNT, oldSelectedCount, getSelectedCount());
    
    209
    -        pcs.firePropertyChange(SELECTED, null, selected);
    
    193
    +    public void removeReferenceNodes(Collection<SynchroNodeSupport> removedNodes) {
    
    194
    +        setAdjusting(true);
    
    195
    +        try {
    
    196
    +            for (SynchroNodeSupport removedNode : removedNodes) {
    
    197
    +                if (removedNode instanceof ReferentialPropertyUpdatedNode) {
    
    198
    +                    removedNode.updateSelect(false);
    
    199
    +                    removeNodeFromParent(removedNode);
    
    200
    +                    continue;
    
    201
    +                }
    
    210 202
     
    
    211
    -        updateSelectedActions();
    
    203
    +                if (removedNode instanceof ReferentialSynchroNodeSupport) {
    
    204
    +                    ReferentialSynchroNodeSupport removedNode1 = (ReferentialSynchroNodeSupport) removedNode;
    
    205
    +                    removedNode1.updateSelect(false);
    
    206
    +                    selected.remove(removedNode1);
    
    207
    +                    ReferentialTypeSynchroNode typeNode = removedNode1.getParent();
    
    208
    +                    if (typeNode.getChildCount() == 1) {
    
    209
    +                        removeNodeFromParent(typeNode);
    
    210
    +                    } else {
    
    211
    +                        removeNodeFromParent(removedNode);
    
    212
    +                    }
    
    213
    +                }
    
    214
    +            }
    
    215
    +        } finally {
    
    216
    +            setAdjusting(false);
    
    217
    +        }
    
    212 218
         }
    
    213 219
     
    
    214 220
         @Override
    
    ... ... @@ -232,44 +238,30 @@ public class ReferentialSynchronizeTreeModel extends DefaultTreeModel {
    232 238
             pcs.removePropertyChangeListener(name, listener);
    
    233 239
         }
    
    234 240
     
    
    241
    +    private void updateSelected(boolean value, ReferentialSynchroNodeSupport node) {
    
    242
    +        if (value) {
    
    243
    +            selected.add(node);
    
    244
    +        } else {
    
    245
    +            selected.remove(node);
    
    246
    +        }
    
    247
    +    }
    
    248
    +
    
    235 249
         private void fireSelectedChanged(boolean oldSelectionEmpty, int oldSelectedCount) {
    
    250
    +        if (adjusting) {
    
    251
    +            return;
    
    252
    +        }
    
    253
    +        updateSelectedActions();
    
    236 254
             pcs.firePropertyChange(SELECTION_EMPTY, oldSelectionEmpty, isSelectionEmpty());
    
    237
    -        pcs.firePropertyChange(SELECTED_COUNT, oldSelectedCount, getSelectedCount());
    
    255
    +        pcs.firePropertyChange(SELECTED_COUNT, null, getSelectedCount());
    
    238 256
             pcs.firePropertyChange(SELECTED, null, selected);
    
    239
    -        updateSelectedActions();
    
    240 257
         }
    
    241 258
     
    
    242
    -    public void removeReferenceNodes(Collection<SynchroNodeSupport> removedNodes) {
    
    243
    -
    
    244
    -        boolean oldSelectionEmpty = isSelectionEmpty();
    
    245
    -        int oldSelectedCount = getSelectedCount();
    
    246
    -
    
    247
    -        adjusting = true;
    
    248
    -
    
    249
    -        try {
    
    250
    -            for (SynchroNodeSupport removedNode : removedNodes) {
    
    251
    -
    
    252
    -                if (removedNode instanceof ReferentialPropertyUpdatedNode) {
    
    253
    -                    removedNode.setSelected(false);
    
    254
    -                    removeNodeFromParent(removedNode);
    
    255
    -                    continue;
    
    256
    -                }
    
    257
    -
    
    258
    -                if (removedNode instanceof ReferentialSynchroNodeSupport) {
    
    259
    -                    ReferentialSynchroNodeSupport removedNode1 = (ReferentialSynchroNodeSupport) removedNode;
    
    260
    -                    removedNode1.setSelected(false);
    
    261
    -                    selected.remove(removedNode1);
    
    262
    -                    ReferentialTypeSynchroNode typeNode = removedNode1.getParent();
    
    263
    -                    if (typeNode.getChildCount() == 1) {
    
    264
    -                        removeNodeFromParent(typeNode);
    
    265
    -                    } else {
    
    266
    -                        removeNodeFromParent(removedNode);
    
    267
    -                    }
    
    268
    -                }
    
    269
    -            }
    
    270
    -        } finally {
    
    271
    -            adjusting = false;
    
    272
    -            fireSelectedChanged(oldSelectionEmpty, oldSelectedCount);
    
    259
    +    public void setAdjusting(boolean adjusting) {
    
    260
    +        this.adjusting = adjusting;
    
    261
    +        if (adjusting) {
    
    262
    +            oldSelectedCount = getSelectedCount();
    
    263
    +        } else {
    
    264
    +            fireSelectedChanged(oldSelectedCount == 0, oldSelectedCount);
    
    273 265
             }
    
    274 266
         }
    
    275 267
     }

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/ReferentialSynchronizeTreeModelsBuilder.java
    ... ... @@ -61,14 +61,13 @@ import java.util.Objects;
    61 61
     public class ReferentialSynchronizeTreeModelsBuilder {
    
    62 62
     
    
    63 63
         private static final Logger log = LogManager.getLogger(ReferentialSynchronizeTreeModelsBuilder.class);
    
    64
    -    private final boolean showProperties;
    
    64
    +
    
    65 65
         private final DifferentialEngine engine;
    
    66 66
         private final RootSynchroNode leftRootNode;
    
    67 67
         private final RootSynchroNode rightRootNode;
    
    68 68
         private final ProgressionModel progressionModel;
    
    69 69
     
    
    70 70
         public ReferentialSynchronizeTreeModelsBuilder(ReferentialSynchronizeMode synchronizeMode, boolean showProperties, DifferentialEngine engine, ProgressionModel progressionModel) {
    
    71
    -        this.showProperties = showProperties;
    
    72 71
             this.engine = Objects.requireNonNull(engine);
    
    73 72
             this.leftRootNode = new RootSynchroNode(true, Objects.requireNonNull(synchronizeMode).isLeftWrite(), showProperties);
    
    74 73
             this.rightRootNode = new RootSynchroNode(false, synchronizeMode.isRightWrite(), showProperties);
    
    ... ... @@ -119,11 +118,11 @@ public class ReferentialSynchronizeTreeModelsBuilder {
    119 118
             boolean leftCanWrite = leftRootNode.isCanWrite();
    
    120 119
     
    
    121 120
             CreateAddNode leftAddNode = new CreateAddNode(rightCanWrite, leftCanWrite);
    
    122
    -        CreateUpdateNode leftUpdateNode = new CreateUpdateNode(rightCanWrite, leftCanWrite, showProperties);
    
    121
    +        CreateUpdateNode leftUpdateNode = new CreateUpdateNode(rightCanWrite, leftCanWrite);
    
    123 122
             create(leftRootNode, leftAddNode, leftUpdateNode, leftDiff);
    
    124 123
     
    
    125 124
             CreateAddNode rightAddNode = new CreateAddNode(leftCanWrite, rightCanWrite);
    
    126
    -        CreateUpdateNode rightUpdateNode = new CreateUpdateNode(leftCanWrite, rightCanWrite, showProperties);
    
    125
    +        CreateUpdateNode rightUpdateNode = new CreateUpdateNode(leftCanWrite, rightCanWrite);
    
    127 126
             create(rightRootNode, rightAddNode, rightUpdateNode, rightDiff);
    
    128 127
     
    
    129 128
             ReferentialSynchronizeTreeModel leftTreeModel = new ReferentialSynchronizeTreeModel(leftRootNode, leftAddNode.getIds());
    
    ... ... @@ -171,17 +170,15 @@ public class ReferentialSynchronizeTreeModelsBuilder {
    171 170
     
    
    172 171
             private final boolean canCopy;
    
    173 172
             private final boolean canRevert;
    
    174
    -        private final boolean showProperties;
    
    175 173
     
    
    176
    -        protected CreateUpdateNode(boolean canCopy, boolean canRevert, boolean showProperties) {
    
    174
    +        protected CreateUpdateNode(boolean canCopy, boolean canRevert) {
    
    177 175
                 this.canCopy = canCopy;
    
    178 176
                 this.canRevert = canRevert;
    
    179
    -            this.showProperties = showProperties;
    
    180 177
             }
    
    181 178
     
    
    182 179
             public void createNode(ReferentialTypeSynchroNode typeNode, Differential diffState) {
    
    183 180
     
    
    184
    -            DifferentialPropertyList modifiedProperties;
    
    181
    +            DifferentialPropertyList modifiedProperties = null;
    
    185 182
                 if (canCopy || canRevert) {
    
    186 183
     
    
    187 184
                     modifiedProperties = diffState.getPropertiesModification();
    
    ... ... @@ -191,8 +188,6 @@ public class ReferentialSynchronizeTreeModelsBuilder {
    191 188
                         return;
    
    192 189
                     }
    
    193 190
                     log.debug(String.format("Modified properties: %s on %s", modifiedProperties, diffState.getId()));
    
    194
    -            } else {
    
    195
    -                modifiedProperties = null;
    
    196 191
                 }
    
    197 192
                 ReferentialSynchroNodeSupport node = new ReferentialUpdatedSynchroNode(diffState, canCopy, canRevert);
    
    198 193
                 typeNode.add(node);
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/actions/DataSourceInformation.java
    ... ... @@ -40,7 +40,7 @@ import static io.ultreia.java4all.i18n.I18n.t;
    40 40
     public class DataSourceInformation extends ReferentialSelectionTreePaneActionSupport {
    
    41 41
     
    
    42 42
         public DataSourceInformation() {
    
    43
    -        super("", t("observe.action.info.storage.tip"), "information", ObserveKeyStrokesSupport.KEY_STROKE_DATA_SOURCE_INFORMATION);
    
    43
    +        super("", t("observe.action.info.storage.tip"), "information", ObserveKeyStrokesSupport.KEY_STROKE_CONFIGURE_LOCAL_SOURCE);
    
    44 44
         }
    
    45 45
     
    
    46 46
         @Override
    
    ... ... @@ -55,4 +55,12 @@ public class DataSourceInformation extends ReferentialSelectionTreePaneActionSup
    55 55
                     JOptionPane.INFORMATION_MESSAGE);
    
    56 56
     
    
    57 57
         }
    
    58
    +
    
    59
    +    @Override
    
    60
    +    public void init() {
    
    61
    +        if (ui.isRight()) {
    
    62
    +            setKeyStroke(ObserveKeyStrokesSupport.KEY_STROKE_CONFIGURE_REMOTE_SOURCE);
    
    63
    +        }
    
    64
    +        defaultInit(getInputMap(ui, getInputMapCondition()), getActionMap(ui));
    
    65
    +    }
    
    58 66
     }

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/actions/RegisterTaskActionSupport.java
    ... ... @@ -247,7 +247,7 @@ public abstract class RegisterTaskActionSupport extends ReferentialSelectionTree
    247 247
             DifferentialPropertyList includedProperties = null;
    
    248 248
             Set<ReferentialPropertyUpdatedNode> toRemove = new LinkedHashSet<>();
    
    249 249
             Differential userObject = node.getUserObject();
    
    250
    -        boolean toOtherSide = taskType.toOtherSide();
    
    250
    +        boolean toOtherSide = taskType != null && taskType.toOtherSide();
    
    251 251
             if (!node.isLeaf() && node instanceof ReferentialUpdatedSynchroNode) {
    
    252 252
                 ReferentialUpdatedSynchroNode node1 = (ReferentialUpdatedSynchroNode) node;
    
    253 253
                 includedPropertyNames = node1.getPropertyNamesSelected().orElse(null);
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/actions/SelectAll.java
    ... ... @@ -27,8 +27,8 @@ import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.
    27 27
     import fr.ird.observe.client.util.ObserveKeyStrokesSupport;
    
    28 28
     
    
    29 29
     import javax.swing.SwingUtilities;
    
    30
    -import javax.swing.tree.TreePath;
    
    31 30
     import java.awt.event.ActionEvent;
    
    31
    +import java.util.Collections;
    
    32 32
     
    
    33 33
     import static io.ultreia.java4all.i18n.I18n.t;
    
    34 34
     
    
    ... ... @@ -44,17 +44,8 @@ public class SelectAll extends ReferentialSelectionTreePaneActionSupport {
    44 44
     
    
    45 45
         @Override
    
    46 46
         protected void doActionPerformed(ActionEvent e, ReferentialSelectionTreePane ui) {
    
    47
    -
    
    48 47
             ReferentialSelectionTree tree = ui.getTree();
    
    49
    -        SwingUtilities.invokeLater(() -> {
    
    50
    -            int l = tree.getRowCount();
    
    51
    -            for (int i = 0; i < l; i++) {
    
    52
    -                TreePath path = tree.getPathForRow(i);
    
    53
    -                tree.addSelectionPath(path);
    
    54
    -            }
    
    55
    -            SelectUnselect.select(tree);
    
    56
    -        });
    
    57
    -
    
    48
    +        SelectUnselect.selectUnSelect(tree, Collections.singleton(tree.getTreeModel().getRoot()), n -> true);
    
    58 49
             SwingUtilities.invokeLater(tree::repaint);
    
    59 50
         }
    
    60 51
     }

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/actions/SelectUnselect.java
    ... ... @@ -24,9 +24,11 @@ package fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree
    24 24
     
    
    25 25
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.ReferentialSelectionTree;
    
    26 26
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.ReferentialSelectionTreePane;
    
    27
    +import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.ReferentialSynchronizeTreeModel;
    
    27 28
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.ReferentialPropertyUpdatedNode;
    
    28 29
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.ReferentialSynchroNodeSupport;
    
    29 30
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.ReferentialTypeSynchroNode;
    
    31
    +import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.RootSynchroNode;
    
    30 32
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.SynchroNodeSupport;
    
    31 33
     import fr.ird.observe.client.util.ObserveKeyStrokesSupport;
    
    32 34
     import org.apache.logging.log4j.LogManager;
    
    ... ... @@ -34,12 +36,20 @@ import org.apache.logging.log4j.Logger;
    34 36
     
    
    35 37
     import javax.swing.ActionMap;
    
    36 38
     import javax.swing.InputMap;
    
    39
    +import javax.swing.JComponent;
    
    40
    +import javax.swing.SwingUtilities;
    
    41
    +import javax.swing.tree.TreeNode;
    
    37 42
     import javax.swing.tree.TreePath;
    
    38 43
     import java.awt.event.ActionEvent;
    
    39 44
     import java.awt.event.MouseAdapter;
    
    40 45
     import java.awt.event.MouseEvent;
    
    46
    +import java.util.Collections;
    
    47
    +import java.util.Enumeration;
    
    41 48
     import java.util.LinkedHashSet;
    
    49
    +import java.util.LinkedList;
    
    50
    +import java.util.List;
    
    42 51
     import java.util.Set;
    
    52
    +import java.util.function.Function;
    
    43 53
     
    
    44 54
     /**
    
    45 55
      * @author Tony Chemit - dev@tchemit.fr
    
    ... ... @@ -49,11 +59,16 @@ public class SelectUnselect extends ReferentialSelectionTreePaneActionSupport {
    49 59
     
    
    50 60
         private static final Logger log = LogManager.getLogger(SelectUnselect.class);
    
    51 61
     
    
    52
    -    private final ReferentialSelectionTreePane opposite;
    
    62
    +//    private final ReferentialSelectionTreePane opposite;
    
    53 63
     
    
    54 64
         public SelectUnselect(ReferentialSelectionTreePane opposite) {
    
    55 65
             super(null, null, null, ObserveKeyStrokesSupport.KEY_STROKE_SPACE);
    
    56
    -        this.opposite = opposite;
    
    66
    +//        this.opposite = opposite;
    
    67
    +    }
    
    68
    +
    
    69
    +    @Override
    
    70
    +    protected int getInputMapCondition() {
    
    71
    +        return JComponent.WHEN_FOCUSED;
    
    57 72
         }
    
    58 73
     
    
    59 74
         @Override
    
    ... ... @@ -79,7 +94,7 @@ public class SelectUnselect extends ReferentialSelectionTreePaneActionSupport {
    79 94
         @Override
    
    80 95
         public void init() {
    
    81 96
             defaultInit(ui);
    
    82
    -        defaultInit(opposite);
    
    97
    +//        defaultInit(opposite);
    
    83 98
         }
    
    84 99
     
    
    85 100
         @Override
    
    ... ... @@ -90,7 +105,14 @@ public class SelectUnselect extends ReferentialSelectionTreePaneActionSupport {
    90 105
                 @Override
    
    91 106
                 public void mouseClicked(MouseEvent e) {
    
    92 107
                     if (e.getClickCount() == 2) {
    
    93
    -                    actionPerformed(new ActionEvent(getUi().getTree(), 0, "yo"));
    
    108
    +                    ReferentialSelectionTree tree = ui.getTree();
    
    109
    +                    TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
    
    110
    +                    Object lastPathComponent = path.getLastPathComponent();
    
    111
    +                    if (lastPathComponent instanceof SynchroNodeSupport) {
    
    112
    +                        SynchroNodeSupport node = (SynchroNodeSupport) lastPathComponent;
    
    113
    +                        selectUnSelect(tree, Collections.singleton(node), n -> !n.isSelected());
    
    114
    +//                    actionPerformed(new ActionEvent(getUi().getTree(), 0, "Coming from mouse click"));
    
    115
    +                    }
    
    94 116
                     }
    
    95 117
                 }
    
    96 118
             });
    
    ... ... @@ -110,56 +132,81 @@ public class SelectUnselect extends ReferentialSelectionTreePaneActionSupport {
    110 132
         @Override
    
    111 133
         protected void doActionPerformed(ActionEvent e, ReferentialSelectionTreePane ui) {
    
    112 134
             ReferentialSelectionTree tree = ui.getTree();
    
    113
    -        if (tree.isFocusOwner()) {
    
    114
    -            selectUnSelect(tree);
    
    115
    -        } else {
    
    116
    -            selectUnSelect(opposite.getTree());
    
    117
    -        }
    
    135
    +        selectUnSelect(tree, tree.getSelectedNodes(), n -> !n.isSelected());
    
    136
    +//        if (tree.isFocusOwner()) {
    
    137
    +//            selectUnSelect(tree);
    
    138
    +//        } else {
    
    139
    +//            selectUnSelect(opposite.getTree());
    
    140
    +//        }
    
    118 141
         }
    
    119 142
     
    
    120
    -    protected static void selectUnSelect(ReferentialSelectionTree tree) {
    
    121
    -        TreePath[] selectedRow = tree.getSelectionPaths();
    
    122
    -        if (selectedRow == null || selectedRow.length == 0) {
    
    143
    +    protected static void selectUnSelect(ReferentialSelectionTree tree, Set<SynchroNodeSupport> selectedNodes, Function<SynchroNodeSupport, Boolean> function) {
    
    144
    +        if (selectedNodes.isEmpty()) {
    
    123 145
                 return;
    
    124 146
             }
    
    125
    -        Set<SynchroNodeSupport> nodes = new LinkedHashSet<>();
    
    126
    -        for (TreePath treePath : selectedRow) {
    
    127
    -            SynchroNodeSupport node = (SynchroNodeSupport) treePath.getLastPathComponent();
    
    128
    -            if (node instanceof ReferentialPropertyUpdatedNode && !node.getRoot().isShowProperties()) {
    
    129
    -                // we can not modify property to update or revert in such mode
    
    147
    +        boolean showProperties = tree.getTreeModel().getRoot().isShowProperties();
    
    148
    +
    
    149
    +        // Get all typed nodes in selection
    
    150
    +        Set<SynchroNodeSupport> typeNodes = new LinkedHashSet<>();
    
    151
    +        // Get all referential nodes in selection
    
    152
    +        Set<SynchroNodeSupport> referentialNodes = new LinkedHashSet<>();
    
    153
    +        // Get all property nodes in selection
    
    154
    +        Set<SynchroNodeSupport> propertyNodes = new LinkedHashSet<>();
    
    155
    +        for (SynchroNodeSupport node : selectedNodes) {
    
    156
    +            if (node instanceof ReferentialPropertyUpdatedNode) {
    
    157
    +                if (!showProperties) {
    
    158
    +                    // we can not modify selected property in such mode
    
    159
    +                    continue;
    
    160
    +                }
    
    161
    +                propertyNodes.add(node);
    
    162
    +                continue;
    
    163
    +            }
    
    164
    +            if (node instanceof ReferentialTypeSynchroNode) {
    
    165
    +                typeNodes.add(node);
    
    130 166
                     continue;
    
    131 167
                 }
    
    132 168
                 if (node instanceof ReferentialSynchroNodeSupport) {
    
    133
    -                if (nodes.contains(node.getParent())) {
    
    134
    -                    continue;
    
    169
    +                referentialNodes.add(node);
    
    170
    +            }
    
    171
    +            if (node instanceof RootSynchroNode) {
    
    172
    +                RootSynchroNode node1 = (RootSynchroNode) node;
    
    173
    +                Enumeration<TreeNode> children = node1.children();
    
    174
    +                while (children.hasMoreElements()) {
    
    175
    +                    ReferentialTypeSynchroNode childNode = (ReferentialTypeSynchroNode) children.nextElement();
    
    176
    +                    referentialNodes.add(childNode);
    
    135 177
                     }
    
    136
    -            } else if (node instanceof ReferentialTypeSynchroNode) {
    
    137
    -                nodes.add(node);
    
    138 178
                 }
    
    139
    -            tree.getTreeModel().setValueAt(node, !node.isSelected());
    
    140 179
             }
    
    141
    -    }
    
    142 180
     
    
    143
    -    protected static void select(ReferentialSelectionTree tree) {
    
    144
    -        TreePath[] selectedRow = tree.getSelectionPaths();
    
    145
    -        if (selectedRow == null || selectedRow.length == 0) {
    
    146
    -            return;
    
    147
    -        }
    
    148
    -        Set<SynchroNodeSupport> nodes = new LinkedHashSet<>();
    
    149
    -        for (TreePath treePath : selectedRow) {
    
    150
    -            SynchroNodeSupport node = (SynchroNodeSupport) treePath.getLastPathComponent();
    
    151
    -            if (node instanceof ReferentialPropertyUpdatedNode && !node.getRoot().isShowProperties()) {
    
    152
    -                // we can not modify property to update or revert in such mode
    
    153
    -                continue;
    
    154
    -            }
    
    155
    -            if (node instanceof ReferentialSynchroNodeSupport) {
    
    156
    -                if (nodes.contains(node.getParent())) {
    
    157
    -                    continue;
    
    181
    +        // To collect all nodes to modify (type nodes are always modified)
    
    182
    +        List<SynchroNodeSupport> nodesToModify = new LinkedList<>(typeNodes);
    
    183
    +
    
    184
    +        // Removes referential node if his type node is also selected
    
    185
    +        referentialNodes.removeIf(node -> typeNodes.contains(node.getParent()));
    
    186
    +        // Retained referential nodes need to be modified
    
    187
    +        nodesToModify.addAll(referentialNodes);
    
    188
    +
    
    189
    +        // Remove property node if one of his ancestor is also selected
    
    190
    +        propertyNodes.removeIf(node -> referentialNodes.contains(node.getParent()) || typeNodes.contains(node.getParent().getParent()));
    
    191
    +        // Retained property nodes need to be modified
    
    192
    +        nodesToModify.addAll(propertyNodes);
    
    193
    +
    
    194
    +        if (!nodesToModify.isEmpty()) {
    
    195
    +            ReferentialSynchronizeTreeModel treeModel = tree.getTreeModel();
    
    196
    +            treeModel.setAdjusting(true);
    
    197
    +
    
    198
    +            try {
    
    199
    +                for (SynchroNodeSupport node : nodesToModify) {
    
    200
    +                    boolean newSelectedValue = function.apply(node);
    
    201
    +                    log.info(String.format("Change selection of node: %s to value? %b", node, newSelectedValue));
    
    202
    +                    treeModel.setValueAt(node, newSelectedValue);
    
    158 203
                     }
    
    159
    -            } else if (node instanceof ReferentialTypeSynchroNode) {
    
    160
    -                nodes.add(node);
    
    204
    +            } finally {
    
    205
    +                treeModel.setAdjusting(false);
    
    161 206
                 }
    
    162
    -            tree.getTreeModel().setValueAt(node, true);
    
    207
    +
    
    208
    +            log.info("Some modification in tree need a repaint");
    
    209
    +            SwingUtilities.invokeLater(tree::repaint);
    
    163 210
             }
    
    164 211
         }
    
    165 212
     
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/actions/UnselectAll.java
    ... ... @@ -24,10 +24,12 @@ package fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree
    24 24
     
    
    25 25
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.ReferentialSelectionTree;
    
    26 26
     import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.ReferentialSelectionTreePane;
    
    27
    +import fr.ird.observe.client.datasource.actions.synchronize.referential.ng.tree.node.RootSynchroNode;
    
    27 28
     import fr.ird.observe.client.util.ObserveKeyStrokesSupport;
    
    28 29
     
    
    29 30
     import javax.swing.SwingUtilities;
    
    30 31
     import java.awt.event.ActionEvent;
    
    32
    +import java.util.Collections;
    
    31 33
     
    
    32 34
     import static io.ultreia.java4all.i18n.I18n.t;
    
    33 35
     
    
    ... ... @@ -44,17 +46,8 @@ public class UnselectAll extends ReferentialSelectionTreePaneActionSupport {
    44 46
         @Override
    
    45 47
         protected void doActionPerformed(ActionEvent e, ReferentialSelectionTreePane ui) {
    
    46 48
             ReferentialSelectionTree tree = ui.getTree();
    
    47
    -
    
    48
    -        SwingUtilities.invokeLater(() -> {
    
    49
    -
    
    50
    -            tree.getTreeModel().clearSelection();
    
    51
    -            tree.clearSelection();
    
    52
    -
    
    53
    -            if (!tree.getTreeModel().getRoot().isLeaf()) {
    
    54
    -                tree.addSelectionRow(0);
    
    55
    -            }
    
    56
    -        });
    
    57
    -
    
    49
    +        RootSynchroNode root = tree.getTreeModel().getRoot();
    
    50
    +        SelectUnselect.selectUnSelect(tree, Collections.singleton(root), n -> false);
    
    58 51
             SwingUtilities.invokeLater(tree::repaint);
    
    59 52
         }
    
    60 53
     }

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/node/ReferentialPropertyUpdatedNode.java
    ... ... @@ -48,8 +48,6 @@ public class ReferentialPropertyUpdatedNode extends SynchroNodeSupport {
    48 48
             String rightValue = left ? property.getNewValueLabel(decoratorService) : property.getOldValueLabel(decoratorService);
    
    49 49
             this.label = property.getPropertyNameLabel(dtoType, decoratorService);
    
    50 50
             this.modificationLabel = String.format("<i>( %s )</i>", t("observe.actions.synchro.referential.property.modified", leftValue, rightValue));
    
    51
    -        // by default all properties are selected
    
    52
    -        setSelected(true);
    
    53 51
         }
    
    54 52
     
    
    55 53
         public DifferentialProperty getModifiedProperty() {
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/node/ReferentialTypeSynchroNode.java
    ... ... @@ -27,7 +27,6 @@ import fr.ird.observe.dto.referential.ReferentialDto;
    27 27
     import fr.ird.observe.dto.tree.I18nTreeHelper;
    
    28 28
     
    
    29 29
     import javax.swing.UIManager;
    
    30
    -import java.util.Enumeration;
    
    31 30
     
    
    32 31
     /**
    
    33 32
      * Created on 09/08/16.
    
    ... ... @@ -47,37 +46,26 @@ public class ReferentialTypeSynchroNode extends SynchroNodeSupport {
    47 46
             return (RootSynchroNode) super.getParent();
    
    48 47
         }
    
    49 48
     
    
    50
    -    @Override
    
    51
    -    public boolean isSelected() {
    
    52
    -        Enumeration<?> children = children();
    
    53
    -        while (children.hasMoreElements()) {
    
    54
    -            SynchroNodeSupport node = (SynchroNodeSupport) children.nextElement();
    
    55
    -            if (!node.isSelected()) {
    
    56
    -                return false;
    
    57
    -            }
    
    58
    -        }
    
    59
    -        return !isLeaf();
    
    60
    -    }
    
    61
    -
    
    62
    -    @Override
    
    63
    -    public void setSelected(boolean selected) {
    
    64
    -        Enumeration<?> children = children();
    
    65
    -        while (children.hasMoreElements()) {
    
    66
    -            SynchroNodeSupport node = (SynchroNodeSupport) children.nextElement();
    
    67
    -            node.setSelected(selected);
    
    68
    -        }
    
    69
    -    }
    
    70
    -
    
    71
    -    public ReferentialSynchroNodeSupport getChild(String id) {
    
    72
    -        Enumeration<?> children = children();
    
    73
    -        while (children.hasMoreElements()) {
    
    74
    -            ReferentialSynchroNodeSupport o = (ReferentialSynchroNodeSupport) children.nextElement();
    
    75
    -            if (id.equals(o.getUserObject().getId())) {
    
    76
    -                return o;
    
    77
    -            }
    
    78
    -        }
    
    79
    -        return null;
    
    80
    -    }
    
    49
    +//    @Override
    
    50
    +//    public boolean isSelected() {
    
    51
    +//        Enumeration<?> children = children();
    
    52
    +//        while (children.hasMoreElements()) {
    
    53
    +//            SynchroNodeSupport node = (SynchroNodeSupport) children.nextElement();
    
    54
    +//            if (!node.isSelected()) {
    
    55
    +//                return false;
    
    56
    +//            }
    
    57
    +//        }
    
    58
    +//        return !isLeaf();
    
    59
    +//    }
    
    60
    +//
    
    61
    +//    @Override
    
    62
    +//    public void setSelected(boolean selected) {
    
    63
    +//        Enumeration<?> children = children();
    
    64
    +//        while (children.hasMoreElements()) {
    
    65
    +//            SynchroNodeSupport node = (SynchroNodeSupport) children.nextElement();
    
    66
    +//            node.setSelected(selected);
    
    67
    +//        }
    
    68
    +//    }
    
    81 69
     
    
    82 70
         @SuppressWarnings("unchecked")
    
    83 71
         @Override
    

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/node/ReferentialUpdatedSynchroNode.java
    ... ... @@ -57,8 +57,4 @@ public class ReferentialUpdatedSynchroNode extends ReferentialSynchroNodeSupport
    57 57
             return Optional.ofNullable(oneSelected ? includedPropertyNamesBuilder.build() : null);
    
    58 58
         }
    
    59 59
     
    
    60
    -    @Override
    
    61
    -    public boolean isPartialSelected() {
    
    62
    -        return false;
    
    63
    -    }
    
    64 60
     }

  • client-datasource-actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/referential/ng/tree/node/SynchroNodeSupport.java
    ... ... @@ -38,7 +38,7 @@ public abstract class SynchroNodeSupport extends DefaultMutableTreeNode implemen
    38 38
     
    
    39 39
         private static final long serialVersionUID = 1L;
    
    40 40
     
    
    41
    -    private transient Icon icon;
    
    41
    +    private final transient Icon icon;
    
    42 42
         private transient boolean selected;
    
    43 43
     
    
    44 44
         protected SynchroNodeSupport(Icon icon, Object userObject) {
    
    ... ... @@ -46,7 +46,6 @@ public abstract class SynchroNodeSupport extends DefaultMutableTreeNode implemen
    46 46
             this.icon = icon;
    
    47 47
         }
    
    48 48
     
    
    49
    -
    
    50 49
         public abstract String toString(DecoratorService decoratorService);
    
    51 50
     
    
    52 51
         public Icon getIcon() {
    
    ... ... @@ -65,25 +64,50 @@ public abstract class SynchroNodeSupport extends DefaultMutableTreeNode implemen
    65 64
             return selected;
    
    66 65
         }
    
    67 66
     
    
    68
    -    public void setSelected(boolean selected) {
    
    69
    -        this.selected = selected;
    
    67
    +    public boolean isPartialSelected() {
    
    68
    +        if (isLeaf()) {
    
    69
    +            return false;
    
    70
    +        }
    
    71
    +        int selectedCount = getSelectedCount();
    
    72
    +        int childCount = getChildCount();
    
    73
    +        return selectedCount > 0 && selectedCount < childCount;
    
    70 74
         }
    
    71 75
     
    
    72
    -    public boolean isPartialSelected() {
    
    73
    -        if (isSelected()) {
    
    76
    +    public boolean isFullySelected() {
    
    77
    +        if (isLeaf()) {
    
    74 78
                 return false;
    
    75 79
             }
    
    80
    +        int selectedCount = getSelectedCount();
    
    81
    +        int childCount = getChildCount();
    
    82
    +        return selectedCount == childCount;
    
    83
    +    }
    
    84
    +
    
    85
    +    public boolean isNotSelected() {
    
    76 86
             if (isLeaf()) {
    
    77 87
                 return false;
    
    78 88
             }
    
    89
    +        int selectedCount = getSelectedCount();
    
    90
    +        return selectedCount == 0;
    
    91
    +    }
    
    92
    +
    
    93
    +    public int getSelectedCount() {
    
    94
    +        int result = 0;
    
    79 95
             Enumeration<?> children = children();
    
    80 96
             while (children.hasMoreElements()) {
    
    81
    -            SynchroNodeSupport nodeSupport = (SynchroNodeSupport) children.nextElement();
    
    82
    -            if (nodeSupport.isSelected()) {
    
    83
    -                return true;
    
    97
    +            SynchroNodeSupport childNode = (SynchroNodeSupport) children.nextElement();
    
    98
    +            if (childNode.isSelected()) {
    
    99
    +                result++;
    
    84 100
                 }
    
    85 101
             }
    
    86
    -        return false;
    
    102
    +        return result;
    
    103
    +    }
    
    104
    +
    
    105
    +    public void updateSelect(boolean selected) {
    
    106
    +        if (selected) {
    
    107
    +            select(true);
    
    108
    +        } else {
    
    109
    +            unselect(true);
    
    110
    +        }
    
    87 111
         }
    
    88 112
     
    
    89 113
         @Override
    
    ... ... @@ -95,4 +119,49 @@ public abstract class SynchroNodeSupport extends DefaultMutableTreeNode implemen
    95 119
         public SynchroNodeSupport getParent() {
    
    96 120
             return (SynchroNodeSupport) super.getParent();
    
    97 121
         }
    
    122
    +
    
    123
    +    protected void select(boolean first) {
    
    124
    +        if (first) {
    
    125
    +            setSelectedDeeply(true);
    
    126
    +        } else {
    
    127
    +            setSelected(true);
    
    128
    +        }
    
    129
    +        SynchroNodeSupport parent = getParent();
    
    130
    +        if (parent.isRoot()) {
    
    131
    +            return;
    
    132
    +        }
    
    133
    +        if (!parent.isNotSelected()) {
    
    134
    +            parent.select(false);
    
    135
    +        }
    
    136
    +    }
    
    137
    +
    
    138
    +    protected void unselect(boolean first) {
    
    139
    +        if (first) {
    
    140
    +            setSelectedDeeply(false);
    
    141
    +        } else {
    
    142
    +            setSelected(false);
    
    143
    +        }
    
    144
    +        SynchroNodeSupport parent = getParent();
    
    145
    +        if (parent.isRoot()) {
    
    146
    +            return;
    
    147
    +        }
    
    148
    +        if (parent.isNotSelected()) {
    
    149
    +            // no more selection on parent
    
    150
    +            parent.unselect(false);
    
    151
    +        }
    
    152
    +    }
    
    153
    +
    
    154
    +    protected void setSelected(boolean selected) {
    
    155
    +        this.selected = selected;
    
    156
    +    }
    
    157
    +
    
    158
    +    private void setSelectedDeeply(boolean selected) {
    
    159
    +        setSelected(selected);
    
    160
    +        // Reset all all children
    
    161
    +        Enumeration<?> children = children();
    
    162
    +        while (children.hasMoreElements()) {
    
    163
    +            SynchroNodeSupport node = (SynchroNodeSupport) children.nextElement();
    
    164
    +            node.setSelectedDeeply(selected);
    
    165
    +        }
    
    166
    +    }
    
    98 167
     }