[java-gnome-hackers] big TreeModel API change
Brought to you by:
afcowie
From: Mark H. <mh...@ti...> - 2003-03-22 13:19:21
|
Hi, ListStore and TreeStore (TreeModels) are the model part of the tree and list widget MVC pattern. At the moment, they are constructed in the form: new ListStore( new Type[] {Type.STRING(), Type.INT() ...} ); and used: listStore.(set|get)Value( iter, 2, 5 ); (2 is the dataBlock of the store; 5 is the value) (these methods are overloaded for each possible type) There are two big disadvantages with this: - It is not easy to keep track of which dataBlock (aka column) relates to which set of data - methods require an integer argument corresponding to the order in which the Types were passed to the TreeModel constructor. - No type checking is performed. I've found this quite problematic recently when I had forgotten to call toString() on an object. I think a good way to solve these problems would be to create new classes: Abstract class dataBlock; dataBlockInt extends dataBlock dataBlockString dataBlockObject dataBlockBoolean They would then be used in the following way: private dataBlockString taskName = new dataBlockString(); private dataBlockInt hours = new dataBlockInt(); private dataBlockInt remaining = new dataBlockInt(); private dataBlockString person = new dataBlockString(); ... new ListStore( new dataBlock[] { taskName, hours, remaining, person } ); setValue( iter, taskName, "fix bugs" ); - type checking would be performed on this. I have used the term dataBlock where gtk usually says column. This is because I was confused when learning about these widgets as you also need TreeViewColumns, which are used by the views. I would prefer to keep calling these dataBlocks in the hope that the bindings will be easier to learn. But I could probably be convinced otherwise... Any comments? -- .''`. Mark Howard : :' : `. `' http://www.tildemh.com `- mh...@de... | mh...@ti... | mh...@ca... |