| Styling > Using Cascading Style Sheets > Customizing Tree Nodes |
Customizing Tree Nodes |
INDEX
PREVIOUS
NEXT
|
Tree nodes are graphically represented with a graphic object or icon and a label, as illustrated in the following example.
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.
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
For details, refer to Customizing the Expansion of 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:
Objects of the IltShelf, IltCard, IltPort, and IltLed classes are represented as follows in a tree:
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:
The default representation for user-defined business objects is a simple representation which combines a label with an optional icon, overlapping icon and tooltip.
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:
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;
}
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;
}
To further customize the tree node rendering, you may also:
IlvGraphic to generate an arbitrarily complex graphic representation (IlvCompositeGraphic). For more information about composite graphics, see Graphic Objects.
JComponent to generate a graphic representation and customize it using CSS.
TreeCellRenderer interface) to generate an arbitrary Swing Component.
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:
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.
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.
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.
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.
You can improve the rendering performance of predefined business objects by replacing their graphic representation with a static image.
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;
}
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. All rights reserved. Legal terms. | PREVIOUS NEXT |