Graphic Components > Tree Component > Configuring the Tree Component > Configuring the Tree Component through the API

This section shows you how to configure a tree component by coding. Architecture of the Tree Component later in this section goes into the details of the classes involved in the architecture of the tree component.

The following example shows how to configure the tree view (ilog.cpl.tree.IlpTreeView) through the API. See Tree Component Services for programming details on the individual services.

How to Configure the Tree View with the API
IlpTreeView view = tree.getView();
 
// Setting the selection mode
view.setSelectionLookAndFeel(IlpTreeView.HIGHLIGHT_SELECTION_LOOK_AND_FEEL);
 
// Setting the tree cell renderer
view.setCellRenderer(new MyTreeCellRenderer());
 
// Setting the background color
view.setBackground(Color.white);

The following example shows how to configure the tree view interactor through the API. For details, see Interacting with the Tree View.

How to Configure the Tree View Interactor with the API
IlpTree tree = // ...
// Retrieve the view interactor
IlpViewInteractor viewInteractor = tree.getViewInteractor();
// Create an action
Action myAction = new MyAction();
// Clicking the 3rd mouse button will trigger myAction
viewInteractor.setGestureAction(IlpGesture.BUTTON3_CLICKED,myAction);

The following example shows how to configure the tree adapter (ilog.cpl.tree.IlpAbstractTreeAdapter) through the API. See Tree Component Services for programming details on the individual services.

How to Configure the Tree Adapter with the API
IlpAbstractTreeAdapter adapter = tree.getAdapter();
 
// Setting the filter
IlpFilter myFilter = new MyFilter();
// (it is the same as tree.setFilter(myFilter)
adapter.setFilter(myFilter);
 
// Origin
List myOrigins = new ArrayList();
myOrigins.add(objectID_1);
myOrigins.add(objectID_2);
.
.
.
myOrigins.add(objectID_n);
// in this case we want to display the
// origins
boolean showOrigin = true;
adapter.setOrigins(myOrigins, showOrigin);
 
// Expansion Strategy Factory
// Usually the expansion strategy factory relies
// on the adapter to access the data source and to
// load/release objects
IlpExpansionStrategyFactory myExpFactory = new
   MyExpansionStrategyFactory(adapter);
adapter.setExpansionStrategyFactory(myExpFactory);
 
// Tree Node Factory
IlpTreeNodeFactory myNodeFactory = new MyTreeNodeFactory();
adapter.setNodeFactory(myNodeFactory);