Interacting with the tree nodes

The topic Interacting with the tree view describes how to set an interactor for the entire tree view. You can also associate behavior with business objects (for a class or for individual objects), as well as with individual IlpTreeNode instances. To do so, you use object interactors, which provide the same options as the view interactor, that is:
  • associating actions with mouse events,
  • associating actions with keyboard events,
  • defining a pop-up menu factory to build a pop-up menu that displays on representation objects.
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 tree

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:
Tree {
  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:
IlpTree tree = // ...
IlpTreeController treeController = tree.getController();
// Create an object interactor
IlpObjectInteractor objectInteractor = new IlpDefaultObjectInteractor();
// Associate the object interactor with a given representation object
IlpTreeNode treeNode = // ...
treeController.setObjectInteractor( treeNode, objectInteractor);
// Configuring the specific object interactor is similar to configuring 
// a view interactor. 
objectInteractor.setGestureAction(IlpGesture.BUTTON3_CLICKED, 
  new MyAction());
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 tree view.
Please refer to Interacting with the graphic components for a detailed description of interactors and gestures.