comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcqada@earthlink.net>
Subject: Re: JGNAT, TreeModels, and interfaces
Date: Sun, 18 Mar 2001 22:08:49 GMT
Date: 2001-03-18T22:08:49+00:00	[thread overview]
Message-ID: <3AB5243D.DE376890@earthlink.net> (raw)
In-Reply-To: 3AB2080E.7C0DFB53@earthlink.net

Responding to myself again, for the aid of posterity and future Deja
searches :-)

I went at this problem of programmatically updating a JTree a slightly
different way and got everything to work.  Part of the problem was that
I'm still doing a lot of "programming by example" when tackling new
areas, and sometimes the example can get you locked into a particular
approach.

Anyhow, instead of using the JTree constructor that creates a tree
starting with a root node, I created a DefaultTreeModel with that root
node, and then created the JTree from that DefaultTreeModel.  By doing
this I had access to all the DefaultTreeModel methods and it was pretty
straightforward then to update the tree.

Although there was a ripple effect, the fundamental change required just
two lines of code.

Marc


"Marc A. Criley" wrote:
> 
> With JGNAT 1.1p on RedHat Linux 6.2...
> 
> I've built a JTree structure, and now I need to update one of its leaves
> programmatically, i.e., by the program, not through user editing.
> 
> Having generated the new leaf node, I need to inform the tree to display
> it.  It appears the way to do this is using the "nodeChanged" method in
> the javax.swing.tree.defaultTreeModel class.
> 
> The Ada binding to this method is:
> 
>    procedure nodeChanged
>      (This : access Typ;
>       P1_TreeNode : access javax.swing.tree.TreeNode.Typ'Class);
> 
> where "Typ" is the DefaultTreeModel tagged type.
> 
> So besides the new node, I also need to specify an instance of the
> DefaultTreeModel.
> 
> Here's where the problem comes in.
> 
> To me, it seems that I ought to get the tree model from the tree using
> the getModel method from javax.swing.jtree, since what I'm working with
> is a Jtree.
> 
> The method looks like this:
> 
>    function getModel
>       (This : access Typ)
>        return javax.swing.tree.TreeModel.Ref;
> 
> I pass in my Jtree and get back a handle to a TreeModel...which is _not_
> a DefaultTreeModel.  TreeModel is in fact a Java interface that
> DefaultTreeModel implements.
> 
> I can't figure out how to get that TreeModel into a form that I can pass
> to a DefaultTreeModel procedure.  In Java, it appears that a typecast is
> performed.  But this won't fly in Ada because these two classes are
> independent of one another and so can't be converted.
> 
> A DefaultTreeModel implements the TreeModel interface, so if I was
> getting a DefaultTreeModel I could easily get at its TreeModel
> capabilities, but I'm getting the TreeModel and somehow need to upgrade
> that to a DefaultTreeModel instead.
> 
> Suggestions are welcome :-)
> 
> Marc A. Criley



      reply	other threads:[~2001-03-18 22:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-16 13:31 JGNAT, TreeModels, and interfaces Marc A. Criley
2001-03-18 22:08 ` Marc A. Criley [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox