Frage

I have created a popup box that extends DialogBox and uses a cellTable that contains a list of values, one of which will be selected and inserted into a textBox.

-I have an onSelectionChange handler which is fired when one of the rows is clicked.

-I have an onDoubleClick handler which is fired when the same rows are double clicked.

both work when the other is commented out. But when they are both in the live code, whichever one is written first gets overwritten by the other one and no longer gets called.

Any way around this?

Code snipbit:

final SingleSelectionModel<popUpBoxContent> selectionModel= new <popUpBoxContent>();
cellTable.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler(){
public void onSelectionChange (selectionChangeEvent event){
//Do something
}});


final SingleSelectionModel<popUpBoxContent> selectionModel2= new <popUpBoxContent>();
cellTable.setSelectionModel(selectionMode2);
cellTable.addDomHandler(new DoubleClickHandler(){
public void onDoubleClick(final DoubleClickEvent event){
//Do something else
}},

DoubleClickEvent.getType());

Thank you!

War es hilfreich?

Lösung

Yes they get overwritten from what I can see in the snippet. Assuming "popUpBoxContent" is the data type with which the CellTable (I presume cellTable is a CellTable) is being populated you could try this and see if it works:

final SingleSelectionModel<PopUpBoxContent> selectionModel = new SingleSelectionModel<PopUpBoxContent>();
cellTable.setSelectionModel(selectionModel);
cellTable.addDomHandler(new DoubleClickHandler() {
    public void onDoubleClick(final DoubleClickEvent event) {
        PopUpBoxContent selected = selectionModel.getSelectedObject();
        if (selected != null) {
            System.out.println("double clicked");
        }
    }
},
DoubleClickEvent.getType());

selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
    public void onSelectionChange(SelectionChangeEvent event) {
        System.out.println("clicked");
    }
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top