List of usage examples for com.google.gwt.cell.client Cell onBrowserEvent
void onBrowserEvent(Context context, Element parent, C value, NativeEvent event, ValueUpdater<C> valueUpdater);
From source file:com.sencha.gxt.widget.core.client.grid.Grid.java
License:sencha.com license
/** * Fires an event to the cell specified by the given record data model and * column./* w ww .j a va2s . com*/ * * @param event the event to fire * @param eventType the type of event * @param cellParent the containing parent element * @param m the record data model containing the cell * @param context the context of the cell (row, column and key) * @param column the column containing the cell */ protected <N> Cell<?> fireEventToCell(Event event, String eventType, Element cellParent, final M m, Context context, final ColumnConfig<M, N> column) { Cell<N> cell = column.getCell(); if (cell != null && cellConsumesEventType(cell, eventType)) { N cellValue = null; if (store.hasRecord(m)) { cellValue = store.getRecord(m).getValue(column.getValueProvider()); } else { cellValue = column.getValueProvider().getValue(m); } cell.onBrowserEvent(context, cellParent, cellValue, event, new ValueUpdater<N>() { @Override public void update(N value) { Grid.this.getStore().getRecord(m).addChange(column.getValueProvider(), value); } }); return cell; } return null; }
From source file:gwt.material.design.client.ui.table.AbstractDataTable.java
License:Apache License
/** * Fire an event to the Cell within the specified {@link TableCellElement}. *///from w w w . j av a 2 s .c om private <C> void fireEventToCell(Event event, String eventType, Element parentElem, final T rowValue, Context context, HasCell<T, C> column) { // Check if the cell consumes the event. Cell<C> cell = column.getCell(); if (!cellConsumesEventType(cell, eventType)) { return; } C cellValue = column.getValue(rowValue); boolean cellWasEditing = cell.isEditing(context, parentElem, cellValue); if (column instanceof Column) { /* * If the HasCell is a Column, let it handle the event itself. This is * here for legacy support. */ Column<T, C> col = (Column<T, C>) column; col.onBrowserEvent(context, parentElem, rowValue, event); } else { // Create a FieldUpdater. final FieldUpdater<T, C> fieldUpdater = column.getFieldUpdater(); final int index = context.getIndex(); ValueUpdater<C> valueUpdater = (fieldUpdater == null) ? null : (value) -> { fieldUpdater.update(index, rowValue, value); }; // Fire the event to the cell. cell.onBrowserEvent(context, parentElem, cellValue, event, valueUpdater); } // Reset focus if needed. cellIsEditing = cell.isEditing(context, parentElem, cellValue); if (cellWasEditing && !cellIsEditing) { CellBasedWidgetImpl.get().resetFocus(() -> { setFocus(true); }); } }
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;// www .j a v a 2 s . 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); } }