我正在 GWT 中编写一个小部件,并希望它在选择复合元素时Composite实现HasSelectionHander并触发SelectionEvent
到目前为止,我有以下内容:
public class SelectionClass extends Composite implements HasSelectionHandlers<Integer>{
    private final EventBus eventBus = new SimpleEventBus();
    //...   
    private void somethingHappens(int i){
            //How do i fire an event?
    }       
    @Override
    public HandlerRegistration addSelectionHandler(SelectionHandler<Integer> handler) {
            return eventBus.addHandler(SelectionEvent.getType(), handler);
    }       
}
public AnotherClass{
    // ...  
    SelectionClass.addSelectionHandler(new SelectionHandler<Integer>() {
            @Override
            public void onSelection(SelectionEvent<Integer> event) {
                    Window.alert(String.valueOf(event.getSelectedItem()));
            }       
    });     
    // ...  
}
我对如何准确地触发事件感到有些困惑。我EventBus在 SelectionClass 中使用 an 是否正确(上图)。任何帮助,将不胜感激。