Perforce JViews TGO Sample: Table Component - Styling
Description
This sample shows how to use the styling features of the Perforce JViews TGO Table Component.
How to Use the Sample
Shift
key to select several adjacent rows or Ctrl
to select individual rows.Shift
key and click the column header. Note that an indicator of the priority appears in the column header and that the first column selected has the highest priority. You can sort on as many columns as you want. If multiple columns are sorted, you should shift-click the header to change the sort order for a column.
How to Run the Sample as an Application
This sample can
be run as an application.
The installation directory contains
an executable JAR file,
table-styling.jar
,
that allows you to execute the sample with a double click from a
file browser. Note that if you are using Internet Explorer, you can
open the installation directory
and execute the JAR file from the browser. This
technique may not work in other Web browsers.
Alternatively, you
can run the sample application from the command line.
First check that the Ant utility is properly configured. If not, see the
instructions on how to configure Ant for Perforce JViews.
Then, go to the installation directory
of the sample and type:
ant run
Topics Covered
- Initializing a JTGO application.
- Creating a data source.
- Creating a table component and connecting it to the data source.
- Reading data from an XML file into a data source.
- Configuring the table component.
- Configuring the table header.
- Configuring the table cells.
- Adding the table to your Swing application.
Detailed Description
This sample shows how to create, use and customize a JTGO table component. The specific code of this sample is in the
doSample
method of styling.Main. It contains the following steps:
-
Initialize the application using the method IltSystem.Init.
You can pass the name of a deployment descriptor file to this method, but in this sample you do not need one. - Create a standard data source of class ilog.tgo.datasource.IltDefaultDataSource.
- Create a table component. The table component is of the class ilog.cpl.IlpTable, a JavaBean with a default constructor.
-
Attach the table component to the data source using the ilog.cpl.IlpTable.setDataSource method.
Because a data source may contain many objects of different classes, this method takes as a second argument the class to
display. In this case, instances of
IltNetworkElement
. are shown initially . However, the sample provides a combo box to change the class of objects displayed. - Set styling information by loading cascading style sheets. The data file table.css is read using the ilog.cpl.IlpTable.setStyleSheets method.
- Create a combo box to change the class displayed. The combo box and its listener are standard Swing components. When triggered, the listener calls the ilog.cpl.IlpTable.setAcceptedClass method of the table component to show instances of a different class.
- Read a data file into the data source. The data file network is read using the ilog.cpl.datasource.IlpDefaultDataSource.parse method. The file contains instances of some of the JTGO predefined classes: network elements, links, shelves, cards, ports, and LEDs.
-
Add the table to your Swing application.
IlpTable
is aSwing JComponent
, so it can be added to your application like any other Swing component.
Installation Directory
The Table Component - Styling sample is installed here.
Classes Involved
-
ilog.tgo.IltSystem
The class that initializes a JViews TGO application.
-
ilog.tgo.datasource.IltDefaultDataSource
The default datasource implementation.
-
ilog.cpl.IlpTable
The table component.
-
ilog.cpl.model.IlpAttribute
The business attribute definition.
-
ilog.cpl.table.selection.IlpTableSelectionMode
The table component selection mode definition.
-
ilog.cpl.table.IlpTableResizeMode
The table component resize mode definition.
Source Files
-
styling.Main
The entry point of the sample.
-
styling.AlarmPopupMenuFactory
The factory that creates pop-up menus for the objects.
-
styling.ShowDetailsAction
The action that displays object details upon double-click.