Thanks Jens for the tip.
For anybody interested on the solution I've implemented it in the following
manner :
addCellPreviewHandler(new CellPreviewEvent.Handler<T>() {
@Override
public void onCellPreview(final CellPreviewEvent<T> event) {
// userChoiceHandler is used to notify an item choice
within the datagrid.
if (userChoiceHandler != null) {
NativeEvent nativeEvent = event.getNativeEvent();
String eventType = nativeEvent.getType();
if ((BrowserEvents.KEYDOWN.equals(eventType) &&
nativeEvent.getKeyCode() == KeyCodes.KEY_ENTER)
||
(BrowserEvents.DBLCLICK.equals(nativeEvent.getType()))) {
T selectedValue = event.getValue();
userChoiceHandler.onUserChoice(selectedValue);
}
}
}
});
On Thursday, October 18, 2012 2:27:29 PM UTC+2, Jens wrote:
>
> If you want to do this outside the Datagrid you can use
> DataGrid.addCellPreviewHandler(). The event contains all the information
> you need.
>
> And it is SelectionModel<? super T> because its less restrictive. For
> example you can have a DataGrid<Integer> that holds a more generic
> SelectionModel<Number>. Using generics that are least restrictive while
> ensuring type safety is a good practice for libraries/toolkits.
>
> -- J.
>
>
> Am Donnerstag, 18. Oktober 2012 14:08:41 UTC+2 schrieb Marius Grama:
>>
>> My (dirty) workaround was extending AbstractCell class and adding the
>> custom code within:
>>
>> @Override
>> public void onBrowserEvent(final Context context, final Element parent,
>> final C value,
>> final NativeEvent event, final ValueUpdater<C>
>> valueUpdater) {
>>
>> HasData<T> data = this.column.getTable();
>> SelectionModel<? super T> selectionModel =
>> data.getSelectionModel();
>>
>> if (selectionModel instanceof SingleSelectionModel) {
>> T val = (T) ((SingleSelectionModel<? super T>)
>> selectionModel).getSelectedObject();
>> userChoiceHandler.onUserChoice(val);
>> }
>> }
>>
>> method.
>>
>> btw, has anyone an idea why the method getSelectionModel() from
>> HasData<T> class returns
>> SelectionModel<? super T>
>> instead of
>> SelectionModel<T>
>> ?
>>
>>
>> On Thursday, October 18, 2012 2:01:33 PM UTC+2, Marius Grama wrote:
>>>
>>> I have a scenario where i am working with a GWT DataGrid on which when
>>> the user makes a double-click an event should be raised containing the
>>> information about the model bean of the selected selected row.
>>> e.g : For a DataGrid containing informations about persons (columns:
>>> first name , last name, age) when a double click (or enter key on the
>>> currently selected row of the datagrid) is made on one of the rows of the
>>> datagrid a MessageBox should appear containing the full name person
>>> selected.
>>>
>>> I've tried for some time to implement this scenario, but I haven't found
>>> so far an elegant (and simple) way to implement it.
>>>
>>> Can anybody assist me on this problem?
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/SFtn2b-vo_UJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.