Class LazyTree


  • public class LazyTree
    extends java.lang.Object
    Represents the front-end for browsing arbitrary large tree.

    The lazy tree can be used in a special dedicated controller, or plugged into a page controller. In either case you should bind the tree to the HTTP session and handle tree-related requests with it. Example controller:

       protected ModelAndView doHandle(HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
         HttpSession session = request.getSession();
         LazyTree tree = (LazyTree) session.getAttribute(TREE_NAME);
         if (tree == null) {
           tree = new LazyTree(new FileSystemBrowser("/"));
           session.setAttribute(TREE_NAME, tree);
         }
         if (tree.isUpdateTreeRequest(request)) {
           return tree.handleUpdateTreeRequest(request, response);
         }
         ...
       }
     
    Also consider storing the tree on a soft reference to avoid memory leaks.

    There could be not more than one tree per controller. If you wish to show several lazy trees on a page, use a separate controller for each of them.

    In a HTML or JSP page you have to:

    • link "/js/bs/tree.js" script to the page;
    • put an empty element for storing the tree with unique id;
    • call the javascript tree loader: BS.LazyTree.loadTree("id");
    If the tree requires a separate controller, specify its url before loading, e.g. BS.LazyTree.treeUrl = window['base_uri'] + "/myController.html";
    Since:
    6.0
    Author:
    Maxim Podkolzine (maxim.podkolzine@jetbrains.com)
    See Also:
    Browser
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Browser getBrowser()
      Returns the reference to the tree browser.
      org.springframework.web.servlet.ModelAndView handleUpdateTreeRequest​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Processes the tree-related request, prints the required dynamic data to the response and returns null.
      boolean isUpdateTreeRequest​(javax.servlet.http.HttpServletRequest request)
      Returns true if the request is a special AJAX request and should be processed using handleUpdateTreeRequest method.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LazyTree

        public LazyTree​(@NotNull
                        Browser browser,
                        @NotNull
                        LazyTreeElementRenderer renderer)
        Construct the lazy tree to show the info provided by browser. The elements are rendered using renderer.
        Parameters:
        browser - the browser
        renderer - the renderer
      • LazyTree

        public LazyTree​(@NotNull
                        Browser browser,
                        @NotNull
                        LazyTreeElementRenderer renderer,
                        @Nullable
                        java.lang.String id)
        Construct the lazy tree to show the info provided by browser. The elements are rendered using renderer.
        Parameters:
        browser - the browser
        renderer - the renderer
        id - id of the tree, specify it if page has more than one tree
      • LazyTree

        public LazyTree​(@NotNull
                        Browser browser)
        Construct the lazy tree to show the info provided by browser.
        Parameters:
        browser - the browser
    • Method Detail

      • isUpdateTreeRequest

        public boolean isUpdateTreeRequest​(@NotNull
                                           javax.servlet.http.HttpServletRequest request)
        Returns true if the request is a special AJAX request and should be processed using handleUpdateTreeRequest method.
        Parameters:
        request - http request
        Returns:
        true iff this a tree-related request
        See Also:
        handleUpdateTreeRequest(HttpServletRequest, HttpServletResponse)
      • handleUpdateTreeRequest

        @Nullable
        public org.springframework.web.servlet.ModelAndView handleUpdateTreeRequest​(@NotNull
                                                                                    javax.servlet.http.HttpServletRequest request,
                                                                                    @NotNull
                                                                                    javax.servlet.http.HttpServletResponse response)
                                                                             throws java.io.IOException
        Processes the tree-related request, prints the required dynamic data to the response and returns null. The response is closed in this method.
        Parameters:
        request - http request
        response - http response.
        Returns:
        null (for simplicity)
        Throws:
        java.io.IOException - if I/O error occurs
        See Also:
        isUpdateTreeRequest(HttpServletRequest)
      • getBrowser

        @NotNull
        public Browser getBrowser()
        Returns the reference to the tree browser.
        Returns:
        the reference to the tree browser
        Since:
        7.0, 6.5.2