Java Data Sources > Java Data Source Adapters > Using IlsTableDS2JTableAdapter > Managing Row Properties
 
Managing Row Properties
In this example, we are going to derive IlsTableDS2JTableAdapter to manage row properties and execute callbacks. We could also write a strategy by deriving the class IlsTableDS2JTableStrategy instead and adding this new strategy to the adapter using the method addStrategy.
First, we write a table view specification in which a row property named lockerStatus is defined. This property will be used to change the background color of a row. This is why it is not defined as a column attribute in the table, but as a property.
In the following code, the view specification is based on the object model of the network7 demo:
view DomainTableView (any containerIndex=0,
string containerClass="table.DomainTableFrame"):
represent IlsDSRepresentation repres:
any containerIndex = view.containerIndex;
string containerClass = view.containerClass;
string title = "A domain table view";
 
subscribe Node:
represent IlsRpRow row:
mandatory Ref<IlsRpTable> table = view.origin->table;
string column[0] = name;
string column[1] = (locker?locker.userName:"none");
 
# Property
int lockerStatus = (locker?((locker==view.user)?2:1):0);
 
subscribe origin Domain:
represent IlsRpTable table:
string column[0] = "Name";
string column[1] = "Locker name";
 
propagate nodes;
Practically, this view defines a table with two columns and the lockerStatus property, which can be used to modify the background color of the corresponding line. For this purpose, we are going to derive the class IlsTableDS2JTableAdapter on the JavaTM client side to store a mapping between the row representation object and the lockerStatus property.
package table;
 
import java.awt.event.*;
import java.util.*;
 
import ilog.ds.RowEvent;
import ilog.server.jcomp.MvValue;
import ilog.server.jsds.table.*;
import ilog.server.jsds.adapter.*;
 
public class DomainTableAdapter extends IlsTableDS2JTableAdapter {
private HashMap _rowLockerStatus;
 
public DomainTableAdapter() {
super();
_rowLockerStatus = new HashMap();
}
 
public void rowChange(RowEvent evt) {
Map map = evt.getProperties();
if ( (map != null) && (map.get("lockerStatus") != null) ) {
_rowLockerStatus.put(evt.getRow(), map.get("lockerStatus"));
}
super.rowChange(evt);
}
 
public void setLock(int rowNumber) {
((IlsRpRow)getDSRow(rowNumber)).execCallback("setLock", null);
}
 
public int getLockerStatus(int row) {
Long status = (Long)_rowLockerStatus.get(this.getDSRow(row));
return (status == null) ? 0 : status.intValue();
}
}
The hash map _rowLockerStatus stores this correspondence and the methods setLock and getLockerStatus let you access and modify this property. We use a global call back in the method setLock on the model object to give a way to change the lock status on the server. This update will be notified in return to the corresponding representation object. Then rowChange method is called on the adapter to update the hash map with the new locker status.
Finally, when the JTable is rendered, a call to the method getLockerStatus supplies the information for deciding the background color of each line of the table. See network7 demo for details.

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.