Class TreeView

  • All Implemented Interfaces:
    java.io.Serializable

    public class TreeView
    extends java.lang.Object
    implements java.io.Serializable
    TreeView definition per user session
    See Also:
    Serialized Form
    • Constructor Detail

      • TreeView

        public TreeView​(Grant g,
                        java.lang.String id,
                        java.lang.String name,
                        int mode,
                        java.lang.String display)
        Constructor
        Parameters:
        g - User rights
        id - Treeview id
        name - Treeview name
        mode - Treeview mode
    • Method Detail

      • getObjects

        public java.util.List<java.lang.String> getObjects()
        Get objects in tree definition (to limit index search)
        Returns:
        Objects
      • getId

        public java.lang.String getId()
        Get the treeview ID
        Returns:
        Treeview ID
      • getName

        public java.lang.String getName()
        Get the treeview name
        Returns:
        treeview name
      • getDisplay

        public java.lang.String getDisplay()
        Get the treeview display label
        Returns:
        Treeview display label
      • setDisplay

        public void setDisplay​(java.lang.String label)
        Set treeview display label
        Parameters:
        label - Treeview display label
      • getRootObjectNames

        public java.util.List<java.lang.String> getRootObjectNames()
        Get objects on the tree root
        Returns:
        List of objects
      • addRootObject

        public void addRootObject​(java.lang.String obj)
        Add object to the tree root
        Parameters:
        obj - Object
      • setMode

        public void setMode​(int mode)
        Set mode
        Parameters:
        mode - Mode: one of TreeView.MODE_*
      • getMode

        public int getMode()
        Get mode
        Returns:
        one of TreeView.MODE_*
      • isDynamic

        public boolean isDynamic()
        Is dynamic: mode is not TreeView.MODE_MANUAL
        Returns:
        True if mod is dynamic
      • removeId

        public void removeId​(java.lang.String id)
        Remove ID
        Parameters:
        id - ID
      • searchLevel

        public TreeView.TreeViewNode searchLevel​(java.lang.String level)
        Search level
        Parameters:
        level - Level
        Returns:
        Node
      • getRootObject

        public TreeView.TreeViewNode getRootObject​(java.lang.String obj)
        Search object node in root only
        Parameters:
        obj - Optional object name
        Returns:
        Matching root or first root with object
      • getTreeObject

        public TreeView.TreeViewNode getTreeObject​(java.lang.String obj)
        Deep node search matching object
        Parameters:
        obj - Object
        Returns:
        Node
      • getUserMenu

        public static java.lang.String getUserMenu​(Grant g)
        Get user preference MENU_TREEVIEW = [{ treeview, object, rowid }]
        Parameters:
        g - Grant
      • addUserMenu

        public void addUserMenu​(java.lang.String object,
                                java.lang.String id)
        Store user preference MENU_TREEVIEW = [{ treeview, object, rowid }]
        Parameters:
        object - Object
        id - ID
      • delUserMenu

        public void delUserMenu​(java.lang.String object,
                                java.lang.String id)
        Remove menu preference MENU_TREEVIEW = [{ treeview, object, rowid }]
        Parameters:
        object - Object
        id - ID
      • toJSON

        public java.lang.String toJSON()
        Treeview definition { id, name, mode, label, root: { node }}
      • jsonPage

        public java.lang.String jsonPage​(java.lang.String parent,
                                         java.lang.String rowId,
                                         java.lang.String child,
                                         int page)
        Search a page for UI service (stateless)
        Parameters:
        parent - Parent
        rowId - Row ID
        child - Child
        page - Page
        Returns:
        JSON
      • toJSON

        public java.lang.String toJSON​(ObjectDB object,
                                       Parameters.InlineParam inlines,
                                       boolean metadata,
                                       TreeView.TreeViewNode node,
                                       int depth,
                                       boolean hist,
                                       java.lang.String path)
        Get the tree from a root node
        Parameters:
        object - selected object
        inlines - inline documents|thumbs|objects
        metadata - get metadata
        node - optional node (default is root object)
        depth - depth of recursion (-1 = search all to leafs on manual tree)
        hist - true to store the requested tree in the user's history
        path - optional sub-tree path
        Returns:
        JSON
      • toJSON

        public java.lang.String toJSON​(TreeView.TreeViewNode node,
                                       ObjectDB obj,
                                       Parameters.InlineParam inlines,
                                       boolean metadata,
                                       int depth,
                                       boolean hist,
                                       java.lang.String path)
        Export the object root as a JSON tree. Structure with all metadata:
         { object: "myObject", // Node object name
           row_id: "123", // Object row ID
           item: { field1:"value", field2:"value", ... }, // record of the row_id
           userkey: "user key", // object user key label
           nid: "3", // node definition id
           level: 5, // node level (0=root)
           path: "obj:id/.../myObject:123" // node path from root object
           style: "tv-blue", // from optional getStyleTree hook
           image: "leaf", // from optional getImageTree hook
           links: [
             { object: "childObject1", // child object name
               path: "obj:id/.../childObject1" // path from root object
               label: "child name", // object label
               count: 20, // children count
               page: 0, // current page (if pagination)
               maxpage: 3, // pages count (if pagination)
               icon: "cup", // object icon
               field: "foreignkey", // foreign key to parent object
               filters: { "foreignkey":"123" }, // filter to search children
               nolist: true, // to hide this list level = show only object items
               list: [ { object, row_id...}, ... ] // recursive
             }, ...
           ]
         }
         
        Parameters:
        node - Node definition in tree
        obj - Related object
        inlines - Inlined infos (doc, image...)
        metadata - Get tree metadata
        depth - Deep search limit
        hist - true to store the requested tree in the user's history
        path - optional sub-tree path
        Returns:
        JSON
      • storeHistory

        public void storeHistory​(ObjectDB obj,
                                 int max)
        Store the tree in user's preferences TREEVIEW_PREFS
        Parameters:
        obj - Business object root
        max - Max history size
      • getHistory

        public org.json.JSONArray getHistory​(Grant g)
        Get the TREEVIEW_PREFS as a JSON array
        Parameters:
        g - User rights
      • importJSON

        public java.lang.String importJSON​(org.json.JSONObject json,
                                           ObjectDB obj)
        Import the JSON tree as an XML import
        Parameters:
        json - JSON object
        obj - Optional root object
        Returns:
        Import logs
      • toString

        public java.lang.String toString()
        Get as string
        Overrides:
        toString in class java.lang.Object
        Returns:
        String
      • jsonReflexiveTree

        public static java.lang.String jsonReflexiveTree​(ObjectDB obj,
                                                         java.util.List<java.lang.String[]> rows,
                                                         java.lang.String fk,
                                                         int treeDepth,
                                                         Parameters.InlineParam inlines,
                                                         int context,
                                                         Parameters.ContextParam params,
                                                         boolean metadata,
                                                         boolean timestamp,
                                                         boolean visibleOnly,
                                                         java.lang.String edit)
        Build the reflexive object tree (for search service)
        Parameters:
        obj - Root object
        rows - List of records
        fk - Reflexive foreign-key name
        treeDepth - max level (-1 = deep search)
        Returns:
        JSON tree of rows [{ data, meta, count, list:[...]}, ...]