Graphic Components > Table Component > Table Component Services > Interacting with the Table Cells

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.

How to Associate an Object Interactor with a Representation Object in the Table

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());
How to Associate an Object Interactor with a Table Cell

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.

Handling the Selection

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.

How to Handle Selection in the Table
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:

The following methods can be used to select business objects:

Similar methods exist in IlpTableSelectionModel to select individual columns and cells.

Fitting to Contents

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:

The following example applies the AUTO_RESIZE_LAST_COLUMN mode to tableComponent.

How to Resize a Table
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.

Resizing Columns

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.

How to Resize Columns in a Table
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.

Fixing Columns in a Table

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.

How to Fix the Position of Columns in a Table
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.

Moving Columns

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.

How to Rearrange Columns in a Table
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.

Searching for a String in a Table

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.

How to Search for a String in a Table
IlpTable tableComponent = new IlpTable();
...
IlpCellCoordinates cellFound
   = tableComponent.searchValue("a string", // searched string
                                null,       // starting cell
                                false,      // scan row by row
                                false);     // case matching

Showing or Hiding Columns in a Table

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.

How to Show or Hide Columns in a Table
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.

Sorting Columns

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:

Note
The sorting order can also be controlled through the "sortingMode" and "sortingPriority" properties. For more information, see Customizing Column Headers and Rows.

Adding New Columns to the Table

It is possible to add custom attributes as new columns in a table component, as illustrated by the following code sample.

How to Add Columns to a Table
// 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);

Filtering Rows

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:

  1. At the adapter level
  2. You have the choice to apply the filter to the table component or to the adapter, the result will be the same.
    The following code shows how to create a filter displaying only IltNetworkElement instances with alarms.
    How to Set a Filter to the Table Component
// Create a table component and set it to a data source
IlpTable tableComponent = new IlpTable();
IltDefaultDataSource dataSource = new IltDefaultDataSource();
// The second parameter specifies which kind of object contained 
// in the data source the table will show
tableComponent.setDataSource(dataSource, 
  IltNetworkElement.GetIlpClass());
IlpFilter alarmFilter = new IlpFilter() {
  public boolean accept(Object object) {
    IlpObject ilpObject = (IlpObject)object;
    Integer alarmCount = 
      (Integer)ilpObject.getAttributeValue(IltObject.AlarmCountAttribute);
    return (alarmCount.intValue() > 0);
   }
};
tableComponent.setFilter(alarmFilter);
The following example shows how to set a filter to an adapter.
How to Set a Filter to the Adapter
adapter.setFilter(new IlpFilter() {
  public boolean accept(Object object) {
   IlpObject bo = (IlpObject)object;
   return bo.getAttributeValue(boolAtt).equals(Boolean.TRUE);
  }
});
The argument 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.
  1. At the controller level.
  2. Filtering takes places between the model and the view and is performed by the controller.
    How to Set a Filter to the Table Controller
IlpTableController controller = table.getController();
controller.setFilter(new IlpFilter() {
  public boolean accept(Object object) {
    IlpObject bo = (IlpObject)object;
    return bo.getAttributeValue(boolAtt).equals(Boolean.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.

Excluding Table Rows

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.

How to Specify Excluded Classes in the Table Component

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.