Hello community,
I have a rather tricky task for which I cannot come up with a satisfying solution - I have to create a tree view for a Hibernate-based web application using Struts 1.2.9. The application I'm working on is quite complex so I hope I can explain everything in sufficient clarity. If not, feel free to ask. I'm really stuck with this so help would be appreciated a lot.
1.) The data structure
Basically, the tree is used to diplay a hierarchy of objects of the same type (Element).
Code:
Element
|
+-Element
|
+-Element
[...]
This means, I have a reference to a parentElement property in my Element class as well as a list of childElements. Displaying a tree view like that is no problem. What is a problem is the fact that I have to filter the data in the tree:
Element has a property called state, an integer that can assume values between 0 and 9. The user shall be able to select any number of state values that he wants to see in the tree. For example, the user could select only values 0, 1 and 6 to be displayed.
Collection filters don't seem to be sufficient for this task. Although I can apply a filter to the collection of childElements this does not solve problem, as I must consider every single descendant of an Element (not only direct children) when making the decision whether or not to display the Element in the tree.
Example: The user sets the filter to "show only Elements with a state of 3. Now look at the following tree:
Code:
Element_1 [state=0]
|
+-Element_2 [state=2]
|
+-Element_3 [state=3]
Basically the filter would now only display Element_3 as it is the only Element that has a state of 3. The problem is that Element_1 and Element_2 must also be displayed because the user must be able to navigate the tree view in order to reach Element_3 in the first place.
One approach would be to simply load the entire tree of Elements and then simply do not display (= generate markup for) those that have a state outside the current filtering bounds. This is not an applicable solution for my problem, though, as the tree view will contain a total of about 2,500 to 5,000 Elements and it is not an option to select the entire data - I store the data model of the tree in the HTTP session, so I have to pay attention to memory usage. With an estimated 30-50 concurrent users each of whom has his own tree model in the HTTP session, this approach is simply not acceptable.
Another idea would be to select the entire data model and then simply remove unused elements which is not really better than the first approach as it causes the same (superfluous) amount of database activity and (which is worse) creates a bunch of unreferenced objects after the tree structure has been cleaned up which will cause the Garbage Collector to steal performance from the application. Hence, not an option neither.
So my question is: Has anyone around these boards ever coped with complex tree structures like that and can give me some advice on how to handle these problems?
Thanks a lot in advance,
a desperate programmer.