I am writing an RCP application in eclipse that contains a combobox, and upon selecting any of its items, a selection event is being fired and some random code comes in action. The listener looks something like this:
randomComboBox.addSelectionListener(new SelectionListener(){
@Override
public void widgetSelected(SelectionEvent e) {
// random code
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
My question is: is it possible to fire the event from the code? For example if I add:
randomComboBox.select(0);
no event is being fired. In this case, do I have to write my own listener?
The
selectmethod of the combo box sends an event of the typeSWT.Modifywhen it changes the selection, so you could use aModifyListenerinstead of aSelectionListener.Actually, the
ModifyListenerlistens to changes in the text field of the combo box, this means it reacts to the text change that is caused by the selection. This also means that it will be fired if that text is changed by other paths (e.g. user entries in the combo text field).Keeping that behaviour in mind, a
ModifyListenermight be an option.