Showing posts with label gwt. Show all posts
Showing posts with label gwt. Show all posts

Friday, May 22, 2009

GWT disable text selection in an HTMLTable

While modifying FlexTable to handle cell selection It took me a while to figure out how to disable the native text selection behavior of the browsers on 'SHIFT+Click' events. Turns out this native javascript function does the job pretty well. I tried playing with event.preventDefault() and event.stopPropagation() but that didn't work.

private native static void disableTextSelectInternal(Element e, boolean disable)/*-{
if (disable) {
e.ondrag = function () { return false; };
e.onselectstart = function () { return false; };
e.style.MozUserSelect="none"
} else {
e.ondrag = null;
e.onselectstart = null;
e.style.MozUserSelect="text"
}
}-*/;

@Override
public void onKeyDown(KeyDownEvent event) {
if (event.isShiftKeyDown()) {
disableTextSelectInternal(table.getElement(), true);
}
...