I'm trying to control which of the columns in a CellTable will trigger a SelectionChangeEvent by implementing CellPreviewEvent.Handler.
The problem is that even if I cancel the SelectionChangeEvent, the CSS-styles for selected rows are still applied (.cellTableKeyboardSelectedRow), which means it looks like the row i being selected to the user. Is there any way to change this behavior, or is there some other way of controlling which columns trigger selection? I have a CellTable with several button columns and several text columns, and I want to disable selection on some of them.
The code below creates a CellTable with to columns. When you click on one of the columns an alert-box pops up, and when you click other the nothing pops up, but the row looks like it's being selected.
CellTable<MyProxy> cellTable = new CellTable<MyProxy>(50);
final NoSelectionModel<MyProxy> selectionModel = new NoSelectionModel<MyProxy>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
Object selected = selectionModel.getLastSelectedObject();
if (selected != null) {
Window.alert("Selected something");
}
}
});
CellPreviewEvent.Handler<MyProxy> selectionEventManager = new CellPreviewEvent.Handler<MyProxy>() {
@Override
public void onCellPreview(CellPreviewEvent<MyProxy> event) {
if (event.getColumn() == 0) {
event.setCanceled(true);
}
else {
// Handle default selection.
NativeEvent nativeEvent = event.getNativeEvent();
String type = nativeEvent.getType();
if ("click".equals(type)) {
if (nativeEvent.getCtrlKey() || nativeEvent.getMetaKey()) {
// Toggle selection on ctrl+click.
selectionModel.setSelected(event.getValue(), !selectionModel.isSelected(event.getValue()));
}
else {
// Select on click.
selectionModel.setSelected(event.getValue(), true);
}
}
else if ("keyup".equals(type)) {
// Toggle selection on space.
int keyCode = nativeEvent.getKeyCode();
if (keyCode == 32) {
selectionModel.setSelected(event.getValue(), !selectionModel.isSelected(event.getValue()));
}
}
}
}
};
cellTable.addColumn(new TextColumn<MyProxy>() {
@Override
public String getValue(MyProxy object) {
return object.getTitle();
}
});
cellTable.addColumn(new TextColumn<MyProxy>() {
@Override
public String getValue(MyProxy object) {
return object.getId();
}
});
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment