<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>JDOMTreeModel</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Dear JDOM People,</FONT>
</P>
<P><FONT SIZE=2>Please scroll down to the "JDOMTreeModel:" bit.</FONT>
</P>
<BR>
<BR>
<P><FONT SIZE=2>-----------------------------------------------------</FONT>
</P>
<P><FONT SIZE=2>Dear All,</FONT>
</P>
<P><FONT SIZE=2>After much work over the Xmas period......I have the Alpha of the XMLDBMS Mapbuilder. Actually I had it a while ago but then work + home + a load of things stopped me writing this document......</FONT></P>
<P><FONT SIZE=2>This has been build against: JDK 1.2.2_006, JDOM Beta 7. </FONT>
</P>
<P><FONT SIZE=2>You will need to include your DB JDBC drivers .zip or .jar in your classpath.</FONT>
</P>
<BR>
<P><FONT SIZE=2>I am including the XMLDBMS version 1.1 code I have been working against (Ron could you do a merge as I don't think I've changed anything in that). You can get the JDOM code from www.jdom.org.</FONT></P>
<P><FONT SIZE=2>Also in the zip is my test Properties file (MapProps.txt) & a test Settings.xml</FONT>
</P>
<P><FONT SIZE=2>You can get this code from the binaries newsgroup in news.barkto.com</FONT>
</P>
<P><FONT SIZE=2>Look for a posting called "XMLDBMS Mapbuilder Alpha 1".</FONT>
</P>
<P><FONT SIZE=2>The Server Code is in there as well.</FONT>
</P>
<P><FONT SIZE=2>I have used the Version 1 DTD as a base however it should be easily capable of moving to any Map Document (or indeed any XML Document). </FONT></P>
<P><FONT SIZE=2>The main thing which needs looking at (apart from Version 2.0 Support) is simply Interfaces & where to use them so as to ensure that the Mapbuilder can load the right classes to deal with a specific Document type (inc the relevant Menu's, Actions, JInternalFrame Handlers etc). It's not much work however I simply wanted to chuck this out so people could play (& possibly even help). </FONT></P>
<P><FONT SIZE=2>There is a completely updated Properties Editor which is hopefully a heck of a lot better than the old one (& can cope with using different class'es for version 1 & 2 etc.</FONT></P>
<P><FONT SIZE=2>The Properties editor is where any testing of mapfile,XSLT, JMS etc. is doen from At the moment there is a mini "test" GUI which is again simply not wired up yet because of time constraints. Again it is simple & should be rapid.</FONT></P>
<BR>
<BR>
<P><FONT SIZE=2>The Mapbuilder is a MapDesigner. Again some bits aren't wired up (e.g. the "links" view (i.e. a tree of classmaps held together by their relationships with each other).</FONT></P>
<P><FONT SIZE=2>The DB part produces a fairly complete JDBC Picture as an XML Doc which you can save etc. It acts as a Cache. Some things need to be actively selected via it's JTree Menus (e.g. SchemaDetails has an Option to get all procedures, an getting fileds etc for a given table requires a selection.)</FONT></P>
<P><FONT SIZE=2>Again many things are lurking e.g. Possibly not every element refreshes correctly etc. Find the probs. </FONT>
</P>
<P><FONT SIZE=2>The code that builds the XML view of your JDBC enabled DB is in:</FONT>
</P>
<P><FONT SIZE=2>org.xmlmiddleware.xmldbms.gui.treebuilder.JDBCTreeBuilder</FONT>
</P>
<BR>
<P><FONT SIZE=2>How to Use:</FONT>
</P>
<P><FONT SIZE=2>It uses the Std Version 1.1 Properties interface as such to start the MapBuilder you simply call (from my .bat file)</FONT>
</P>
<P><FONT SIZE=2>SET JARHOME=D:\aat\Jars</FONT>
</P>
<P><FONT SIZE=2>java -cp %JARHOME%\xmldbms.jar;%JARHOME%\classes12.zip;%JARHOME%\db2java.zip;%JARHOME%\xerces.jar;%JARHOME%\xalan.jar;%JARHOME%\jaxp.jar;%JARHOME%\jdom.jar;.; org.xmlmiddleware.xmldbms.gui.mapbuilder.Mapbuilder File=MapProps.txt </FONT></P>
<BR>
<P><FONT SIZE=2>The PropertiesEditor can be started either from the MapBuilder or on it's own e.g.</FONT>
</P>
<BR>
<P><FONT SIZE=2>SET JARHOME=D:\aat\Jars</FONT>
</P>
<BR>
<P><FONT SIZE=2>java -cp %JARHOME%\xmldbms.jar;%JARHOME%\xerces.jar;%JARHOME%\xalan.jar;%JARHOME%\jaxp.jar;%JARHOME%\jdom.jar;.; org.xmlmiddleware.xmldbms.gui.PropertiesEditor File=MapProps.txt </FONT></P>
<BR>
<P><FONT SIZE=2>It uses a settings file & can use a DBCache XML file thus in the Properties File there are 2 new values:</FONT>
</P>
<P><FONT SIZE=2>settingsfile</FONT>
<BR><FONT SIZE=2>e.g. settingsfile=D\:\\Move\\aat\\Settings.xml</FONT>
</P>
<P><FONT SIZE=2>If this is not set then it will look into it's local dir for a file called Settings.xml</FONT>
<BR><FONT SIZE=2>If this is not found then it will create a new (blank) settings file</FONT>
<BR><FONT SIZE=2>And </FONT>
</P>
<P><FONT SIZE=2>dbfile</FONT>
<BR><FONT SIZE=2>e.g. dbfile=D\:\\Move\\aat\\db.xml</FONT>
</P>
<P><FONT SIZE=2>If this is not set then it will look into it's local dir for a file called db.xml</FONT>
<BR><FONT SIZE=2>If this is not found then it will create a new (blank) DBCache</FONT>
</P>
<P><FONT SIZE=2>I have not yet produced a DTD for the settings simply because I was not sure it has been finished. If people want I will run my Settings.xml off against a DTD from Document tool.</FONT></P>
<P><FONT SIZE=2>The Elements which I have Written JInternalFrames for are:</FONT>
</P>
<P><FONT SIZE=2>ClassMap - org.xmlmiddleware.xmldbms.gui.v1.ClassMap</FONT>
<BR><FONT SIZE=2>IgnoreRoot - org.xmlmiddleware.xmldbms.gui.v1.IgnoreRoot</FONT>
<BR><FONT SIZE=2>Options - org.xmlmiddleware.xmldbms.gui.v1.Options</FONT>
</P>
<P><FONT SIZE=2>Equally you can select a table from the JDBC view & create a std ClassMap.</FONT>
</P>
<BR>
<P><FONT SIZE=2>What makes (hopefully) the whole thing so extensible??? Well as they say the fewer the lines of code the more thought is required & what you're seeing here is about version 8...where all the others were scrapped. The key is the JDOMTreeModel.</FONT></P>
<BR>
<P><FONT SIZE=2>JDOMTreeModel:</FONT>
</P>
<P><FONT SIZE=2>I have been looking at the JTree & JDOM. We have 2 different forms of XML Mapfile (version 1.0 & 2.0) & thus I had to cope with the idea of multiple Docs. Also I built some code which creates a JDOM/XML "picture" of a Database using the JDBC DB & ResultSet Metadata & had a settings Doc thus I had 4 Docs. So I wanted an easy & generic way to bind a JDOM/XML Doc to a JTree.</FONT></P>
<P><FONT SIZE=2>Thus I have created a JDOMTreeModel which extends DefaultTreeModel.</FONT>
</P>
<P><FONT SIZE=2>It uses a class called ElementNode which extends BasicNode which in turn extends javax.swing.tree.DefaultMutableTreeNode.</FONT></P>
<P><FONT SIZE=2>The BasicNode is there because at some point I may need other sorts of Nodes.</FONT>
</P>
<P><FONT SIZE=2>An Element Node Contains that element. It also overloads a some methods e.g. getName such that (in getName) it returns the Value in an element (if there is one) or if there isn't then it returns the Element Name. It also has a method called getElement which simply returns the element for that Node.</FONT></P>
<P><FONT SIZE=2>The best idea is to have a static Node as a field in your GUI Class that whenever the mouse reports that a Node has been selected you simply set the "hidden node" to the selected Node. This gives you a single point to query against.</FONT></P>
<P><FONT SIZE=2>This makes doing any Swing/JTree based GUI using an XML Document as a base so easy......</FONT>
</P>
<P><FONT SIZE=2>example:</FONT>
</P>
<P><FONT SIZE=2>//To setup a JTM - It is usefull to provide a root node when constructing even if you are then going</FONT>
<BR><FONT SIZE=2>// to replace it via the document you're feeding in. </FONT>
</P>
<P><FONT SIZE=2>JDOMTreeModel JTM = new JDOMTreeModel(new ElementNode(new Element("Root")));</FONT>
</P>
<P><FONT SIZE=2>// You then feed in your JDOM Doc</FONT>
</P>
<P><FONT SIZE=2>JTM.setDoc(Doc);</FONT>
</P>
<P><FONT SIZE=2>// Then you simply use it as the Model for your JTree e.g.</FONT>
</P>
<P><FONT SIZE=2>JTree DBTree = new JTree();</FONT>
<BR><FONT SIZE=2>DBTree.setModel(JTM);</FONT>
</P>
<P><FONT SIZE=2>& You're done.</FONT>
</P>
<P><FONT SIZE=2>Other stuff:</FONT>
</P>
<P><FONT SIZE=2>I have created a std TreeListener</FONT>
</P>
<P><FONT SIZE=2>public class BasicTreeListener</FONT>
<BR><FONT SIZE=2> extends java.awt.event.MouseAdapter</FONT>
<BR><FONT SIZE=2> implements</FONT>
<BR><FONT SIZE=2> javax.swing.event.TreeExpansionListener,</FONT>
<BR><FONT SIZE=2> javax.swing.event.TreeSelectionListener</FONT>
</P>
<P><FONT SIZE=2>Useage Example:</FONT>
</P>
<P> <FONT SIZE=2>BasicTreeListener BTL = new BasicTreeListener( getDBTree(), getTreePopupMenu());</FONT>
</P>
<P> <FONT SIZE=2>getDBTree().addTreeExpansionListener( BTL );</FONT>
<BR> <FONT SIZE=2>getDBTree().addTreeSelectionListener( BTL );</FONT>
<BR> <FONT SIZE=2>getDBTree().addMouseListener( BTL );</FONT>
</P>
<P> <FONT SIZE=2>getDBTree().setEditable(false);</FONT>
</P>
<BR>
<P><FONT SIZE=2>All you have left to do....is decide what menu's you want adding onto the JTree & thus the ActionPerformed.</FONT>
</P>
<P><FONT SIZE=2>Please look at org.xmlmiddleware.xmldbms.gui.mapbuilder.Mapbuilder.initTree()</FONT>
<BR><FONT SIZE=2>&</FONT>
<BR><FONT SIZE=2>org.xmlmiddleware.xmldbms.gui.mapbuilder.Mapbuilder.addMenus()</FONT>
<BR><FONT SIZE=2>& finally</FONT>
<BR><FONT SIZE=2>org.xmlmiddleware.xmldbms.gui.mapbuilder.Mapbuilder.actionPerformed(ActionEvent)</FONT>
</P>
<BR>
<P><FONT SIZE=2>to see how to do this.</FONT>
</P>
<P><FONT SIZE=2>So if you want to build something which can view any JDOM Doc (& thus any XML) as a JTree and then have menu actions coming off from the Tree it couldn't get much easier. In essence your GUI can edit an Element (e.g. I am using code within JInternalFrames) & then the JDOM Doc is automatically updated.</FONT></P>
<P><FONT SIZE=2>Enjoy</FONT>
</P>
<BR>
<P><FONT SIZE=2>Adam</FONT>
</P>
</BODY>
</HTML>