SingleSelectionModel が有効になっている GWT CellTable があります。ユーザーが行をクリックすると、onSelectionChange(...) が確認ダイアログを起動し、続行するかどうかをユーザーに尋ねます。問題は、ユーザーが [キャンセル] をクリックすると、何も起こらないが、同じ行を選択できないことです (CellTable に 1 行しかないと仮定します)。ユーザーが [キャンセル] をクリックすると、選択をクリアできることはわかっていますが、それはonSelectionChange(..) が再び起動し、確認ダイアログがトリガーされます.....これは無限ループです。
以下は私のコードです:
// Add SelectionModel to dTable;
final SingleSelectionModel<Driver> ssm = new SingleSelectionModel<Driver>();
dTable.setSelectionModel(ssm);
ssm.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@ Override
public void onSelectionChange(final SelectionChangeEvent event)
{
SC.confirm("Do you want to contact the driver?", new BooleanCallback() {
public void execute(Boolean value) {
if (value != null && value) {
final Driver d = ssm.getSelectedObject();
dataStoreService.updateDrivers(d._UUID.toString(),tripDate.getValue(), loginInfo.getEmailAddress(),destination.getText().trim(),
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
public void onSuccess(String uuid) {
Window.alert("The driver has been notified. Please keep your reference id: "+uuid);
}
});
dataStoreService.getBookings(loginInfo.getEmailAddress(), new AsyncCallback<List<Booking>>() {
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
public void onSuccess(List<Booking> myBookings) {
ClientUtilities.populateBookings(bookingDataProvider, myBookings);
}
});
} else {
//clear selection
//ssm.setSelected(ssm.getSelectedObject(), false);
}
}
});
}
});
CellTable でこの種の状況を処理する方法を教えてもらえますか? 私はどんな解決策にもオープンです。