Discussion:
GWT Single Selection Model to prevent having all records unchecked in Cell List.
BM
2018-07-23 16:17:58 UTC
Permalink
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 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+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Thomas Broyer
2018-07-24 08:30:23 UTC
Permalink
Post by BM
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+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
BM
2018-08-02 14:23:08 UTC
Permalink
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;
}

}
}
Post by Thomas Broyer
Post by BM
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+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
BM
2018-08-03 09:25:10 UTC
Permalink
Ok It finally worked. The original problem was I had keyboard policy bound
to selection which was preventing the calls to setSelected.
Post by Thomas Broyer
Post by BM
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+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Loading...