DBTreeView

Hello,

Is there a user guide for the various beans that ship with Servoy? I am a new Servoyian and am wasting a lot of my time trying to work out what, for example, is the difference between setNrelation and setMrelation in the DBTreeView. I would be able to work this sort of stuff out a lot quicker with instructions. There appears to be nothing in the Deleoper Guide or the User Guide about the beans that Servoy comes with.

What I’m currently wanting to do is create a treeview based on one table with Parent,Child,Child (3 levels). The table has company_id, division_id/parent-id, subdivision_id/subdivisionparent_id.

The problem is there doesn’t seem to be any information around that can tell me if this is even possible with one table. From the topic at http://forum.servoy.com/viewtopic.php?t … dbtreeview it is possible to have 3 levels with a multitable.

I feel like I’m stumbling around in the dark! Can someone help turn on the lights? Any help would be appreciated! :roll:

I’m very interested too. And another thing, selected a parent node is there a method to return all the childs node (recursively in a multi-depth tree)?

Hi,

Beans come in three variants:

  • Beans that ship with Servoy and that are specifically build for Servoy, like the DBTree(TableView) bean and the InMemDatagrid bean
  • Beans that ship with Servoy but are not specifically addapted for Servoy (all the J* beans, several charting beans)
  • 3rd party beans, like the Calendar bean from it2be or the Tableview bean from Dr. Maison for example).

The first category ought to be documented by Servoy. the second category we ship with Servoy, but is not activly supported. Documentation on these beans is everywhere on the internet. For documentation on beans in the third category you need to turn to your bean vendor.

When talking specifically about the DBTreeView bean: this bean has seen some major enhancements in several of the 3.5.x releases. While these are maintenance releases, we did not want to hold back the improved DBTreeView bean untill Servoy 4.0.

Since our documentation is only updated with major releases (so the upcomming 4.0), the documentation on the latest release of the DBTreeView bean is poor. Therefor, we posted the sample solution + comments on the forementioned thread.

with regards to your specific questions: The sample solution on the aforementioned thread shows you how to build a tree from records in one table using 1 and the same relation and also an example how to build a tree using different relations.

It soulnds like you need to create 2 relations: parent_to_subdivision and subdivision_to_subsubdivision.

If you compare your setup with the multitable example in the sample solution the only difference is that in your scenario, the 2 different relations point to the same table, whereas int eh sample solution they point to the same table. Technically, it doesn’t matter where the relation points. As long as you have created a binding for the table(s).

And another thing, selected a parent node is there a method to return all the childs node (recursively in a multi-depth tree)?

You can set the onClick method for when a node is clicked and have an argument send into the method you set. From there, you should be able to get all the childNodes yourself in scripting. There is no function on the bean to do that for you.

Paul

Paul,

Thanks for your post.

It soulnds like you need to create 2 relations: parent_to_subdivision and subdivision_to_subsubdivision.

If you compare your setup with the multitable example in the sample solution the only difference is that in your scenario, the 2 different relations point to the same table, whereas int eh sample solution they point to the same table. Technically, it doesn’t matter where the relation points. As long as you have created a binding for the table(s).

If the relations are created as required (parent_id to division_id and division_id to subdivision_id), how does the bean know what the relation is, in a single table example, between parent and division, division and subdivision when you are creating a binding to one table only and in the post on how to use the bean, you say “You can bind the bean to mulitple tables but a table can only be binded to the bean once.” It would appear that you can only provide one relation with one table and hence get only one child node, whereas when you create a binding with multiple tables, the relation between the tables is ‘figured out’ by the bean’s coding and voila, you get the related child nodes.

If you can do a 3 level tree from one table then I’ve missed something here! :oops:

You can let an (unstored) calculation return the relation name, so then each node can use a different relation.

With regards to the binding: in your scenario, you use 1 table, so you bind the bean only once to that table.

Using (unstored) calculations, you can make it as dynamic as you want.

For example, you set the relation name dataprovider to a calculation named “my RelationNameProviderCalc”. So, that is your binding for this table. For each node through, this calculation is called to get the relationName and the calc can return a different value for each node.

In your scenarion, you do need to be able to determine on row level what type of records you are dealing with, so you can return the proper relation name.

Does this make sense a bit?

Paul

Paul,

What you say makes sense and I suspect it’s the syntax of the method that is letting down my efforts.

So we all can relate to this topic, I have used your TreeBeanSample and added the following columns to the CRM database ‘Companies’ table:

division_id
subdivision_id
subdivparent_id.

I retained the ‘companies_to_companies’ relation which is company_id to parent_id (this gets the child nodes in the top left tree in the solution (company_tree).

I added the relation ‘companies_to_companies_divtosubdiv’ to create the child nodes from division to sub division. All aforementioned relations are within the companies table.

I then created the following unstored calc as you suggested, called ‘relation_name’:

if ( parent_id != null && subdivparent_id == null )
{
return ‘companies_to_companies’;
}
else if (parent_id != null && subdivparent_id != null)
{
return ‘companies_to_companies_divtosubdiv’;
}

I put some test data in and then tried many ways to try and get the nodes to render with no success. I have used the bottom left tree of your solution as the test and this is last variant of code I have tried in the ‘onLoad’ method:

//Init Multi Table Tree

_binding = elements.multiple_related_tables_tree.createBinding(controller.getServerName(), controller.getTableName());
_binding.setNRelationDataprovider(‘relation_name’);
_binding.setImageURLDataprovider(‘type_icon’);
_binding.setTextDataprovider(‘company_name’);

_binding = elements.multiple_related_tables_tree.createBinding(controller.getServerName(), controller.getTableName());
_binding.setNRelationDataprovider(‘relation_name’);
_binding.setImageURLDataprovider(‘type_icon’);
_binding.setTextDataprovider(‘company_name’);

controller.find();
parent_id = ‘^’;
subdivparent_id = ‘^’;

controller.search(true,true);
elements.multiple_related_tables_tree.addRoots(foundset);

This method gets the parents OK but renders no children (I gues you could say the tree is barren… :D ) The icons render OK, with different pretty colours for the different company_type_id.

The top left (company_tree) renders the division nodes, but that is it.

As a new Servoyian, I have to say that this TreeBean has proved harder to master than any of the J* beans I have tried so far (I guess the internet helps here) and all the SQL stuff. I hope your reply may help others with this bean!

I think the problem is in your relation_name calc.

if ( parent_id != null && subdivparent_id == null ) 
{ 
return 'companies_to_companies'; 
} 
else if (parent_id != null && subdivparent_id != null) 
{ 
return 'companies_to_companies_divtosubdiv'; 
}

The rootNodes do not have a parent_id filled, because you (I think correctly) set all records without a parent_id filled as rootnodes with the code below:

controller.find(); 
parent_id = '^'; 
subdivparent_id = '^'; 

controller.search(true,true);

In you calc through, you only return a relationName if the parent_id is not null, to no relationName is ever returned for the RootNodes, so therefor you get a barren tree :)

with regards to the DBTree bean being harde to master than JTree (for example): Well, partly that is because the documentation is not there yet, but on the other hand the DBTree beans is a lot more powerfull than the JTree, with it’s automatic databinding and such.

Paul

Thank you Paul, that was enlightening. I got it working with a simple NrelationName populating 3 levels fine. The reason I wanted a 2 relation tree from the one table was simply due to the stucture of the existing SQL data I’m working with that has the 2 relation structure. I’ll work with what I’ve got and see what happens!

It is a good thing that bean - actually very simple until you try and make it too complicated. :lol:

Glad you got it working! :D

Paul