Re: [Java-gnome-developer] [TreeView] How to know which DataColumn is used by a TreeViewColumn ?
Brought to you by:
afcowie
From: Andrew C. <an...@op...> - 2006-06-10 05:37:34
|
On Wed, 2006-06-07 at 09:04 +0200, Mehdi Rabah wrote: > In fact I wanted to know how do you choose and get this > blah_Object_DataColumn. The Listener that I use is in a class in a > different package (it contains a lot of code). I can make the two > class aware of each others and write getters, but... ... or you could add a parameter to your concrete implementation of the Listener and pass the object in that way. Just a thought. > > Which is the method to use to get this array? I didn't find it. You could use TreeIter's getModel() give you the underlying TreeModel - your ListStore or TreeStore presumably. From there you could use ListStore.getDataColumn(int)... http://java-gnome.sourceforge.net/docs/javadoc/org/gnu/gtk/ListStore.html#getDataColumn(int) Sometimes people just keep a reference to the array they feed to ListStore's constructor around and use that. I prefer to keep references to the individual DataColumnWhatevers as it reduces the casting hassle. > In fact my real problem is not to get the columns, it is to know which > is the dataColumn behind the TreeViewColumn clicked (it's the title > of my mail ^^) I want to know the cell (x,y) clicked Ah. That's a bigger problem. GTK's TreeViews are not spreadsheets, although the alternating shading in both dimensions might give that impression. They're more like square datatables as you might find in an RDBMS - columns specify data types, and then rows enumerate the data itself. > - I have the TreeIter (x) and I want the DataColumn (y). > I only have the TreeViewColumn (y but for view, not data), how to get > the DataColumn behind this ?? As such, a click event does not "go" to a DataColumn, for two reasons. One is that the event goes to the entire row (the row is selected; the row is activated, whichever). Note that that's not "selects all the columns Ctrl-A style, but just that the row, as a single atomic object, is selected|activated. The other reason is that in an MVC paradigm (which the TreeView/TreeModel code implements), the "click" doesn't hit the DataColumns of the model. It hits a piece of the presented UI, ie in your TreeView widget. You then have to ask the event for an TreeIter which points you at which row of data in the underlying square TreeModel (ie ListStore) that event corresponds to. You then just read off whichever columns are of interest to you. AfC Sydney -- Andrew Frederick Cowie Managing Director Operational Dynamics Consulting Pty Ltd Australia: Office 02 9977 6866, Mobile 04 1079 6725 Management Consultants specializing in strategy, organizational architecture, procedures to survive change, and performance hardening for the people and systems behind the mission critical enterprise. http://www.operationaldynamics.com/ |