Styling > Using Cascading Style Sheets > Customizing Tree Nodes

Tree nodes are graphically represented with a graphic object or icon and a label, as illustrated in the following example.

images/treenodes.gif

Although the graphic representation is similar, tree nodes are customized differently depending on whether the business objects represented in the tree are predefined or user-defined objects.

The following table lists the properties that are common to both predefined and user-defined business objects represented in a tree component.

Table 2.1 Common CSS Properties for Tree Node Rendering 
Property Name 
Type of Value 
Default 
Description 
focusBorderColor 
Color 
null 
Color to be used for the focus border of the node. The focus border shows which cell has the focus. If the value is null, the color of the active look-and-feel is used. 
focusBorderWidth 
Integer 
1 
Width of the focus border, in pixels 
labelBackground 
Color 
null 
Color to be used for the label background. If the value is null, the color of the active look-and-feel is used. 
labelFont 
Font 
null 
Font to be used for the label. If the value is null, the font of the active look-and-feel is used. 
labelForeground 
Color 
null 
Color to be used for the label foreground. If the value is null, the color of the active look-and-feel is used. 
labelPosition 
IlvDirection 
Right 
Position of the label relative to the icon. Possible values are: 
Left 
Right 
Top 
Bottom 
Center 
labelSpacing 
Float 
2f 
Spacing between the label and the icon in pixels. 
label 
String 
null 
Text to be displayed for the label. If the value is null, the identifier of the business object is displayed. 
labelVisible 
Boolean 
true 
Controls whether the label string is displayed or not. 
selectionFocusMode 
IlpSelectionFocusMode 
CELL_SELECTION_FOCUS_MODE 
Determines the rendering of the selection and focus. Possible values are: 
CELL_SELECTION_FOCUS_MODE: select both icon and label. 
LABEL_SELECTION_FOCUS_MODE: select only the label. 
The third possible value for this property, BASE_SELECTION_FOCUS_MODE, is not recommended for use in the tree. 
toolTipGraphic 
IlvGraphic or JComponent 
null 
This property accepts IlvGraphic and JComponent objects that are created in CSS using @+, @=, or @# constructors. 
toolTipText 
String 
null 
Tooltip text for the cell, used only if toolTipGraphic is null. If the value of this property and the toolTipGraphic property are both null, no tooltip is displayed. 
expansion 
IlpObject.ExpansionType 
IN_PLACE 
Determines whether an object should be expandable in the tree, so that its children can be displayed. Possible values are: 
IN_PLACE 
IN_PLACE_MINIMAL_LOADING 
NO_EXPANSION 

Predefined Business Objects

By default, the predefined business objects for managed objects are displayed in the tiny representation. The tiny representation is controlled by the CSS property tiny. It can be customized using the same CSS properties as for the symbolic representation (for example, foreground, background, label, labelPosition).

For a list of the properties that you can customize per type of predefined business object, please refer to the following sections:

Objects of the IltNetworkElement and IltLink classes are represented as follows in a tree:

images/tinyNELinkInTree.gif

Objects of the IltShelf, IltCard, IltPort, and IltLed classes are represented as follows in a tree:

images/tinyShelfCardPortLedInTree.gif

Some properties for the graphic representation of predefined business objects in a tree component have a default value that is different from the network and equipment components. These properties and their default values are the following:

Table 2.2 CSS Properties for Predefined Business Objects with Default Values Specific to the Tree 
Property Name 
Type of Value 
Default 
Description 
tiny 
Boolean 
true 
The tree always represents the node in compact form. The default value in other graphic components is false (that is, they use a more detailed representation). 
labelVisible 
Boolean 
true 
The tree always shows the label. The default value for some predefined business objects in other graphic components is false
labelPosition 
IlvDirection 
Right 
The tree always positions the label to the right of the icon. The default value in other graphic components is Bottom

User-Defined Business Objects

The default representation for user-defined business objects is a simple representation which combines a label with an optional icon, overlapping icon and tooltip.

images/TreebasicSample.gif

In addition to the common properties listed in Table 2.1, Common CSS Properties for Tree Node Rendering, user-defined business objects have the following specific properties that you can customize:

Table 2.3 CSS Properties for Tree Node Rendering of User-Defined Business Objects 
Property Name 
Type of Value 
Default 
Description 
icon 
Image 
null 
Icon to be displayed. If the value is null, no icon is displayed. 
iconVisible 
Boolean 
true 
Controls whether the icon is displayed or not. If this value is true and icon is null, a default icon will be displayed. 
overlapIcon 
Image 
null 
Defines the image used for the overlap icon. 
overlapIconVisible 
boolean 
true 
Determines whether the overlap icon is to be visible or not. 

How to Customize Tree Nodes

The following example shows you how you can customize the tree nodes. It is based on the CSS file located in

<installdir>/samples/tree/customClasses/data/tree.css

where <installdir> is the directory where you have installed JViews TGO.

The CSS selectors used to customize the nodes of the tree component are formed by the CSS type object and the CSS class <business class name>, as illustrated below:

object."NetworkElement" {
  label : @name;
  labelForeground : black;
  iconVisible : true;
  toolTipText : @name;
}
 
object."NetworkElement":selected {
  labelForeground: red;
}

The example above illustrates a tree node configuration using pseudoclasses: the graphic representation of the nodes is based on the pseudoclass "selected", so that the label foreground color changes whether the object is selected or not in the tree component.

Besides the selection state, you can also customize tree nodes according to the focus state or to custom pseudoclasses. The following example shows tree nodes whose label foreground color changes according to the focus and selection state:

object:selected {
  labelForeground: red;
}
 
object:focus {
  labelForeground: blue;
}
 
object {
  labelForeground: black;
}
How to Customize an Overlapping Icon

You can define an overlapping icon to be displayed over the default tree node icon.

To set an overlapping icon for all instances of a given business class, use the following style sheet extract:

object."Domain" {
    overlapIcon: '@|image("overlap.png")';
    overlapIconVisible: true;
}

Advanced Customization

To further customize the tree node rendering, you may also:

Using an IlvGraphic

IlvGraphic instances can be used to represent tree nodes through the property 'class'. The given class must follow the JavaBeans pattern; its properties can be directly customized in CSS.

The following example illustrates the use of IlvCompositeGraphic to represent tree nodes:

How to Use an IlvGraphic to Generate a Tree Node Representation
object."Workstation" {
  class: 'ilog.views.graphic.composite.IlvCompositeGraphic';
  layout: @+attachmentLayout;
  children[0]: @+wsBase;
  children[1]: @+wsLabel;
  constraints[1]: @+wsLabelConstraint;
}
 
Subobject#attachmentLayout {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentLayout';
}
Subobject#wsBase {
  class: 'ilog.views.graphic.IlvIcon';
  image: '@|image("workstation.png")';
}
Subobject#wsLabel { 
  class: 'ilog.views.graphic.IlvText';
  label: @name;
  foreground: black;
  font: 'arial-bold-12';
}
Subobject#wsLabel:selected { 
  foreground: red;
}
Subobject#wsLabelConstraint {
  class: 'ilog.views.graphic.composite.layout.IlvAttachmentConstraint';
  hotSpot: Left;
  anchor: Right;
  offset: 3,0;
}

For information about how to use JavaBeans in CSS and how to use the class property, refer to Class Property.

Using a JComponent

The following example shows how to define a JComponent to generate a tree node representation. It is based on the CSS file located in

<installdir>/samples/tree/customClasses/data/tree.css

where <installdir> is the directory where you have installed JViews TGO.

In this example, tree nodes are represented using a simple JLabel whose properties text, icon and foreground are customized according to the business attributes and the selection state of the tree node.

How to Use a JComponent to Generate a Tree Node Representation
object."Workstation" {
  class: 'javax.swing.JLabel';
  icon : @=icon;
  text: @name;
  foreground: black;
}
object."Workstation":selected {
  foreground: red;
}
Subobject#icon {
  class: 'javax.swing.ImageIcon';
  image: '@|image("workstation.png")';
}

As illustrated in this example, JComponent instances can be used to represent tree nodes through the property 'class'. The given class must follow the JavaBeans pattern; its properties can be customized directly in CSS (icon, text, foreground).

For information about how to use JavaBeans in CSS and how to use the class property, refer to Class Property.

Creating Your Own Renderer

You may want to replace the JViews TGO tree node representation by your own representation. To do so, you need to create your own implementation of the Swing TreeCellRenderer interface. For details, refer to Using an Arbitrary TreeCellRenderer in the Graphic Components documentation.

You will then be able to register the new tree cell renderer in the tree component through CSS or through the API.

For information on how to set a new tree cell renderer through CSS, refer to The View Rule in the Graphic Components documentation.

For information on how to set a new tree cell renderer through the API, refer to Configuring the Tree Component through the API in the Graphic Components documentation.

Improving Performance

You can improve the rendering performance of predefined business objects by replacing their graphic representation with a static image.

How to Improve Performance in the Tree Component by Rendering Predefined Business Objects as Static Images

The useDefaultCellRenderer CSS property enables the default tree node renderer, normally used for user-defined objects, to work with predefined objects. This technique will improve performance as the default renderer is based on static images instead of the dynamic alarm colored representation of predefined objects.

The following CSS example configures all ilog.tgo.model.IltObject business objects to be represented by the image myImage.png:

object."ilog.tgo.model.IltObject" {
  useDefaultCellRenderer: true;
  icon: '@|image("resource/myImage.png")';
  iconVisible: true;
}