Search in sources :

Example 1 with TableSectionElement

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_);
}
Also used : TableSectionElement(com.google.gwt.dom.client.TableSectionElement) TableRowElement(com.google.gwt.dom.client.TableRowElement) TableCellElement(com.google.gwt.dom.client.TableCellElement) TableSectionElement(com.google.gwt.dom.client.TableSectionElement) TableRowElement(com.google.gwt.dom.client.TableRowElement) TableElement(com.google.gwt.dom.client.TableElement) Element(com.google.gwt.dom.client.Element) EventTarget(com.google.gwt.dom.client.EventTarget) TableCellElement(com.google.gwt.dom.client.TableCellElement) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

Element (com.google.gwt.dom.client.Element)1 EventTarget (com.google.gwt.dom.client.EventTarget)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 TableCellElement (com.google.gwt.dom.client.TableCellElement)1 TableElement (com.google.gwt.dom.client.TableElement)1 TableRowElement (com.google.gwt.dom.client.TableRowElement)1 TableSectionElement (com.google.gwt.dom.client.TableSectionElement)1