View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

How to Create a Custom Tree

Bulbgraph.png   This feature is available from Openbravo PR14Q2

Contents

Introduction

Openbravo supports native support for the ADTree and LinkToParent structures (more info here). Openbravo also provides support for defining manual datasources to handle trees whose structure it not ADTree nor LinkToParent. This manual describes how to create a manual datasource to handle a custom tree table.

TreeDatasourceService class

All the datasources from custom tables must be a subclass of TreeDatasourceService. This datasource is used in the following events:

The TreeDatasource class exposes the following abstract methods:

addNewNode

protected void addNewNode(JSONObject bobProperties)

This method is invoked when a new record is added using DAL to a table whose main tree is the custom tree. All the bob properties of the new record are available from the bobProperties parameter.

The implementation of this method should take all the action needed to add the new record to the tree structure. For instance, if the custom tree is going to use the ADTree and ADTree node tables, at this point the ADTree node should be created for the new record.

deleteNode

protected void deleteNode(JSONObject bobProperties)

This method is invoked when a new record is delete using DAL from a table whose main tree is the custom tree. All the bob properties of the deleted record are available from the bobProperties parameter.

The implementation of this method should take all the action needed to remove the new record to the tree structure. For instance, removing an ADTree node, reparenting the children of the deleted node, etc.

moveNode

JSONObject moveNode(Map<String, String> parameters, String nodeId, String newParentId,
      String prevNodeId, String nextNodeId) throws Exception

This method is invoked when a node is moved using the tree grid view. It has these parameters:

This method is in charge of making the change needed to keep the tree structure updated after the change (i.e. updating the node sequence number, etc)

fetchNodeChildren

protected JSONArray fetchNodeChildren(Map<String, String> parameters,
      Map<String, Object> datasourceParameters, String parentId, String hqlWhereClause,
      String hqlWhereClauseRootNodes) throws JSONException, TooManyTreeNodesException

This method is invoked when the tree grid view or the tree selector need to fetch the children of a node.

It has the following parameters:

The Openbravo trees do not support pagination for fetching the nodes of a tree yet. This means that the datasource is asked for all the children. If the datasource were to return a number of nodes higher than the number stored in the TreeDatasourceFetchLimit preference, the TooManyTreeNodesException exception should be thrown.

This method should return a json object that contains all the properties of the records associated with the returned nodes plus:

nodeConformsToWhereClause

protected boolean nodeConformsToWhereClause(TableTree tableTree, String nodeId,
      String hqlWhereClause)

This method is invoked when the tree grid is filtered. This method is in charge of cheking if a particular node of a table tree should be filtered out by a HQL Where Clause.

It has the following parameters:

This method should return true if the node conforms to the HQL where clause, false otherwise.

getJSONObjectByRecordId

protected JSONObject getJSONObjectByRecordId(Map<String, String> parameters,
      Map<String, Object> datasourceParameters, String bobId)

This method is invoked when a tree table is being filtered. Its purpose is to return the full JSON representation of a node based on the node id. It has these parameters:

This method should return a json object that contains all the properties of the requested record plus: nodeId: the id of the node. Unless the tree needs to support nodes with several parents, the id of the record should be used to set the nodeId parentId: the id of the parent of the record. Most of the times the parentId parameter should be used to set this property. seqno: if the tree is ordered, the sequence number of the node should be set. _hasChildren: a boolean to specify if the node has children on its own.

Example: AD_TAB table

In this section a custom tree datasource for the ADTab table is going to be described.

The ADTab table stores tabs, which are structured hierarchy in a window. All windows have a header tab, that may have subtabs. Each of these subtabs can have subtabs can also have subtabs of their own, and so on.

The ADTab table builds the hierarchy of the tabs using the Tab Level and Sequence Number fields like this:

This tree must be custom because:

This is the result:

SalesOrderTabTree.png

Retrieved from "http://wiki.openbravo.com/wiki/How_to_Create_a_Custom_Tree"

This page has been accessed 2,105 times. This page was last modified on 10 March 2014, at 08:33. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.