Developing with the SDK > Using and Writing Data Models > NonJavaBeans Example: Abstract Model Variant > Loading the Data Model and Style Sheet into the Diagram Component

The Tree Model sample is a subclass of IlvDiagrammerApplication. It therefore has the full application facilities as described in Customizing the Predefined Application.

The Data Model

To load the TreeSDMModel object, the sample overrides the createDiagrammer method to perform extra operations, see Code Sample 2.30.

protected IlvDiagrammer createDiagrammer()
  {     
    // Create a default tree model. The JTree creates one
    // if you don't specify a model: let's use it.
    //
    TreeModel treeModel = new JTree().getModel();
    
    // Create the IlvDiagrammer instance.
    //
    IlvDiagrammer diagrammer = super.createDiagrammer();

    // Create a default tree model. The JTree creates one

Code Sample 2.30 An Override Method for createDiagrammer

The sample creates an instance of TreeSDMModel, giving it a default tree model as a parameter, see Code Sample 2.31.

 // Create the Tree -> SDM model adapter.
    //
    TreeSDMModel sdmModel = new TreeSDMModel(treeModel);

Code Sample 2.31 Creating a Tree Model from the JTree One

The sample then gets the SDM engine for the IlvDiagrammer instance and sets the data model to the TreeSDMModel instance, as shown in Code Sample 2.32.

  // Tell the IlvDiagrammer to use this model:
    //
    diagrammer.getEngine().setModel(sdmModel);
    
    return diagrammer;
  }

Code Sample 2.32 Assigning the Data Model to the SDM Engine

The Style Sheet

The style sheet used to display the tree model is located in <installdir>/jviews-diagrammer81/codefragments/datamodel/treemodel/data/tree.css.

To load the style sheet, you pass the relative path to the sample as a startup argument.

public TreeModelDemo()
  {
    super(new String[]{
      "-title", "Tree Model Demo",
      "-style", "data/tree.css",
    });
  }

Code Sample 2.33 The TreeModelDemo Class with its Startup Arguments

The style sheet specifies a Tree layout in Radial mode with various parameters, in the two rules shown in Code Sample 2.34.

SDM {
   GraphLayout : "Tree" ;
}

GraphLayout {
   flowDirection : "Bottom";
   layoutMode : "RADIAL";
   globalLinkStyle : "ORTHOGONAL_STYLE";
   position : "300,200";
   parentChildOffset : "10";
   siblingOffset : "10";
}

Code Sample 2.34 Customizing a Tree Graph Layout in the Style Sheet

The style sheet also specifies the colors of the various objects.

Note that the CSSclass property of the TreeSDMNode class is recognized automatically by the CSS engine as specifying a CSS class because of its name, and therefore the values of this attribute can be used directly in rules. This allows you to set colors at the level of types of object with a simple syntax, see Code Sample 2.35.

node.food {
  fillColor2 : "lightgreen" ;
  }

// node.treenode[userObject='food'] node.treenode {
//   fillColor2 : "lightgreen" ;
// }

Code Sample 2.35 Cutsomizing Nodes by Type Through a CSSClass Property

The comment lines show the alternative, longer way to set the color for food objects. This longer way relies on a parent-child construct in CSS for Java. Note that the parent-child construct is not supported in the Designer.