Rogue Wave JViews TGO Sample: Table Component - Styling
Description
This sample shows how to use the styling features of the Rogue Wave JViews TGO Table Component.
How to Use the Sample
The sample shows a table that contains various types of predefined JTGO business objects, as well as user-defined business objects. The table allows you to select rows, as well as to move and resize columns. You can choose the class of objects to display with a combo box in the lower part of the screen.
- To select a row, click anywhere inside one of its cells. Use the
Shift
key to select several adjacent rows orCtrl
to select individual rows. - To move a column, click its header and drag it to a new location. To resize it, click the separator between two columns in the header and drag it left or right.
- The table also allows you to sort the rows based on the contents of one or more columns. To do so, click a column header; an indicator of the sort order will appear. Clicking again inverts the order, clicking a third time removes the indicator.
- The data can also be sorted based on more than one column. To add a column to refine the sort, use the
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. - To replace the current sort order with a new one, click any column header.
How to Run the Sample as an Application
This sample can also 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 Rogue Wave 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.