| Graphic Components > Tree Component > Tree Component Services > Interacting with the Tree View |
Interacting with the Tree View |
INDEX
PREVIOUS
NEXT
|
The IlpTree allows you to associate behavior with the tree view as a whole, and with the business objects it contains.
In particular, using the default view interactor, you can:
The IlpTree is associated with an IlpDefaultViewInteractor, which should satisfy most needs. You can retrieve this interactor by calling the method getViewInteractor().
You can associate actions with mouse events by using either CSS or the API. The following CSS extract shows how to proceed:
Tree {
interactor: true;
}
Interactor {
viewInteractor: @+viewInt;
}
Subobject#viewInt {
class: 'ilog.cpl.interactor.IlpDefaultViewInteractor';
action[0]: @+viewAction0;
}
Subobject#viewAction0 {
class: 'ilog.cpl.interactor.IlpGestureAction';
gesture: BUTTON3_CLICKED;
action: @+myAction;
}
Subobject#myAction {
class: MyAction;
}
The same configuration can be achieved through the API, as follows:
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);
You can find out whether this event occurred on an IlpObject by means of the following code (which should be in the MyAction class).
// Implementation of the ActionListener interface
public void actionPerformed(ActionEvent e) {
// ILOG JTGO interactors use IlpViewActionEvent
IlpViewActionEvent viewEvent = (IlpViewActionEvent)e;
// Get the IlpObject (if any) where the interaction occurred
IlpObject ilpObj = viewEvent.getIlpObject();
// Perform operation on the given object
}
You can associate actions with keyboard events by using either CSS or the API. The following CSS extract shows how to proceed:
Tree {
interactor: true;
}
Interactor {
viewInteractor: @+viewInt;
}
Subobject#viewInt {
class: 'ilog.cpl.interactor.IlpDefaultViewInteractor';
action[0]: @+viewAction0;
}
Subobject#viewAction0 {
class: 'ilog.cpl.interactor.IlpKeyStrokeAction';
keyStroke: '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
viewInteractor.setKeyStrokeAction(
KeyStroke.getKeyStroke('D',java.awt.Event.CTRL_MASK),myAction);
You can customize a pop-up menu factory for the tree view 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:
Tree {
interactor: true;
}
Interactor {
viewInteractor: @+viewInt;
}
Subobject#viewInt {
class: 'ilog.cpl.interactor.IlpDefaultViewInteractor';
popupMenuFactory: @+viewPopupMenuFactory;
}
Subobject#viewPopupMenuFactory {
class: MyPopupMenuFactory;
}
The same configuration can be achieved through the API, as follows:
// Subclass IlpAbstractPopupMenuFactory, which has useful shortcuts
IlpPopupMenuFactory popupMenuFactory = new IlpAbstractPopupMenuFactory(){
// Add the identifier of each of the selected objects to the menu
public JPopupMenu createPopupMenu (IlpObjectSelectionModel ilpSelectionModel)
{
// Create an empty popup menu
JPopupMenu menu = new JPopupMenu();
// Access the selected objects from the selection model
Collection selectedObjects = ilpSelectionModel.getSelectedObjects();
// fill the menu according to the current selection
return menu;
}
};
The following code shows you how to associate the defined pop-up menu factory with the tree component.
// Set the popup menu factory to the view interactor viewInteractor.setPopupMenuFactory(popupMenuFactory);
Please refer to Interacting with the Graphic Components for a detailed description of interactors and gestures.
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. All rights reserved. Legal terms. | PREVIOUS NEXT |