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 the following code example.
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
The sample creates an instance of TreeSDMModel , giving it a default tree model as a parameter, see the following code example.
 // Create the Tree -> SDM model adapter.
    //
    TreeSDMModel sdmModel = new TreeSDMModel(treeModel);
The sample then gets the SDM engine for the IlvDiagrammer instance and sets the data model to the TreeSDMModel instance, as shown in the following code example.
  // Tell the IlvDiagrammer to use this model:
    //
    diagrammer.getEngine().setModel(sdmModel);
    
    return diagrammer;
  }

The style sheet

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",
    });
  }
The style sheet specifies a Tree layout in Radial mode with various parameters, in the two rules shown in the following code example.
SDM {
   GraphLayout : "Tree" ;
}

GraphLayout {
   flowDirection : "Bottom";
   layoutMode : "RADIAL";
   globalLinkStyle : "ORTHOGONAL_STYLE";
   position : "300,200";
   parentChildOffset : "10";
   siblingOffset : "10";
}
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 the following code example.
node.food {
  fillColor2 : "lightgreen" ;
  }

// node.treenode[userObject='food'] node.treenode {
//   fillColor2 : "lightgreen" ;
// }
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.