@Override
    public void valueChanged(TreeSelectionEvent e) {
      TreePath[] paths = e.getPaths();
      if (paths == null) return;

      boolean reversed = false;
      if (paths.length > 1 &&
          myTree.getRowForPath(paths[0]) < myTree.getRowForPath(e.getOldLeadSelectionPath()) &&
          myTree.getRowForPath(paths[paths.length - 1]) < myTree.getRowForPath(e.getOldLeadSelectionPath())) {
        // `paths` is always sorted from top to bottom (as shown on screen), even when selected in a different order.
        // When the user selects from the bottom to the top, we want to have the paths in that order too.
        // For example members a, b and c.
        // Case 1: c is selected. The user shift-clicks a. Event contains a and b, in that order. We want to reverse,
        // so the order of selection will be c, b, a (not c, a, b).
        // Case 2: b is selected. The user presses cmd/ctrl+a (select all). Event contains root, a, c. No need to
        // reverse. The order of selection will be a, b, c.
        // Case 3: a is selected. The user shift-clicks c. Event contains b and c, in that order. No need to
        // reverse. The order of selection will be a, b, c.
        paths = ArrayUtil.reverseArray(paths);
        reversed = true;
      }
      for (int i = 0; i < paths.length; i++) {
        if (paths[i].getLastPathComponent() instanceof MemberNode memberNode) {
          if (e.isAddedPath(reversed ? paths.length - (i + 1) : i)) {
            if (!mySelectedNodes.contains(memberNode)) {
              mySelectedNodes.add(memberNode);
            }
          }
          else {
            mySelectedNodes.remove(memberNode);
          }
        }
      }
      mySelectedElements = new LinkedHashSet<>();
      for (MemberNode selectedNode : mySelectedNodes) {
        mySelectedElements.add((T)selectedNode.getDelegate());
      }
      if (!myAllowEmptySelection) {
        setOKActionEnabled(!mySelectedElements.isEmpty());
      }
    }
@Override
    public void valueChanged(TreeSelectionEvent e)