use of com.google.gwt.dom.client.TableSectionElement in project rstudio by rstudio.
the class MultiSelectCellTable method handleContextMenu.
// handle context-menu clicks. this implementation (specifically the
// detection of table rows from dom events) is based on the code in
// AbstractCellTable.onBrowserEvent2. we first determine if the click
// applies to a row in the table -- if it does then we squelch the
// standard handling of the event and update the selection and then
// forward the event on to any external listeners
private void handleContextMenu(ContextMenuEvent cmEvent) {
// bail if there are no context menu handlers
if (handlerManager_.getHandlerCount(ContextMenuEvent.getType()) == 0)
return;
// Get the event target.
NativeEvent event = cmEvent.getNativeEvent();
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget))
return;
final Element target = event.getEventTarget().cast();
// always squelch default handling (when there is a handler)
event.stopPropagation();
event.preventDefault();
// find the table cell element then get its parent and cast to row
TableCellElement tableCell = findNearestParentCell(target);
if (tableCell == null)
return;
Element trElem = tableCell.getParentElement();
if (trElem == null)
return;
TableRowElement tr = TableRowElement.as(trElem);
// get the section of the row and confirm it is a tbody (as opposed
// to a thead or tfoot)
Element sectionElem = tr.getParentElement();
if (sectionElem == null)
return;
TableSectionElement section = TableSectionElement.as(sectionElem);
if (section != getTableBodyElement())
return;
// determine the row/item target
int row = tr.getSectionRowIndex();
T item = getVisibleItem(row);
// if this row isn't already selected then clear the existing selection
if (!getSelectionModel().isSelected(item))
clearSelection();
// select the clicked on item
getSelectionModel().setSelected(item, true);
// forward the event
DomEvent.fireNativeEvent(event, handlerManager_);
}
Aggregations