List of usage examples for com.google.gwt.dom.client TableRowElement getSectionRowIndex
public int getSectionRowIndex()
From source file:com.google.gwt.sample.contacts.client.view.ContactsViewImpl.java
@UiHandler("contactsTable") void onTableClicked(ClickEvent event) { if (presenter != null) { EventTarget target = event.getNativeEvent().getEventTarget(); Node node = Node.as(target); TableCellElement cell = findNearestParentCell(node); if (cell == null) { return; }/* w w w .java 2 s . c o m*/ TableRowElement tr = TableRowElement.as(cell.getParentElement()); int row = tr.getSectionRowIndex(); if (cell != null) { if (shouldFireClickEvent(cell)) { presenter.onItemClicked(rowData.get(row)); } if (shouldFireSelectEvent(cell)) { presenter.onItemSelected(rowData.get(row)); } } } }
From source file:gwt.material.design.client.ui.table.AbstractDataTable.java
License:Apache License
/** * Get the index of the row value from the associated {@link TableRowElement}. * * @param row the row element/*from w w w . j av a 2 s. c o m*/ * @return the row value index */ public final int getRowValueIndex(TableRowElement row) { return row.getSectionRowIndex() + getView().getVisibleRange().getStart(); }
From source file:no.eirikb.bomberman.client.view.GameListViewImpl.java
License:BEER-WARE LICENSE
@UiHandler("gameListTable") void onTableClicked(ClickEvent event) { if (presenter != null) { EventTarget target = event.getNativeEvent().getEventTarget(); Node node = Node.as(target); TableCellElement cell = findNearestParentCell(node); if (cell == null) { return; }/*from w w w. j av a 2s .c o m*/ TableRowElement tr = TableRowElement.as(cell.getParentElement()); int row = tr.getSectionRowIndex(); if (cell != null) { if (shouldFireClickEvent(cell)) { if (row < rowData.size()) { presenter.onItemClicked(rowData.get(row)); } } } } }
From source file:org.drools.guvnor.client.widgets.decoratedgrid.VerticalMergableGridWidget.java
License:Apache License
@Override public void onBrowserEvent(Event event) { String eventType = event.getType(); // Get the event target EventTarget eventTarget = event.getEventTarget(); if (!Element.is(eventTarget)) { return;//ww w .j a v a 2s.co m } Element target = event.getEventTarget().cast(); //Check whether "group" widget has been clicked boolean bGroupWidgetClick = isGroupWidgetClicked(event, target); // Find the cell where the event occurred. TableCellElement eventTableCell = findNearestParentCell(target); if (eventTableCell == null) { return; } int htmlCol = eventTableCell.getCellIndex(); Element trElem = eventTableCell.getParentElement(); if (trElem == null) { return; } TableRowElement tr = TableRowElement.as(trElem); int htmlRow = tr.getSectionRowIndex(); // Convert HTML coordinates to physical coordinates CellValue<?> htmlCell = data.get(htmlRow).get(htmlCol); Coordinate eventPhysicalCoordinate = htmlCell.getPhysicalCoordinate(); CellValue<?> eventPhysicalCell = data.get(eventPhysicalCoordinate.getRow()) .get(eventPhysicalCoordinate.getCol()); //Event handlers if (eventType.equals("mousedown")) { handleMousedownEvent(event, eventPhysicalCoordinate, bGroupWidgetClick); return; } else if (eventType.equals("mousemove")) { handleMousemoveEvent(event, eventPhysicalCoordinate); return; } else if (eventType.equals("mouseup")) { handleMouseupEvent(event, eventPhysicalCoordinate); return; } else if (eventType.equals("keydown")) { handleKeyboardNavigationEvent(event); if (event.getKeyCode() == KeyCodes.KEY_ENTER) { // Enter key is a special case; as the selected cell needs to be // sent events and not the cell that GWT deemed the target for // events. switch (rangeDirection) { case UP: eventPhysicalCell = selections.first(); break; case DOWN: eventPhysicalCell = selections.last(); break; } eventPhysicalCoordinate = eventPhysicalCell.getCoordinate(); eventTableCell = tbody.getRows().getItem(eventPhysicalCell.getHtmlCoordinate().getRow()).getCells() .getItem(eventPhysicalCell.getHtmlCoordinate().getCol()); } } // Pass event and physical cell to Cell Widget for handling Cell<CellValue<? extends Comparable<?>>> cellWidget = columns.get(eventPhysicalCoordinate.getCol()) .getCell(); // Implementations of AbstractCell aren't forced to initialise consumed events Set<String> consumedEvents = cellWidget.getConsumedEvents(); if (consumedEvents != null && consumedEvents.contains(eventType)) { Context context = new Context(eventPhysicalCoordinate.getRow(), eventPhysicalCoordinate.getCol(), eventPhysicalCoordinate); //The element containing the cell's HTML is nested inside two DIVs Element parent = eventTableCell.getFirstChildElement().getFirstChildElement(); cellWidget.onBrowserEvent(context, parent, eventPhysicalCell, event, null); } }
From source file:org.jboss.ballroom.client.widgets.tables.TableUtils.java
License:Open Source License
/** * Borrowed from CellTable#onBrowserEvent2(Event event) * * @param target//from ww w .j av a 2 s .co m * @return */ public static int identifyRow(Element target) { // Find the cell where the event occurred. TableCellElement tableCell = findNearestParentCell(target); if (tableCell == null) { return -1; } // Determine if we are in the header, footer, or body. Its possible that // the table has been refreshed before the current event fired (ex. change // event refreshes before mouseup fires), so we need to check each parent // element. Element trElem = tableCell.getParentElement(); if (trElem == null) { return -1; } TableRowElement tr = TableRowElement.as(trElem); Element sectionElem = tr.getParentElement(); if (sectionElem == null) { return -1; } int row = tr.getSectionRowIndex(); return row; }
From source file:org.rstudio.core.client.widget.MultiSelectCellTable.java
License:Open Source License
private void handleContextMenu(ContextMenuEvent cmEvent) { // bail if there are no context menu handlers if (handlerManager_.getHandlerCount(ContextMenuEvent.getType()) == 0) return;/*from w w w . j av a2 s.com*/ // 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_); }