Interacting with the table view

The table component allows you to define behavior for the main view of the table, as well as specific behavior for the table header. In both cases, an interactor is used. The default interactors handle the basic interaction supported by the table (selection, moving columns, for example) and can be easily customized to:
  • associate actions with mouse events and focus events,
  • associate actions with keyboard events,
  • build a pop-up menu to be displayed on the table.

Interacting with the main table view

A default view interactor (an instance of IlpDefaultTableViewInteractor) is associated with the main view of the table component. It is retrieved using the getViewInteractor method of IlpTable.

How to associate an action with a gesture in a table component

You can associate actions with mouse events by using either CSS or the API. The following CSS extract shows how to proceed:
Table {
  interactor: true;
} 

Interactor {
  viewInteractor: @+viewInt;
}

Subobject#viewInt {
  class: 'ilog.cpl.table.interactor.IlpDefaultTableViewInteractor';
  action[0]: @+viewAction0;
}

Subobject#viewAction0 {
  class: 'ilog.cpl.interactor.IlpGestureAction';
  gesture: BUTTON1_DOUBLE_CLICKED;
  action: @+myAction;
}
Subobject#myAction {
  class: MyAction;
}
The same configuration can be achieved through the API, as follows:
// Create the table, and retrieve the view interactor
IlpTable tableComponent = new IlpTable()
IlpViewInteractor viewInteractor = tableComponent.getViewInteractor();
// Create a Swing action
// We assume the MyAction class is defined elsewhere
Action myAction = new MyAction();
// Double-clicking the left mouse button will trigger myAction
viewInteractor.setGestureAction(IlpGesture.BUTTON1_DOUBLE_CLICKED,
                         myAction);
.
Note
A gesture is a series of one or more atomic user input events that are meant to invoke a single action.

How to associate an action with a keyboard event in a table component

You can associate actions with keyboard events by using either CSS or the API. The following CSS extract shows how to proceed:
Table {
  interactor: true;
} 

Interactor {
  viewInteractor: @+viewInt;
}

Subobject#viewInt {
  class: 'ilog.cpl.table.interactor.IlpDefaultTableViewInteractor';
  action[0]: @+viewAction0;
}

Subobject#viewAction0 {
  class: 'ilog.cpl.interactor.IlpKeyStrokeAction';
  keyStroke: 'ctrl typed D';
  action: @+myAction;
}

Subobject#myAction {
  class: MyAction;
}
The same configuration can be achieved through the API, as follows:
// Create an action
Action myAction = new MyAction();
// Typing CTRL+D will trigger myAction
KeyStroke ctrlD = KeyStroke.getKeyStroke('D',java.awt.Event.CTRL_MASK);
viewInteractor.setKeyStrokeAction(ctrlD, myAction);
Both mouse and keyboard actions can be invoked anywhere in the table, except in the header.

Interacting with the table header

Usually, specific behavior is needed for the table header. For that reason, the table component also has a default interactor for the header. It is an instance of IlpDefaultTableHeaderInteractor and can be retrieved using the getHeaderInteractor method of IlpTable. This interactor can be customized in the same way as the interactor for the main view.
Note
If no header interactor is set to the table controller (that it, if it is null), the events are handled directly by the view interactor.

Using pop-up menus

The JViews TGO interactors allow you to create custom pop-up menus easily for the table. To do this, you should implement the IlpPopupMenuFactory interface. One abstract and two default menu factories are provided, which you can extend by subclassing:
The following code shows how to define a custom pop-up menu factory for the table view.

How to define a custom pop-up menu for the table view

You can customize a pop-up menu factory for the table view or the table header, either through CSS or through the API. The following CSS extract shows how to configure a CSS file to add a pop-up menu factory:
Table {
  interactor: true;
} 

Interactor {
  viewInteractor: @+viewInt;
}

Subobject#viewInt {
  class: 'ilog.cpl.table.interactor.IlpDefaultTableViewInteractor';
  popupMenuFactory: @+viewPopupMenuFactory;
}
Subobject#viewPopupMenuFactory {
  class: MyTableMenuFactory;
}
The same configuration can be achieved through the API, as follows:
  1. Create a class extending IlpAbstractPopupMenuFactory as follows:
    public MyTableMenuFactory extends IlpAbstractPopupMenuFactory
    {
      public JPopupMenu createPopupMenu
        (IlpObjectSelectionModel ilpSelectionModel)
      {
      // The following menu could be context-dependent
      JPopupMenu popupMenu = new JPopupMenu();
      // Create here the items and add them in the menu
      // ....
      return popupMenu;
      }
    }
    
  2. Use a pop-up menu in the table view or header:
    IlpTable tableComponent = new IlpTable();
    // Use a custom pop-up menu in the table view
    IlpPopupMenuFactory tableMenuFactory = new MyTableMenuFactory();
    tableComponent.getViewInteractor().setPopupMenuFactory(tableMenuFactory);
    // Use the default header pop-up menu in the table header
    IlpPopupMenuFactory headerMenu = 
      new IlpDefaultTableHeaderMenuFactory();
    tableComponent.getHeaderInteractor().setPopupMenuFactory(headerMenu);
    
For a detailed description of interactors and gestures, refer to Interacting with the graphic components.