code: protected static CmsTreeItem getLastOpenedItem(CmsTreeItem item, int stopLevel, boolean requiresDropEnabled) {
  
          if (stopLevel != -1) {
              // stop level is set
              int currentLevel = getPathLevel(item.getPath());
              if (currentLevel > stopLevel) {
                  // we are past the stop level, prevent further checks
                  stopLevel = -1;
              } else if (currentLevel == stopLevel) {
                  // matches stop level
                  return item;
              }
          }
          if (item.getChildCount() > 0) {
              int childIndex = item.getChildCount() - 1;
              CmsTreeItem child = item.getChild(childIndex);
              if (requiresDropEnabled) {
                  while (!child.isDropEnabled()) {
                      childIndex--;
                      if (childIndex < 0) {
                          return item;
                      }
                      child = item.getChild(childIndex);
                  }
              }
  
              if (child.isOpen()) {
                  return CmsTreeItem.getLastOpenedItem(child, stopLevel, requiresDropEnabled);
              }
          }
          return item;
      }
docs: Returns the last opened item of a tree fragment.<p>
  
  @param item the tree item
  @param stopLevel the level to stop at, set -1 to go to the very last opened item
  @param requiresDropEnabled <code>true</code> if it is required the returned element to be drop enabled
  
  @return the last visible item of a tree fragment