Altova StyleVision 2024 Professional Edition

Listing the Properties of a StyleVision Document

Home Prev Top Next

The listing below shows the properties of a StyleVision document (schemas, parameters, etc) can be loaded as nodes in a tree.

 

 

001 //access StyleVision Java-COM bridge

002 import com.altova.automation.StyleVision.*;

003

004 // access AWT/Swing components

005 import java.awt.*;

006 import javax.swing.*;

007 import javax.swing.tree.*;

008

009 /**

010  * A simple example of a tree control loading the structure from a StyleVision Document object.

011  * The class receives a Document object, loads its nodes in a JTree, and prepares

012  * for modal activation.

013  *

014  * Feel free to modify and extend this sample.

015  *

016  * @author Altova GmbH

017  */

018 class StyleVisionDialog extends JDialog

019 {

020   /**

021    * The tree control

022    */

023   private JTree myTree;

024  

025   /**

026    * Root node of the tree control

027    */

028   private DefaultMutableTreeNode top ;

029

030   /**

031    * Constructor that prepares the modal dialog containing the filled tree control

032    * @param xml   The data to be displayed in the tree

033    * @param parent  Parent frame

034    */

035   public StyleVisionDialog( Document doc, Frame parent )

036   {

037     // Construct the modal dialog

038     super( parent, "Data tree", true );

039     // Arrange controls in the dialog

040     top = new DefaultMutableTreeNode("root");    

041     myTree = new JTree(top);

042     setContentPane( new JScrollPane( myTree ) );

043     // Build up the tree; expand all nodes, hide root node

044     fillTree( top, doc );

045     for(int i = 0 ; i < myTree.getRowCount() ; ++i )

046       myTree.expandRow( i );

047     myTree.setRootVisible( false );

048   }

049

050   /**

051    * Loads the nodes of an XML element under a given tree node

052    * @param node  Target tree node

053    * @param doc Source XML element

054    */

055   private void fillTree( DefaultMutableTreeNode node, Document doc)

056   {

057     try

058     {

059       DefaultMutableTreeNode titleNode = new DefaultMutableTreeNode( "SchemaSources" ) ;

060       for (SchemaSource schema : doc.getSchemaSources())

061       {

062         String nodeText = "$" + schema.getName() ;

063         if ( schema.getIsMainSchemaSource() )

064           nodeText += " (main)";

065         DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(nodeText ) ;

066         node.add( titleNode ) ;

067         titleNode.add( newNode );

068         String attribute = schema.getSchemaFileName() ;

069         if ( attribute.length() > 0 )

070         {

071           DefaultMutableTreeNode subNode = new DefaultMutableTreeNode( "SchemaFile" ) ;

072           subNode.add( new DefaultMutableTreeNode( attribute ) );

073           newNode.add( subNode );

074         }

075         attribute = schema.getWorkingXMLFileName() ;

076         if ( attribute.length() > 0 )

077         {

078           DefaultMutableTreeNode subNode = new DefaultMutableTreeNode( "Working XML" ) ;

079           subNode.add( new DefaultMutableTreeNode( attribute ) );

080           newNode.add( subNode );

081         }

082         attribute = schema.getTemplateFileName() ;

083         if ( attribute.length() > 0 )

084         {

085           DefaultMutableTreeNode subNode = new DefaultMutableTreeNode( "Template" ) ;

086           subNode.add( new DefaultMutableTreeNode( attribute ) );

087           newNode.add( subNode );

088         }

089       }

090      

091       titleNode = new DefaultMutableTreeNode( "Parameters" ) ;

092       for (Parameter param : doc.getParameters())

093       {

094         DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( "$" + param.getName() );

095         node.add( titleNode ) ;

096         titleNode.add( newNode );

097         DefaultMutableTreeNode subNode = new DefaultMutableTreeNode( "Value" ) ;

098         subNode.add( new DefaultMutableTreeNode( param.getValue() ) );

099         newNode.add( subNode );

100       }

101     }

102     catch (Exception e)

103     {

104       e.printStackTrace();

105     }

106   }

107

108 }

 

© 2018-2024 Altova GmbH