private void processModelEvent(TreeModelEvent event, TreeModelAdapter.EventType type) {
    var path = event.getTreePath();
    if (path == null) {
      // Shouldn't normally happen for regular events, may be a global change (the entire model is cleared).
      detach();
      return;
    }
    switch (type) {
      case StructureChanged -> {
        if (path.equals(this.path)) {
          checkExpanded();
        }
        else if (path.isDescendant(this.path)) {
          detach(); // One of the parent dirs was rebuilt completely.
        }
      }
      case NodesChanged, NodesInserted -> {
        checkExpanded(path);
      }
      case NodesRemoved -> {
        if (path.isDescendant(this.path.getParentPath())) {
          detach(); // Our directory was removed.
        }
        else {
          checkExpanded(path); // Could be a result of an empty dir expansion! ('loading...' removed)
        }
      }
    }
  }
private void processModelEvent(TreeModelEvent event, TreeModelAdapter.EventType type)