Quick TreeModels with OGB - No Fluff Just Stuff

Quick TreeModels with OGB

Posted by: Andres Almiray on February 6, 2008

Preparing for one of the sessions for 2GX I had the need to setup a TreeModel with sample data to feel out the UI, before properly bridging the app to a database source. So there I was browsing the javadocs and code examples thinking that perhaps there was a groovier way to create the model, then I realized that ObjectGraphBuilder would be an ideal solution, which lead me to the following code

I cheated a bit, firstly I tell OGB that any node it will build should be a DefaultMutableTreeNode, no matter what name you choose the resulting object would be an instance of that class. Secondly I modify the default behavior for setting a child node into a parent node, as DefaultMutableTreeNode does not have a 'setNode()' method (or setXyz() if I choose that as node name). Once the model is created it is assigned to a JXTree giving the following result



Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »