Styling > Using Cascading Style Sheets > Customizing Table Cells

The default table cell renderer (ilog.cpl.table.IlpTableCellRenderer) generates two default types of graphic representations for table cells:

images/NETable.gif

Objects of the IltLink class are represented as follows in the table:

images/LinkTable.gif

Objects of the IltShelf class are represented as follows in the table:

images/ShelfTable.gif

Objects of the IltCard class are represented as follows in the table. (Objects of classes IltPort and IltLed differ only by the icon in the column "Object.")

images/CardTable.gif

Objects of class IltAlarm are represented as follows in the table:

images/AlarmTable.gif

images/customtable.gif

Both of these representations can be customized through the use of style sheets.

The following table lists the properties involved in the table cell rendering.

Table 2.4 CSS Properties for the Table Cells 
Property Name 
Type of Value 
Default 
Description 
focusBorderColor 
Color 
null 
Color to be used for the focus border of the cell. The focus border shows which cell has the focus. The default color is the same as in a JTable
focusBorderWidth 
Integer 
1 
Width of the focus border of the cell. 
horizontalAlignment 
SwingConstants 
Left 
Horizontal position of the label and icon in the cell. Possible values are: 
Center 
Left 
Right
icon 
Image 
null 
Icon to be displayed. By default, no icon is displayed. 
iconVisible 
Boolean 
true 
Determines whether the icon is displayed or not. 
labelBackground 
Color 
null 
Color to be used for the label background of a cell. By default, the color is white. 
labelFont 
Font 
null 
Font to be used for the label. By default, it is a sans serif font. 
labelForeground 
Color 
null 
Color to be used for the label foreground of a cell. By default, the color is black. 
labelInsets 
Integer 
1 
Space in pixels around the label and icon. 
labelPosition 
IlvDirection 
Right 
Position of the label relative to the icon. Possible values are: 
Center 
Top 
Left 
Bottom 
Right
labelSpacing 
Float 
4 
Spacing between the label and the icon. 
label 
String 
null 
Text to be displayed for the label. By default, no text is displayed. 
labelVisible 
Boolean 
true 
Determines whether the label is displayed or not. 
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. By default, no tooltip string is displayed. 
verticalAlignment 
SwingConstants 
Center 
Vertical position of the label and icon in the cell. Possible values are: 
Center 
Top 
Bottom

How to Customize the Object Column for Predefined Business Objects in Table Cells

In the case of predefined business objects for managed objects, an Object column displays the value of the attribute graphicRepresentation. It shows the tiny representation of the business object displayed in the table row. To customize this tiny representation, you can use the same CSS properties as for the symbolic representation of the specific predefined business class (for example, foreground, background, label, labelPosition). The following code extract:

object."ilog.tgo.model.IltNetworkElement" {
  foreground: green;
}

changes the foreground color used in the tiny representation of network elements.

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

How to Customize Table Cells

This use case shows you how to customize the cells of the table. The CSS selectors used to customize the table cells are formed by the CSS type object and the CSS class <business class name/attribute name>, as illustrated in the following example.

This example is based on the CSS file located in

<installdir>/samples/table/styling/data/table.css

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

object."Alarm/perceivedSeverity"[perceivedSeverity=0] {
  labelBackground: '#FFFFFF';
  label: Cleared;
  toolTipText: "Cleared alarm";
}
 
object."Alarm/perceivedSeverity"[perceivedSeverity=1] {
  labelBackground: '#C0C0C0';
  label: Indeterminate;
  toolTipText: "Indeterminate alarm";
}

The example illustrates a table cell configuration based on the value of the attribute perceivedSeverity.

By means of cascading style sheets, you can also customize the table cell representation according to the focus and selection states. To do so, you use the pseudoclasses focus and selected, as follows:

object."ilog.tgo.model.IltObject/name":selected {
  labelForeground: red;
}
 
object."ilog.tgo.model.IltObject/name":focus {
  labelForeground: blue;
}
 
object."ilog.tgo.model.IltObject/name" {
  labelForeground: black;
}
How to Customize Multiple Table Cells using Wildcards

This use case shows you how to customize multiple cells of a table. The CSS selectors used to customize the table cells are formed by the CSS type object and the CSS class <business class name/attribute name>, as illustrated in the previous example. However, you can use the * wildcard to indicate that multiple attributes of a given business class should be configured using a single selector.

The following example illustrates how you can configure all cells of business class ilog.tgo.model.IltNetworkElement to have a blue background:

object."ilog.tgo.model.IltNetworkElement/*" {
  labelBackground: blue;
}

You can also specify that all columns related to alarms should have a bold font:

object."ilog.tgo.model.IltObject/*larm*" {
  labelFont: "arial-bold-12";
}

Finally, the following CSS extract can be found in <installdir>/samples/table/styling/data/table.css, where <installdir> is the directory where you have installed JViews TGO. This CSS extract configures the background of all the cells in the rows displaying objects of the business class Alarm according to the value of the perceivedSeverity attribute.

object."Alarm/*"[perceivedSeverity] {
  labelBackground: '@|valuemap(@=perceivedSeverityBackgroundMap, @perceivedSeverity)';
}
 
object."Alarm/*"[perceivedSeverity]:selected {
  labelBackground: '@|valuemap(@=perceivedSeveritySelectionBackgroundMap, @perceivedSeverity)';
}

Advanced Customization

To further customize the table cell rendering, you may also:

Using an IlvGraphic

IlvGraphic instances can be used to represent table cells 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 IlvGeneralNode to represent table cells:

How to Use an IlvGraphic to Generate a Table Cell Representation
object."Service/type" {
  class: 'ilog.views.sdm.graphic.IlvGeneralNode';
  label: @name;
  labelPosition: Right;
  labelColor: black;
  labelSpacing: 4;
  shapeType: RECTANGLE;
  shapeWidth: 12;
  shapeHeight: 12;
}
object."Service/type":selected {
  labelColor: red;
}

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

Using a JComponent

JComponent instances can be used to represent table cells in the same way as they are used to represent tree nodes (see How to Use a JComponent to Generate a Tree Node Representation).

In the following example, table cells are represented using a simple JLabel whose properties text, icon and foreground are customized according to the business attribute and the selection state of the table cell.

How to Use a JComponent to Generate a Table Cell Representation
object."Service/type" {
  class: 'javax.swing.JLabel';
  icon : @=icon;
  text: @type;
  foreground: black;
}
object."Service/type":selected {
  foreground: red;
}
Subobject#icon {
  class: 'javax.swing.ImageIcon';
  image: '@|image("service.png")';
}

As illustrated in this example, JComponent instances can be used to represent table cells 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 table cell representation by your own representation. To do so, you need to create your own implementation of the Swing TableCellRenderer interface. For details, refer to Using an Arbitrary TableCellRenderer in the Graphic Components documentation.

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

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

For information on how to set a new table cell renderer through the API, refer to Configuring the Table 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 Table Component by Rendering Predefined Business Objects as Static Images

The graphicRepresentation attribute of predefined business objects can be configured with the useDefaultCellRenderer CSS property so that predefined business objects are rendered as static images in the table component. This technique will improve performance as static images are faster to render than the alarm colored tiny 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/graphicRepresentation" {
  useDefaultCellRenderer: true;
  icon: '@|image("resource/myImage.png")';
  iconVisible: true;
}