| Graphic Components > Table Component > Table Component Services > Interacting with the Table Cells |
Interacting with the Table Cells |
INDEX
PREVIOUS
NEXT
|
The section Interacting with the Table View describes how to set an interactor for the entire table view. You can also associate behavior with business objects (for a class or for individual objects), as well as with individual table cell instances. To do so, you use object interactors, which provide the same options as the view interactor, that is:
The object interactor handles any events occurring on the object with which the interactor is associated, provided the view interactor has enabled the use of object interactors. You can check this by means of the isUsingObjectInteractor method or modify it with the setUsingObjectInteractor method. Object interactors are enabled by default.
No default interactor is associated with any object. To associate actions with mouse or keyboard events or to define a pop-up menu factory, you first have to create an IlpObjectInteractor. You may use the IlpDefaultObjectInteractor, extend it, or create your own implementation.
You can associate an object interactor with a representation object by using either CSS or the API. The following CSS extract shows how to proceed:
Table {
interactor: true;
}
object."ilog.tgo.model.IltNetworkElement" {
interactor: @+objInteractor;
}
Subobject#objInteractor {
class: 'ilog.cpl.interactor.IlpDefaultObjectInteractor';
}
The same configuration can be achieved through the API, as follows:
IlpTable table = // ... IltNetworkElement ne = //... IlpTableController tableController = table.getController(); // Create an object interactor IlpObjectInteractor objectInteractor = new IlpDefaultObjectInteractor(); tableController.setObjectInteractor(ne, objectInteractor); // Configuring the specific object interactor is similar to configuring // a view interactor. objectInteractor.setGestureAction(IlpGesture.BUTTON3_CLICKED, new MyAction());
You can associate an object interactor with a table cell, which is identified by a representation object and an attribute, by using either CSS or the API. The following CSS extract shows how to customize a specific object interactor to the cell that represents the name attribute:
Table {
interactor: true;
}
object."ilog.tgo.model.IltNetworkElement/name" {
interactor: @+objInteractor;
}
Subobject#objInteractor {
class: 'ilog.cpl.interactor.IlpDefaultObjectInteractor';
}
The same configuration can be achieved through the API, as follows:
IlpTable table = // ... IltNetworkElement ne = //... IlpAttribute attribute = IltNetworkElement.NameAttribute; IlpTableController tableController = table.getController(); // Create an object interactor IlpObjectInteractor objectInteractor = new IlpDefaultObjectInteractor(); tableController.setObjectInteractor( ne, attribute, objectInteractor);
Actions related to mouse and keyboard events can be customized in the same way as for the view interactor. A pop-up menu factory can also be defined in the same way as for the view interactor. Please refer to Interacting with the Table View.
Please refer to Interacting with the Graphic Components for a detailed description of interactors and gestures.
Selection in the table view is managed by an IlpTableSelectionModel. Different kinds of selection models can be set to the table by using the method setSelectionModel of the table view. However, only the IlpDefaultTableSelectionModel allows you to use the method setSelectionMode, as illustrated in the following code sample.
IlpTable tableComponent = new IlpTable(); // Set a selection mode to select multiple entire rows tableComponent.setSelectionMode(IlpTableSelectionMode. MULTIPLE_OBJECTS_SELECTION);
The different selection modes, defined by the enumerated type IlpTableSelectionMode, are the following:
EMPTY_SELECTION: nothing is selected when clicking the table.
SINGLE_OBJECT_SELECTION: a single row can be selected in the table.
MULTIPLE_OBJECTS_SELECTION: multiple rows can be selected (by using the traditional Shift and/or Control keys and dragging the mouse).
SINGLE_ATTRIBUTE_SELECTION: a single column can be selected.
MULTIPLE_ATTRIBUTES_SELECTION: multiple columns can be selected.
SINGLE_CELL_SELECTION: a single cell can be selected.
MULTIPLE_CELLS_SELECTION: multiple cells can be selected.| Note |
The selection mode can also be customized through the selectionMode property. The default mode is MULTIPLE_OBJECTS_SELECTION.
|
The following methods can be used to select business objects:
addSelectionObject(IlpObject object) adds a business object to the selection (the entire row is selected).
removeSelectionObject(IlpObject object) removes a business object from the selection.
getSelectedObjects() returns the collection of selected business objects.
getSelectedObject() returns the first selected business object (the first in the collection of business objects.)
isObjectSelected(IlpObject object) returns true if the given selected object is selected.
clearSelection() deselects all the selected objets.
selectAll() selects all the visible cells (this means that filtered objects and hidden columns are not selected.)
Similar methods exist in IlpTableSelectionModel to select individual columns and cells.
The table can dynamically adjust the width of one or more of its columns in order to fit in the available space. The table supports the following resizing modes defined in the enumerated type IlpTableResizeMode:
IlpTableResizeMode.AUTO_RESIZE_OFF
IlpTableResizeMode.AUTO_RESIZE_LAST_COLUMN
IlpTableResizeMode.AUTO_RESIZE_ALL_COLUMNS
| Notes |
Unlike what happens in the Swing JTable when the resizing mode is AUTO_RESIZE_LAST_COLUMN and when the entire table is resized, not all the columns are proportionally adjusted. Only the last column is adjusted.The default resize mode is |
The following example applies the AUTO_RESIZE_LAST_COLUMN mode to tableComponent.
IlpTable tableComponent = new IlpTable();
// Apply the policy
tableComponent.setAutoResizeMode
(IlpTableResizeMode.AUTO_RESIZE_LAST_COLUMN) ;
// Now, when a column or the entire table is resized, only the last column
//is shrunk or expanded
| Note |
The resize mode can also be controlled through the autoResizeMode property.
|
The user can dynamically resize the columns in a table by dragging the right border of their header.
To resize a column by programming, use the following code, setting a size of 10 to the name column.
IlpTable tableComponent = new IlpTable();
// This table will contain Network Elements
IlpClass acceptedClass = IltNetworkElement.GetIlpClass();
tableComponent.setAcceptedClass(acceptedClass);
...
// Retrieve the IlpAttribute corresponding to the name in
// IltNetworkElement class
IlpAttribute name = acceptedClass.getAttribute("name");
TableComponent.getTableColumn(name).setPreferredSize(10);
| Note |
The preferred width of a column can also be controlled through the preferredWidth property. For more information, see Customizing Column Headers and Rows.
|
You can fix a set of columns on the left side of the table. To do so, call the method setFixedColumnCount with the number of columns you want to fix as its parameter. The method has no effect if the value of its parameter is less than 0. A value of 0 indicates that none of the columns in the table will be fixed. If the parameter is greater than the number of columns in the table, all the columns are fixed. Here is an example.
IlpTable tableComponent = new IlpTable(); ... // Fix 3 columns tableComponent.setFixedColumnCount(3) ; // Fix a 4th column tableComponent.setFixedColumnCount(4) ; // Unfix all columns tableComponent.setFixedColumnCount(0) ;
You can retrieve the number of fixed columns in the table by using the method getFixedColumnCount, and know whether a given column is fixed by using the method isColumnFixed.
The number of fixed columns can be configured using style sheets, as described in Configuring the Table Component.
The user can dynamically rearrange the columns in a table by dragging their header to a new location. This functionality can be disabled and enabled with the method setReorderingAllowed of the class IlpTable.
To rearrange the columns by programming, use the following code.
IlpTable tableComponent = new IlpTable();
// This table will contain Network Elements
IlpClass acceptedClass = IltNetworkElement.GetIlpClass();
tableComponent.setAcceptedClass(acceptedClass);
...
// Retrieve the IlpAttribute corresponding to the name in
// IltNetworkElement class
IlpAttribute name = acceptedClass.getAttribute("name");
// Column "name" will take the second position
tableComponent.setColumnIndex(name,1);
| Note |
The default order of columns for a business class can also be controlled through the tableColumnOrder property. For more information, see Customizing the Table Column Order in the Styling documentation.
|
You can search for a string in a table by using the searchValue method. Searching is performed on the values displayed in the cells (that is, with styles applied), not on the raw values stored by the representation objects. The searchValue method returns the coordinates of the first cell containing the string, starting from the specified cell.
If the startingcell parameter is null, the search starts from the first cell in the table.
The search is not case sensitive if the parameter caseMatching is false.
The search can be performed row by row (scanRowByRow parameter is true), or column by column (scanRowByRow parameter is false).
The method returns null if the searched value cannot be found in the scope of the search.
IlpTable tableComponent = new IlpTable();
...
IlpCellCoordinates cellFound
= tableComponent.searchValue("a string", // searched string
null, // starting cell
false, // scan row by row
false); // case matching
You can alternatively hide and show columns in a table by using the method setColumnVisible. This method takes as its parameters the IlpAttribute of the affected column and a Boolean value setting the visibility to true or false. The attribute can be retrieved from the table model or from the table view using the method getColumn(int columnIndex).
Here is an example.
IlpTable tableComponent = new IlpTable();
// This table will contain Network Elements
IlpClass acceptedClass = IltNetworkElement.GetIlpClass();
tableComponent.setAcceptedClass(acceptedClass);
...
// Retrieve the IlpAttribute corresponding to the name in
// IltNetworkElement class
IlpAttribute nameAttr = acceptedClass. getAttribute("name");
// Hide the column
tableComponent.setColumnVisible(nameAttr, false) ;
// Show the column again
tableComponent.setColumnVisible(nameAttr, true) ;
The method isColumnVisible(IlpAttribute attribute) indicates whether the column specified by attribute is visible.
| Note |
The visibility of a column can also be controlled through the visible property. For more information, see Customizing Column Headers and Rows.
|
Columns can be sorted in ascending or descending order, interactively or by programming.
Interactively, the user clicks a column header once to sort it in ascending order, twice to sort it in descending order, and three times for no sorting at all. Using the Shift key while clicking the column header adds this column as a sorting criterion, whereas otherwise the column is set as the only sorting criterion.
By programming, you can use the following methods:
addSortingCriteria (IlpAttribute attribute, int order, boolean ascendingOrder, boolean useDisplayValue) adds the given attribute as a sorting criterion. This method takes as its arguments:
order parameter that defines the position of the column among the sorting criteria
ascendingOrder parameter, which, when set to true, sorts the column in ascending order
useDisplayValue, which indicates whether the sorting is applied to the display values (that is, with style sheets applied) or to the raw values
order equals 1, the column is selected as the first sorting criterion, if it equals 2, it is selected as the second sorting criterion, and so on. If order is less than 1, the column is considered as the first criterion. If order is greater than the current number of criteria, the column is considered as the next criterion.
getSortingOrder(IlpAttribute attribute) returns the position as a sorting criterion of the given attribute.
isUsingAscendingOrder(IlpAttribute attribute) returns true if the given attribute is sorted in ascending order.
isUsingDisplayValue(IlpAttribute attribute) returns true if the given attribute is sorted by display values.
removeAllSortingCriteria() removes all sorting criteria.
getSortedAttributesCount() returns the number of sorted columns in the table.
| Note |
The sorting order can also be controlled through the "sortingMode" and "sortingPriority" properties. For more information, see Customizing Column Headers and Rows.
|
It is possible to add custom attributes as new columns in a table component, as illustrated by the following code sample.
// Create a datasource
IltDefaultDataSource dataSource = new IltDefaultDataSource();
// Read an XML file into the datasource
dataSource.parse("alarms.xml");
// Create a table component
IlpTable tableComponent = new IlpTable();
// Get the Alarm class
IlpClass alarmClass =
IltSystem.GetDefaultContext().getClassManager().getClass("Alarm");
// Set the datasource to the component, and show instances
// of the Alarm class
tableComponent.setDataSource(dataSource, alarmClass);
// Add custom attributes
// Get the existing severity attribute
IlpAttribute severity = alarmClass.getAttribute("perceivedSeverity");
// Create a 'Short severity' attribute that represents the severity
// in a concise way
IlpAttribute shortSeverityAttribute =
new IlpReferenceAttribute("shortSeverity", severity);
tableComponent.addAttribute(shortSeverityAttribute);
You can filter the rows in a table by implementing the interface IlpFilter and setting it to the table.
To perform the filtering, you can use the method setFilter at two different levels:
IltNetworkElement instances with alarms.
boolAtt passed to the method getAttributeValue is an instance of IlpAttribute that returns a Boolean value. Business objects will be transformed into representation objects only if this argument is true.
The setFilter method at the adapter level may seem redundant with the setFilter method at the controller level; however, the advantages and drawbacks are not the same. Modifying the filter associated with an adapter to which a number of representation objects have already been added causes a large number of objects to be created or destroyed. Whereas changing a filter set to the controller only alters intermediate data, without leading to object creation or destruction. Setting a filter to an adapter significantly improves the performance, since it avoids creating a great number of unused representation objects, and saves storage space in the memory of the model.
The most likely scenario for using the setFilter method at two different levels is the following: The setFilter method at the adapter level can be considered the first step in the filtering process in the sense that it reduces the number of objects of the accepted class that will be created and displayed. The next step consists in setting a filter at the controller level to further reduce the number of objects that will be actually displayed in the table component.
You can specify the business objects that will not be represented in the table component depending on their business classes. To do so, you need to specify the business classes to be excluded using method setExcludedClasses in the table component adapter. To retrieve the adapter, use the getAdapter method. The adapter must be an instance of a subclass of IlpListAdapter.
You can specify that business objects from specific business classes are not represented in the table component. You can do that using the API, IlpAbstractAdapter.setExcludedClasses method, or using CSS.
The following example shows you how to prevent objects from business classes IltAlarm and IltLed to be represented:
Adapter {
excludedClasses[0]: "ilog.tgo.model.IltAlarm";
excludedClasses[1]: "ilog.tgo.model.IltLed";
}
| Note |
| The filtering that is performed through the use of the excluded class list takes actually place at the adapter level. |
Please refer to The Adapter Rule to know how to configure excluded classes through CSS.
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. All rights reserved. Legal terms. | PREVIOUS NEXT |