/**
   * @param node
   * @return
   */
  @Pure
  @Nonnull
  @CheckReturnValue
  public static DefaultMutableTreeNode deepCloneNode(
      final DefaultMutableTreeNode node, final Function<Object, ?> cloneFunc) {
    Preconditions.checkNotNull(node);
    Preconditions.checkNotNull(cloneFunc);

    // shadow clone node
    final DefaultMutableTreeNode cloneNode = (DefaultMutableTreeNode) node.clone();

    // deep clone the user object
    final Object cloneObject = cloneFunc.apply(node.getUserObject());
    cloneNode.setUserObject(cloneObject);

    return cloneNode;

    //        //@throws IllegalArgumentException
    //        //   If the node's user object is not cloneable.
    //
    //        final Cloneable userObjectAsCloneable = CommonOP.As(node.getUserObject(),
    // Cloneable.class);
    //        if (userObjectAsCloneable != null) {
    //            // shadow clone node
    //            final DefaultMutableTreeNode cloneNode = (DefaultMutableTreeNode) node.clone();
    //
    //            //deep clone the user object
    //            final Object cloneObject = userObjectAsCloneable.clone();
    //            cloneNode.setUserObject(cloneObject);
    //
    //            return cloneNode;
    //        } else {
    //            throw new IllegalArgumentException("The node's user object is not cloneable.");
    //        }
  }
  public static DefaultMutableTreeNode getSelectedTree(List<DefaultMutableTreeNode> selectedNodes) {
    DefaultMutableTreeNode basicRoot =
        (DefaultMutableTreeNode)
            PanelsController.contradictionsPanel.getTree().getModel().getRoot();
    if (selectedNodes.contains(basicRoot)) {
      return basicRoot;
    }

    DefaultMutableTreeNode newRoot = (DefaultMutableTreeNode) basicRoot.clone();
    for (int i = 0; i < basicRoot.getChildCount(); i++) {
      DefaultMutableTreeNode type = (DefaultMutableTreeNode) basicRoot.getChildAt(i);

      if (selectedNodes.contains(type)) {
        DefaultMutableTreeNode newType = (DefaultMutableTreeNode) type.clone();
        newRoot.add(newType);
        for (int j = 0; j < type.getChildCount(); j++) {
          DefaultMutableTreeNode creterion = (DefaultMutableTreeNode) type.getChildAt(j);
          newType.add((DefaultMutableTreeNode) creterion.clone());
        }
      } else {
        DefaultMutableTreeNode newType = (DefaultMutableTreeNode) type.clone();

        boolean isTypeAdded = false;
        for (int j = 0; j < type.getChildCount(); j++) {
          DefaultMutableTreeNode creterion = (DefaultMutableTreeNode) type.getChildAt(j);

          if (selectedNodes.contains(creterion)) {
            if (!isTypeAdded) {
              newRoot.add(newType);
              isTypeAdded = true;
            }
            newType.add((MutableTreeNode) creterion.clone());
          }
        }
      }
    }

    return newRoot;
  }