Hello everybody!
I have a big problem understanding the setChecked and
setCheckedElements methods of CheckboxTreeViewer.
What exact data do these methods expect?
This is our scenario:
We have lets say "items", which are represented as leafs in the tree-
structure. These items are organized in "folders" to facilitate
finding the items in the Tree-Control.
So to populate the TreeViewer-component, we build up a tree-data-
structure consisting of folders and items. This works very well so
far, as the tree is shown correctly.
Now comes the usecase:
The selected items are associated with entitys in our database. When
reading such an entity from the db, we get back a flat list of items
(without their folder-information), associated with the db-entity. Our
goal is now to set the appropriate checkboxes in the
CheckboxTreeViewer by calling setChecked/setCheckedElements.
As the Javadocs say, that setCheckedElements expects Object[]. Our
assuption was now, that we can provide a flat list of items, that can
be uniquely identified by their .equals()-method, or with the help of
an IElementComparer-implementation.
But when such a flat list is provided, the items can not be found in
the CheckboxedTreeViewer. Inspecting the code at runtime suggested,
that the control tries to climb along some parent/child-structure,
which of course is not present in our flat db-items.
The only way we could get the methods to work was to access the exact
reference of the underlying tree-data-structure, get a reference to
one of its nodes and provide this reference to the mentioned methods.
Does that mean, that we have to implement the search in the tree
ourselfs and memorize the references to the proper tree-items in the
Object[] ?
Any help is very appreciated.
Regards,
Markward
Roedy Green - 20 Jun 2007 10:50 GMT
On Wed, 20 Jun 2007 00:31:13 -0700, Markward
<markward.schubert@gmail.com> wrote, quoted or indirectly quoted
someone who said :
>Does that mean, that we have to implement the search in the tree
>ourselfs and memorize the references to the proper tree-items in the
>Object[] ?
I don't properly understand your question, so I will just make some
general observations that might be useful. I apologise If am
belabouring the obvious.
Your objects you use to represent your nodes and leaves will be a
custom class or two custom classes . They can have all manner of
additional information in them.
The tree structure is for controlling collapse of detail. You can
have your own search stuff that works quite independently e.g. by
adding your objects to various sorted ArrayLists or HashMaps or
TreeMaps.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Markward - 20 Jun 2007 12:03 GMT
Thanks for the reply!
Sorry that I formulated the question so complicated.
I will try to reduce it a bit :-).
What kind of objects are expected by the setCheckedElements-method?
Can I simply provide single objects, that are disconnected from the
model's tree structure to specify, which item should be checked? Or is
this method implemented to work only with references to objects
properly wired in the tree-model (with all the parents and childs)?
Regards,
Markward