Thread: [java-gnome-hackers] More thougths about TreeView and related
Brought to you by:
afcowie
From: Vreixo F. L. <met...@ya...> - 2008-03-16 21:27:30
Attachments:
tree.patch
|
Hi! Some more thoughts about TreeView and related widgets 1. I've noticed you have implemented TreeModel as an abstract class instead of an interface. In my opinion this is a good design decission. However, I don't like one things, the dispatch function and its ugly "if (this instanceof XXXX)". It would be much better to have a protected method and let its subclasses (ListStore, TreeStore...) overwrite it (Object Oriented way!!). See attached patch. 2. A problem of the TreeModel as abstract class design is that it allows users to call setValue() on TreeModels that do not have such method, for example TreeModelFilter, of course getting the UnsupportedOperationException. I wonder, however, whether we could implement dispatch() in such models. For example, in TreeModelFilter we could delegate the operations in the base model easily. What do you think about this? 3. I've noticed TreeSortable interface is still not implemented. Is it by design, or just missing coverage? At a first sight, it seems setSortColumn() in TreeViewColumn is enought to sorting. However, this do not allow us to sort elements in a ComboBox, for example. And there is a missing feature: the gtk_tree_sortable_set_sort_func(), very useful for handling non-trivial sort in an easy way. For example, think again on my "nautilus" example. When sorting files by name, usually folders are show before files. In the same way, when sorting by size, we want to sort by the real size (a long) and not by the String size we need to use to show the size. Both cases are much easier of implement with a custom sort function. In my opinion, this should be exposed using java.util.Comparator<TreeIter> interface, and of course implemented internally using our signal handling system. I'd like to implement this, but please give me you opinions. 4. DataColumnPixbuf has a bug. Its type should be GDK_TYPE_PIXBUF, and not G_TYPE_OBJECT as it is now. With current implementation you get a (java:6304): Gtk-CRITICAL **: gtk_icon_view_set_pixbuf_column: assertion `column_type == GDK_TYPE_PIXBUF' failed when used with a IconView. The solutions is quite easy, but requires to change Value implemenation. So here comes the question, where to add the new Value constructor? Make it sense to add a gdk.Pixbuf dependence in glib.Value? Should I code it in gtk.Value instead? 5. GtkCellRendererPixbuf can render a Stock icon via the stock-id property, that is a gchar array. However, currently only a Pixbuf can be renderer with our CellRendererPixbuf. What about adding a new DataColumnStock? And what we should do? add a setStock(DataColumnStock) to CellRendererPixbuf, or either create a new CellRendererStock that obviously maps to a GtkCellRendererPixbuf? Opinions? Cheers, Vreixo Abra sua conta no Yahoo! Mail, o único sem limite de espaço para armazenamento! http://br.mail.yahoo.com/ |
From: Andrew C. <an...@op...> - 2008-03-17 09:43:01
|
On Sun, 2008-03-16 at 18:27 -0300, Vreixo Formoso Lopes wrote: > 1. I've noticed you have implemented TreeModel as an > abstract class instead of an interface. In my opinion > this is a good design decision. However, I don't like > one things, the dispatch function and its ugly "if > (this instanceof XXXX)". Yeah, changing that is fine. AfC Paris -- Andrew Frederick Cowie Operational Dynamics is an operations and engineering consultancy focusing on IT strategy, organizational architecture, systems review, and effective procedures for change management. We actively carry out research and development in these areas on behalf of our clients, and enable successful use of open source in their mission critical enterprises, worldwide. http://www.operationaldynamics.com/ Sydney New York Toronto London |
From: Andrew C. <an...@op...> - 2008-03-19 20:18:02
|
On Sun, 2008-03-16 at 18:27 -0300, Vreixo Formoso Lopes wrote: > === modified file 'src/bindings/org/gnome/gtk/TreeIter.java' > --- src/bindings/org/gnome/gtk/TreeIter.java 2008-01-14 03:53:07 > +0000 > +++ src/bindings/org/gnome/gtk/TreeIter.java 2008-03-15 19:18:49 > +0000 ... > + public boolean hasChild() { ... > + public TreeIter children() { ... > + public TreeIter children() { ... Unfortunately TreeIters are not stable first class references. I'll wait to so see what Srichand thinks of this, but I really don't think we should put this stuff on TreeIter. We moved one method only to TreeIter and that was just to make cycling over a model work.* The three methods you are proposing to add above are specialities of TreeStore and really do belong there (actually, they are part of the TreeModel interface, so the open question is whether you ever need the hierarchy methods on a model that is not a TreeStore), and not on TreeIter. [* and even that's sketchy: I am hitting a bug this week where a TreeModel is failing to update because I am making changes to something which affects the sort order while looping over a model's data. I should know better] AfC Toronto |
From: Andrew C. <an...@op...> - 2008-03-24 06:02:02
|
On Sun, 2008-03-16 at 18:27 -0300, Vreixo Formoso Lopes wrote: > 1. It would be much better to have a protected method and let its > subclasses (ListStore, TreeStore...) overwrite it Approved (as already discussed) > 2. A problem of the TreeModel as abstract class design > is that it allows users to call setValue() on > TreeModels that do not have such method, for example > TreeModelFilter, of course getting the > UnsupportedOperationException. I wonder, however, > whether we could implement dispatch() in such models. > For example, in TreeModelFilter we could delegate the > operations in the base model easily. What do you think > about this? Sounds like a good idea. Make sure you [unit] test the hell out of it though - the relationship between those pseudo TreeModels and their underlying ("child?!?") model is tricky. You can add tests to ValidateTreeModel or a new class as you see fit. > 3. I've noticed TreeSortable interface is still not > implemented. Is it by design, or just missing > coverage? At a first sight, it seems setSortColumn() > in TreeViewColumn is enough I implemented that this week, actually, but it was crashing on me (due to something else), so that's when I decided to change the error behaviour. I've already merged my work into the 'treestore' branch you sent me. I'll publish it in my repo when I get a chance (assuming I don't finish my part and merge it to 'mainline') > However, this > do not allow us to sort elements in a ComboBox, for > example. And there is a missing feature: the > gtk_tree_sortable_set_sort_func(), very useful for > handling non-trivial sort in an easy way. I always recommend people (and wrote up the docs to this effect) to add a column to their model that contains the sort ordering and then just tell the TreeViewColumn to sort based on that column. Quick, easy, and a hell of a lot less effort than calling back to Java every time. So it's not something I need personally. If you really do need it, go ahead. You can use TreeModelFilter's VISIBLE signal & setVisibleCallback() as a roadmap. The interesting bit is in GtkTreeModelFilterOverride.c Kinda sucks that those are on TreeSortable and not just on TreeModelSort. It will therefore be a pain in the ass to implement everywhere. I would imagine you have better things to do. Personally, I'd stick with sorting on a known column via TreeViewColumn's setSortColumn() or TreeModelSort's setSortColumn(). > 4. DataColumnPixbuf has a bug. The fix for that you submitted has been merged. AfC Vancouver -- Andrew Frederick Cowie Operational Dynamics is an operations and engineering consultancy focusing on IT strategy, organizational architecture, systems review, and effective procedures for change management. We actively carry out research and development in these areas on behalf of our clients, and enable successful use of open source in their mission critical enterprises, worldwide. http://www.operationaldynamics.com/ Sydney New York Toronto London |