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
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TreeView.TreeViewNode
      Node definition
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeView​(Grant g, java.lang.String id, java.lang.String name, int mode, java.lang.String display)
      Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addRootObject​(java.lang.String obj)
      Add object to the tree root
      void addUserMenu​(java.lang.String object, java.lang.String id)
      Store user preference MENU_TREEVIEW = [{ treeview, object, rowid }]
      void delUserMenu​(java.lang.String object, java.lang.String id)
      Remove menu preference MENU_TREEVIEW = [{ treeview, object, rowid }]
      java.lang.String getDisplay()
      Get the treeview display label
      Grant getGrant()
      Get user rights
      org.json.JSONArray getHistory​(Grant g)
      Get the TREEVIEW_PREFS as a JSON array
      java.lang.String getId()
      Get the treeview ID
      int getMode()
      Get mode
      java.lang.String getName()
      Get the treeview name
      java.util.List<java.lang.String> getObjects()
      Get objects in tree definition (to limit index search)
      TreeView.TreeViewNode getRoot()
      Get the root node
      TreeView.TreeViewNode getRootObject​(java.lang.String obj)
      Search object node in root only
      java.util.List<java.lang.String> getRootObjectNames()
      Get objects on the tree root
      TreeView.TreeViewNode getTreeObject​(java.lang.String obj)
      Deep node search matching object
      TreeView.TreeViewNode getTreeObject​(java.lang.String obj, TreeView.TreeViewNode root)
      Deep node search matching object
      static java.lang.String getUserMenu​(Grant g)
      Get user preference MENU_TREEVIEW = [{ treeview, object, rowid }]
      java.lang.String importJSON​(org.json.JSONObject json, ObjectDB obj)
      Import the JSON tree as an XML import
      boolean isDynamic()
      Is dynamic: mode is not TreeView.MODE_MANUAL
      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)
      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, boolean unique, java.lang.String edit)
      Build the reflexive object tree (for search service)
      java.lang.String jsonToXML​(FlowXML xml, org.json.JSONObject json, java.lang.String obj, java.lang.String dfltAction, boolean strict)
      Convert the JSON tree as an XML flow
      org.json.JSONObject mergeTree​(Grant g, org.json.JSONObject tree1, org.json.JSONObject tree2, boolean onlyDiff)
      Merge tree 2 in tree 1 using same hierarchy and user-keys
      void removeId​(java.lang.String id)
      Remove ID
      TreeView.TreeViewNode searchLevel​(java.lang.String level)
      Search level
      void setDisplay​(java.lang.String label)
      Set treeview display label
      void setMode​(int mode)
      Set mode
      void storeHistory​(ObjectDB obj, int max)
      Store the tree in user's preferences TREEVIEW_PREFS
      java.lang.String toJSON()
      Treeview definition { id, name, mode, label, root: { node }}
      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
      org.json.JSONObject toJSON​(ObjectDB object, java.util.Map<java.lang.String,​java.lang.String> filters, java.io.File cfgDir, java.io.File docDir, boolean verbose, boolean withIds, boolean exploded, boolean scanReflexive, boolean exportable)
      Export a tree
      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.
      org.json.JSONObject toJSONTree​(TreeView.TreeViewNode node, ObjectDB obj, Parameters.InlineParam inlines, boolean metadata, int depth, boolean hist, java.lang.String path, boolean verbose, java.util.Map<java.lang.String,​java.lang.String> filters, boolean unique, boolean withIds, boolean withPath, java.io.File cfgDir, java.io.File docDir, boolean exploded, boolean scanReflexive)
      Export the object root as a JSON tree.
      java.lang.String toString()
      Get as string
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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
      • getGrant

        public Grant getGrant()
        Get user rights
        Returns:
        User rights
      • 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
      • toJSONTree

        public org.json.JSONObject toJSONTree​(TreeView.TreeViewNode node,
                                              ObjectDB obj,
                                              Parameters.InlineParam inlines,
                                              boolean metadata,
                                              int depth,
                                              boolean hist,
                                              java.lang.String path,
                                              boolean verbose,
                                              java.util.Map<java.lang.String,​java.lang.String> filters,
                                              boolean unique,
                                              boolean withIds,
                                              boolean withPath,
                                              java.io.File cfgDir,
                                              java.io.File docDir,
                                              boolean exploded,
                                              boolean scanReflexive)
                                       throws java.io.IOException
        Export the object root as a JSON tree. Structure with all metadata:
         { object: "myObject", // Node object name
           row_id: "123", // Node 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
        verbose - get all node ids and count
        path - optional sub-tree path
        filters - optional filters in tree
        unique - true to export item once even if it appears in several branches
        withIds - true to get all row_id and count
        withPath - true to get doc id and local path
        cfgDir - Optional directory to serialize the configuration hierarchy
        docDir - Optional directory to serialize the attached documents (defaults to cfgDir
        exploded - Exploded JSON in dir?
        scanReflexive - Scan reflexive links?
        Returns:
        JSON
        Throws:
        java.io.IOException
      • 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
      • jsonToXML

        public java.lang.String jsonToXML​(FlowXML xml,
                                          org.json.JSONObject json,
                                          java.lang.String obj,
                                          java.lang.String dfltAction,
                                          boolean strict)
        Convert the JSON tree as an XML flow
        Parameters:
        json - JSON object
        obj - Optional root object
        xml - output XML flow
        dfltAction - get or upsert
        strict - true to respect tree definition and N,N dependencies
        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,
                                                         boolean unique,
                                                         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)
        inlines - Inline doc options
        context - UI context
        params - Parent context
        metadata - true to get meta associated to item
        timestamp - get all timestamps?
        visibleOnly - visible fields only?
        unique - Avoid duplicated items
        edit - Optional edit list mode
        Returns:
        JSON tree of rows [{ data, meta, count, list:[...]}, ...]
      • toJSON

        public org.json.JSONObject toJSON​(ObjectDB object,
                                          java.util.Map<java.lang.String,​java.lang.String> filters,
                                          java.io.File cfgDir,
                                          java.io.File docDir,
                                          boolean verbose,
                                          boolean withIds,
                                          boolean exploded,
                                          boolean scanReflexive,
                                          boolean exportable)
                                   throws java.io.IOException
        Export a tree
        Parameters:
        object - Selected root object
        filters - Optional fields filters
        cfgDir - Optional directory to serialize the hierarchy
        docDir - Optional directory to serialize the attached documents (defaults to cfgDir)
        verbose - with node ids and count?
        withIds - with item ids?
        exploded - Exploded JSON in dir?
        scanReflexive - Scan reflexive links?
        exportable - only exportable fields?
        Returns:
        JSON
        Throws:
        java.io.IOException
      • mergeTree

        public org.json.JSONObject mergeTree​(Grant g,
                                             org.json.JSONObject tree1,
                                             org.json.JSONObject tree2,
                                             boolean onlyDiff)
        Merge tree 2 in tree 1 using same hierarchy and user-keys
        Parameters:
        g - User rights
        tree1 - Tree from a treeview scan, will receive missing tree2 nodes
        tree2 - Other tree to merge in tree1, will be corrupted by merge
        onlyDiff - do not return equals data/branches
        Returns:
        merged tree1 (tree2 corrupted)