Thursday, August 2, 2018

Re: GWT Single Selection Model to prevent having all records unchecked in Cell List.

Hi Thomas,
Thanks for the suggestions. I tried both of them and didn't really work. Am I missing something here? Any help would be appreciated.

1) I tried using Custom Selection Model and overriding setSelected. When checkbox is unchecked, it doesn't go to setSelected method. 

private class CustomSingleSelectionModel<T> extends SingleSelectionModel<T> {
public CustomSingleSelectionModel() {
super();
}

public CustomSingleSelectionModel(final ProvidesKey<T> keyProvider) {
super(keyProvider);
}


@Override
public void setSelected(final T object, final boolean selected) {
if (selected) {
Window.alert("Selected is true");
super.setSelected(object, selected);
}
else {
Window.alert("Selected is false");
//Do nothing. To skip already selected cell to uncheck.
}
}
}

2) I tried using customEventTranslator. I had breakpoint in translateSelectionEvent() method. But it doesn't go there. 

DefaultSelectionEventManager.<EnrollmentSummaryDTO> createCustomManager(
new CustomCheckboxEventTranslator<>(5))

private class CustomCheckboxEventTranslator<T> extends DefaultSelectionEventManager.CheckboxEventTranslator<T> {
private int column;

public CustomCheckboxEventTranslator() {
super();
}

public CustomCheckboxEventTranslator(final int column) {
super(column);
this.column = column;
}

@Override
public DefaultSelectionEventManager.SelectAction translateSelectionEvent(final CellPreviewEvent<T> event) {
final boolean isSelected = event.getDisplay().getSelectionModel().isSelected(event.getValue());
if (isSelected) {
return DefaultSelectionEventManager.SelectAction.IGNORE;
}
else {
return DefaultSelectionEventManager.SelectAction.TOGGLE;
}

}
}

On Tuesday, July 24, 2018 at 3:30:24 AM UTC-5, Thomas Broyer wrote:


On Monday, July 23, 2018 at 6:17:58 PM UTC+2, BM wrote:
I have GWT cell list with single selection model and checkbox which is one of the selection column. So it does toggle between rows since it acquires single section model. 

The toggle should function AS-IS but what I want is if one clicks on an already selected row, the selection should not uncheck that row. If they click on second row, the selection should move to second row which is fine. 

How do we do this?

You'd need a specific SelectionModel that would "refuse" to unselect the selected item.
It might be as simple as extending SingleSelectionModel, overriding setSelected(T,boolean) to do nothing when 'selected' is 'false'; or you may have to write your own SelectionModel (inspired by the SingleSelectionModel)

Alternatively, I suppose you could also achieve your goal with a specific EventTranslator that wouldn't toggle the selection on an already selected item (instead of using DefaultSelectionEventManager.createCheckboxManager(), use a new DefaultSelectionEventManager(new MyEventTranslator()); you could possibly wrap a CheckboxEventTranslator and return IGNORE on an already-selected item –event.getDisplay().getSelectionModel().isSelected(event.getValue())– instead of delegating to the CheckboxEventTranslator, which could then only return TOGGLE on an unchecked checkbox)

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment