How complex can this be?

time to read 4 min | 636 words

TriStateTree.png How long would it take you to implement the functionality to the left?

I have already spent over a day implementing a tri state tree. The scary part is that I have not even tried to build the tree myself, it was a completely innocent chain of events that led to this stage.

Let me explain a bit about what I am trying to do first. It is a tree that shows the assoication of an entity to a hierarchy. To make a concrete example, let us say that we have an employee entity that should have responsability on a part of the hierarchy. The hierarchy is 5 levels deep, and fairly big.

At first, I tried to simply use the ASP.Net Tree View. That didn't work very well. Too much data was sent to the client. So I needed to do lazy load of the tree, using Ajax. The ASP.Net tree view supports that, but, to my utter lack of amazement, not in a way that allows me to plug in easily and handle additional concerns after the load has happened.

Time to write my own tree :-(, that isn't very hard, actually, there are numerous examples of tree around, and it was fairly easy to turn MkTree into an ajaxian one. Now I had the proper extension points, and I could turn my mind to the other concerns. As you can see in the picture, there is a checkbox that indicate whatever the user is associated with this node or not. So far, not so hard, I can handle that with ease.

The problem is that I need to handle the third state, where the assoication is in a deeper level, and still show it to the user. So, in a 5 level hierarchy, where the user can be associated to any of the levels (many to many, btw), I need to find out if it is associated with this node or any of its children.

17 left outer joins later (and no, this isn't just a number, I really got to that), I realized that I have no idea what I am doing and that I probably want to stop before I reach the triple digit joins statement (don't ask, but it was a hand written query, to stem the OR/M sucks complaints) again.

Solved that (with MutliQuery and by thinking about it from the other end), and found out that the hierarchy is so nicely real world, so you can have a 4th level node that doesn't have a 3rd level node, which should still go under its grandfather on the 2nd level. And if that is not enough the next issue in line is solving the issue of editing a partially loaded tree, what do I do with the unloaded state? Yuck!

Right now, it is compromised of:

  • User Control
  • Two custom server controls
  • Web Service
  • JavaScript on the client side
  • Controller
  • Create querying with NHibernate
  • Complex UI interactions

It is a %$#@$& tri state tree view, for crying out load, and I can't believe how complex this has turned out to be. And it is not over yet.