protected void addGroupCell(String text) { // String only content is optimized by not using Label widget Element tdElement = DOM.createTD(); final TableCellElement td = tdElement.cast(); initCellWithText(text, ALIGN_LEFT, "", false, true, null, td); // Enchance DOM for table cell Element container = (Element) td.getChild(0); String containerInnerHTML = container.getInnerHTML(); container.setInnerHTML(""); expander = DOM.createDiv(); expander.setInnerHTML(" "); expander.setClassName(CLASSNAME + "-group-cell-expander"); DOM.appendChild(container, expander); Element contentDiv = DOM.createDiv(); contentDiv.setInnerHTML(containerInnerHTML); contentDiv.setClassName(CLASSNAME + "-float"); DOM.appendChild(container, contentDiv); }
@Override protected void initCellWithText(String text, char align, String style, boolean textIsHTML, boolean sorted, String description, TableCellElement td) { super.initCellWithText(text, align, style, textIsHTML, sorted, description, td); Element tdElement = td.cast(); Tools.textSelectionEnable(tdElement, _delegate.textSelectionEnabled); if (_delegate.clickableColumns != null && _delegate.clickableColumns.contains(currentColumnKey)) { Element wrapperElement = tdElement.getFirstChildElement(); final Element clickableSpan = DOM.createSpan().cast(); clickableSpan.setClassName(CUBA_TABLE_CLICKABLE_CELL_STYLE); clickableSpan.setInnerText(wrapperElement.getInnerText()); wrapperElement.removeAllChildren(); DOM.appendChild(wrapperElement, clickableSpan); } if (_delegate.multiLineCells) { Style wrapperStyle = tdElement.getFirstChildElement().getStyle(); wrapperStyle.setWhiteSpace(Style.WhiteSpace.PRE_LINE); } }
@Override protected void initCellWithText(String text, char align, String style, boolean textIsHTML, boolean sorted, String description, TableCellElement td) { super.initCellWithText(text, align, style, textIsHTML, sorted, description, td); final Element tdElement = td.cast(); Tools.textSelectionEnable(tdElement, _delegate.textSelectionEnabled); if (_delegate.clickableColumns != null && _delegate.clickableColumns.contains(currentColumnKey)) { Element wrapperElement = tdElement.getFirstChildElement(); final Element clickableSpan = DOM.createSpan().cast(); clickableSpan.setClassName(CUBA_TABLE_CLICKABLE_CELL_STYLE); clickableSpan.setInnerText(wrapperElement.getInnerText()); wrapperElement.removeAllChildren(); DOM.appendChild(wrapperElement, clickableSpan); } if (_delegate.multiLineCells) { Style wrapperStyle = tdElement.getFirstChildElement().getStyle(); wrapperStyle.setWhiteSpace(Style.WhiteSpace.PRE_LINE); } }
/** * Fills the main grid data */ protected void populateDialog(){ addNewGrid( 1, false, "", false); //Set the login label final TableCellElement loginLabelCell = (TableCellElement) Document.get().getElementById(LOGIN_LABEL_CELL_ID); Label loginField = InterfaceUtils.getNewFieldLabel( titlesI18N.loginNameField(), true ); loginLabelCell.setInnerHTML( loginField.toString() ); //Set the password label final TableCellElement passwordLabelCell = (TableCellElement) Document.get().getElementById(PASSWORD_LABEL_CELL_ID); Label passwordField = InterfaceUtils.getNewFieldLabel( titlesI18N.passwordField(), true ); passwordLabelCell.setInnerHTML( passwordField.toString() ); //Set the progress bar element final TableCellElement progressBarCell = (TableCellElement) Document.get().getElementById(PROGRESS_BAR_CELL_ID); progressBarCell.appendChild( progressBarUI.getElement() ); addToGrid( FIRST_COLUMN_INDEX, form, false, false ); }
public static void focusFirstEditableElementFromFirstElementOfRow(Grid grid, int rowIndex, GridFocusHandler gridFocusHandler, boolean shiftKeyDown) { NavigationUtil.focusCell(grid, rowIndex, 0, gridFocusHandler); TableCellElement element = NavigationUtil.getFocusedCell(grid) .getElement(); if (element == null) { return; } if (hasInputElement(element, shiftKeyDown)) { return; } int counter = getNextInputElementCounter(element, shiftKeyDown); if (counter > 0) { NavigationUtil.focusCell(grid, rowIndex, counter, gridFocusHandler); } else if (counter == -1) { focusFirstEditableElementFromFirstElementOfRow(grid, rowIndex + 1, gridFocusHandler, shiftKeyDown); } }
public static void focusLastEditableElementFromFirstElementOfRow(Grid grid, int rowIndex, GridFocusHandler gridFocusHandler, boolean shiftKeyDown) { gridFocusHandler.setShiftKeyDown(true); NavigationUtil.focusCell(grid, rowIndex, grid.getColumnCount() - 1, gridFocusHandler); TableCellElement element = NavigationUtil.getFocusedCell(grid) .getElement(); if (element == null) { return; } if (hasInputElement(element, shiftKeyDown)) { return; } int counter = getPreviousInputElementCounter(element, shiftKeyDown); if (counter > 0) { NavigationUtil.focusCell(grid, rowIndex, (grid.getColumnCount() - 1) - counter, gridFocusHandler); } else if (counter == -1) { focusLastEditableElementFromFirstElementOfRow(grid, rowIndex - 1, gridFocusHandler, shiftKeyDown); } }
public TableCellElement getViewCell(int aRow, int aCol) { GridSection<T> targetSection; if (aRow < frozenRows) { if (aCol < frozenColumns) { targetSection = frozenLeft; } else { aCol -= frozenColumns; targetSection = frozenRight; } } else { aRow -= frozenRows; if (aCol < frozenColumns) { targetSection = scrollableLeft; } else { aCol -= frozenColumns; targetSection = scrollableRight; } } return targetSection.getCell(aRow, aCol); }
@Override protected boolean resetFocusOnCell() { boolean focused = false; if (hasFilterHeaders() && filterFocusedCellColumn > -1 && filterFocusedCellRow > -1) { TableSectionElement thead = getTableHeadElement(); NodeList<TableRowElement> rows = thead.getRows(); if (filterFocusedCellRow < rows.getLength()) { TableRowElement row = rows.getItem(filterFocusedCellRow); NodeList<TableCellElement> cells = row.getCells(); if (filterFocusedCellColumn < cells.getLength()) { TableCellElement cell = cells.getItem(filterFocusedCellColumn); if (getHeaderBuilder().isHeader(cell)) { Header<?> header = getHeaderBuilder().getHeader(cell); Context context = new Context(0, 0, header.getKey()); focused = resetFocusOnFilterCellImpl(context, header, cell); } } } } if (!focused) { focused = super.resetFocusOnCell(); } return focused; }
private void ensureEnoughCells( int nb ) { if( cells.size() >= nb ) return; for( int i = cells.size(); i < nb; i++ ) { if( tr.getChildCount() < i + 1 ) { TableCellElement td = Document.get().createTDElement(); tr.appendChild( td ); } CellImpl cell = i == 0 ? new TreeCellImpl() : new CellImpl(); cells.add( cell ); } }
private void ensureTdOk() { TableCellElement td = getTd(); if( td == null ) return; int count = td.getChildCount(); if( count <= 0 ) { SpanElement treeView = Document.get().createSpanElement(); td.appendChild( treeView ); DOM.sinkEvents( treeView, Event.ONCLICK ); DOM.setEventListener( treeView, this ); } if( count <= 1 ) { SpanElement content = Document.get().createSpanElement(); td.appendChild( content ); } }
@Override public void setWidget( Widget widget ) { clearCellWidget(); TableCellElement td = getTd(); if( td != null ) { td.setInnerText( "" ); childWidget = widget; if( childWidget != null ) { customPanel.addIn( td, childWidget ); } } }
TDSelecter() { super(TableCellElement.TAG_TD); if (TableSelecter.this.singleSelection) { this.inputElem = InputElement.as(DOM.createInputRadio(TableSelecter.this.groupId)); } else { this.inputElem = InputElement.as(DOM.createInputCheck()); } this.getElement().appendChild(this.inputElem); }
@Override protected ResizerInformation getResizerInformation( int mx ) { boolean isPrimed = false; ResizerInformation resizerInfo = new ResizerInformation(); for ( int iCol = 0; iCol < widget.headerRows[ 0 ].getChildCount(); iCol++ ) { TableCellElement tce = widget.headerRows[ 0 ].getChild( iCol ).<TableCellElement>cast(); int cx = tce.getAbsoluteRight(); if ( Math.abs( mx - cx ) <= 5 ) { isPrimed = true; resizerInfo.setResizePrimed( isPrimed ); resizerInfo.setResizeColumn( widget.headerColumns.get( iCol ) ); resizerInfo.setResizeColumnLeft( tce.getAbsoluteLeft() ); break; } } if ( isPrimed ) { setCursorType( Cursor.COL_RESIZE ); } else { setCursorType( Cursor.DEFAULT ); } return resizerInfo; }
private TableRowElement populateTableRowElement( TableRowElement tre, DynamicDataRow rowData ) { tre.getStyle().setHeight( resources.rowHeight(), Unit.PX ); for ( int iCol = 0; iCol < columns.size(); iCol++ ) { DynamicColumn<T> column = columns.get( iCol ); if ( column.isVisible() ) { TableCellElement tce = makeTableCellElement( iCol, rowData ); if ( tce != null ) { tre.appendChild( tce ); } } } return tre; }
@Override void hideColumn( int index ) { if ( index < 0 ) { throw new IllegalArgumentException( "index cannot be less than zero" ); } if ( index > columns.size() ) { throw new IllegalArgumentException( "index cannot be greater than the number of rows" ); } for ( int iRow = 0; iRow < data.size(); iRow++ ) { DynamicDataRow rowData = data.get( iRow ); CellValue<? extends Comparable<?>> cell = rowData.get( index ); if ( cell.getRowSpan() > 0 ) { Coordinate hc = cell.getHtmlCoordinate(); TableRowElement tre = tbody.getRows().getItem( hc.getRow() ); TableCellElement tce = tre.getCells().getItem( hc.getCol() ); tre.removeChild( tce ); } } }
@Override void selectCell( CellValue<? extends Comparable<?>> cell ) { if ( cell == null ) { throw new IllegalArgumentException( "cell cannot be null" ); } Coordinate hc = cell.getHtmlCoordinate(); TableRowElement tre = tbody.getRows().getItem( hc.getRow() ) .<TableRowElement>cast(); TableCellElement tce = tre.getCells().getItem( hc.getCol() ) .<TableCellElement>cast(); //Cell selected style takes precedence String cellSelectedStyle = resources.cellTableCellSelected(); String cellOtherwiseStyle = resources.cellTableCellOtherwise(); String cellMultipleValuesStyle = resources.cellTableCellMultipleValues(); tce.removeClassName( cellMultipleValuesStyle ); tce.removeClassName( cellOtherwiseStyle ); tce.addClassName( cellSelectedStyle ); tce.focus(); }
@Override void showColumn( int index ) { if ( index < 0 ) { throw new IllegalArgumentException( "index cannot be less than zero" ); } if ( index > columns.size() ) { throw new IllegalArgumentException( "index cannot be greater than the number of rows" ); } for ( int iRow = 0; iRow < data.size(); iRow++ ) { DynamicDataRow rowData = data.get( iRow ); TableCellElement tce = makeTableCellElement( index, rowData ); if ( tce != null ) { CellValue<? extends Comparable<?>> cell = rowData.get( index ); Coordinate hc = cell.getHtmlCoordinate(); TableRowElement tre = tbody.getRows().getItem( hc.getRow() ); TableCellElement ntce = tre.insertCell( hc.getCol() ); tre.replaceChild( tce, ntce ); } } }
/** * Retrieve the extents of a cell * @param cv The cell for which to retrieve the extents * @return */ CellSelectionDetail getSelectedCellExtents( CellValue<? extends Comparable<?>> cv ) { if ( cv == null ) { throw new IllegalArgumentException( "cv cannot be null" ); } // Cells in hidden columns do not have extents if ( !columns.get( cv.getCoordinate().getCol() ).isVisible() ) { return null; } Coordinate hc = cv.getHtmlCoordinate(); TableRowElement tre = tbody.getRows().getItem( hc.getRow() ).<TableRowElement>cast(); TableCellElement tce = tre.getCells().getItem( hc.getCol() ).<TableCellElement>cast(); int offsetX = tce.getOffsetLeft(); int offsetY = tce.getOffsetTop(); int w = tce.getOffsetWidth(); int h = tce.getOffsetHeight(); CellSelectionDetail e = new CellSelectionDetail( cv.getCoordinate(), offsetX, offsetY, h, w ); return e; }
private void displayQuireItem(com.google.gwt.dom.client.Document htmldoc, TableElement table, Element item) { TableRowElement tr = table.insertRow(-1); TableCellElement td1 = tr.insertCell(-1); TableCellElement td2 = tr.insertCell(-1); TableCellElement td3 = tr.insertCell(-1); td1.setInnerText(item.getAttribute("n")); NodeList l = item.getElementsByTagName("locus"); if (l.getLength() > 0) { Element locus = (Element) l.item(0); td2.appendChild(displayLocus(htmldoc, locus)); for (Node n = locus.getNextSibling(); n != null; n = n .getNextSibling()) { td3.appendChild(displayDescription(htmldoc, n)); } } }
@Inject public ResultCellTable(final @Assisted int pageSize, final @NotNull CellTableResourcesQueryResults cellTableResources, final @NotNull SqlRequestLauncherConstants constants) { super(pageSize, cellTableResources); final InlineLabel emptyWidget = new InlineLabel(constants.emptyResult()); setEmptyTableWidget(emptyWidget); emptyWidget.setStyleName(cellTableResources.cellTableStyle().emptyTableWidget()); addCellPreviewHandler(new CellPreviewEvent.Handler<List<String>>() { @Override public void onCellPreview(CellPreviewEvent<List<String>> event) { if ("click".equals(event.getNativeEvent().getType())) { TableCellElement cellElement = getRowElement(event.getIndex()).getCells().getItem(event.getColumn()); cellElement.setTitle(cellElement.getInnerText()); } } }); }
public void addDividerCell(char align) { // String only content is optimized by not using Label widget final TableCellElement td = DOM.createTD().cast(); this.groupDividerCell = td; initCellWithText("", align, "", false, false, null, td); td.addClassName(CLASSNAME + "-group-divider"); }
@Override protected void initCellWithWidget(Widget w, char align, String style, boolean sorted, TableCellElement td) { super.initCellWithWidget(w, align, style, sorted, td); td.getFirstChildElement().addClassName(WIDGET_CELL_CLASSNAME); if (CubaTreeTableWidget.this.isSelectable()) { // Support for #PL-2080 recursiveAddFocusHandler(w, w); } }
@Override protected void updateCellStyleNames(TableCellElement td, String primaryStyleName) { Element container = td.getFirstChild().cast(); boolean isWidget = container.getClassName() != null && container.getClassName().contains(WIDGET_CELL_CLASSNAME); super.updateCellStyleNames(td, primaryStyleName); if (isWidget) { container.addClassName(WIDGET_CELL_CLASSNAME); } }
@Override protected void initCellWithWidget(final Widget w, char align, String style, boolean sorted, TableCellElement td) { super.initCellWithWidget(w, align, style, sorted, td); td.getFirstChildElement().addClassName(WIDGET_CELL_CLASSNAME); if (CubaScrollTableWidget.this.isSelectable()) { // Support for #PL-2080 recursiveAddFocusHandler(w, w); } }
/** * Loops through columns and calls {@code setTableCell} for each. */ @Override public void setViewData(TableRowView view, T item) { NodeList<TableCellElement> cells = view.getRootElement().getCells(); for (int i = 0; i < columns; i++) { setTableCell(i, cells.getItem(i), item); } }
/** * Default implementation that populates the table cells with a return value of {@link #getCellContent(int, Object)}. * Override this method if you need to perform more complex operation on a table cell. * @param column The column index of the table cell (0-based) * @param elem The DOM element of the table cell * @param item The item for this row */ protected void setTableCell(int column, TableCellElement elem, T item) { Object content = getCellContent(column, item); if (content instanceof SafeHtml) { elem.setInnerSafeHtml((SafeHtml) content); } else { elem.setInnerText(content != null ? content.toString() : ""); } }
private static NodeList<TableCellElement> getMaxColsAmongRows(NodeList<TableRowElement> rows) { NodeList<TableCellElement> cols = null; int maxCols = 0; for (int i = 0; i < rows.getLength(); i++) { NodeList<TableCellElement> currCols = rows.getItem(i).getCells(); if (currCols.getLength() > maxCols) { maxCols = currCols.getLength(); cols = currCols; } } return cols; }
private void appendRow(String title, JsArrayString l) { TableRowElement row = table.insertRow(-1); TableCellElement th = Document.get().createTHElement(); th.setInnerText(title); row.appendChild(th); row.insertCell(-1).setInnerSafeHtml(formatList(l)); }
private void selectCell(int aRow, int aCol) { List<JavaScriptObject> data = grid.getDataProvider().getList(); if (grid.getSelectionModel() instanceof SetSelectionModel) { SetSelectionModel<JavaScriptObject> ssm = (SetSelectionModel<JavaScriptObject>) grid.getSelectionModel(); ssm.clear(); ssm.setSelected(data.get(aRow), true); } TableCellElement cell = grid.getViewCell(aRow, aCol); if (cell != null) { cell.scrollIntoView(); //grid.focusViewCell(aRow, aCol);// this call leads to cell editing in subsequent enter hit } }
public TableCellElement getCell(int aRow, int aCol) { NodeList<TableRowElement> rows = getTableBodyElement().getRows(); if (aRow >= 0 && aRow < rows.getLength()) { TableRowElement row = rows.getItem(aRow); NodeList<TableCellElement> cells = row.getCells(); if (aCol >= 0 && aCol < cells.getLength()) { return cells.getItem(aCol); } } return null; }
public <C> void redrawAllRowsInColumn(int aIndex, ListDataProvider<T> aDataProvider) { if (aIndex >= 0 && aIndex < getColumnCount()) { int start = getVisibleRange().getStart(); Column<T, C> column = (Column<T, C>) getColumn(aIndex); Cell<C> cell = column.getCell(); List<T> data = aDataProvider.getList(); ProvidesKey<T> keys = getKeyProvider(); NodeList<TableRowElement> rows = getTableBodyElement().getRows(); for (int i = 0; i < rows.getLength(); i++) { TableRowElement row = rows.getItem(i); NodeList<TableCellElement> cells = row.getCells(); if (aIndex >= 0 && aIndex < cells.getLength()) { TableCellElement toRerender = cells.getItem(aIndex); if (toRerender != null) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); int dataIdx = start + i; if (dataIdx >= 0 && dataIdx < data.size()) { T object = data.get(dataIdx); Cell.Context cx = new Cell.Context(start + i, aIndex, keys.getKey(object)); cell.render(cx, column.getValue(object), sb); // Take into account, that cell builder supports // some // maps // to cells' divs // and generates them. So we have to work with first // <div> // in <td>. toRerender.getFirstChildElement().setInnerSafeHtml(sb.toSafeHtml()); } } } } } }
/** * Given a click event, return the Cell that was clicked, or null if the event * did not hit this table. The cell can also be null if the click event does * not occur on a specific cell. * * @param event A click event of indeterminate origin * @return The appropriate cell, or null */ public Cell getCellForEvent(MouseEvent<? extends EventHandler> event) { Element td = getEventTargetCell(Event.as(event.getNativeEvent())); if (td == null) { return null; } int row = TableRowElement.as(td.getParentElement()).getSectionRowIndex(); int column = TableCellElement.as(td).getCellIndex(); return new Cell(row, column); }
/** * Get the TD element * * @param root * @param column * @param row * @return */ public static TableCellElement getCell( Element root, int column, int row ) { TableSectionElement tbody = getTBodyElement( root ); TableRowElement tr = tbody.getChild( row ).cast(); TableCellElement td = tr.getChild( column ).cast(); return td; }
public int addColumn( String html, String width ) { headTableColgroup.appendChild( createColumnElement( width ) ); tableColgroup.appendChild( createColumnElement( width ) ); TableCellElement th = Document.get().createTHElement(); th.setInnerHTML( html ); thead.appendChild( th ); int index = getNbColumns() - 1; return index; }
/** * Does both the logical and physical attachment of the child row * * @param child * The row to be added at the end of the children collection */ private void insertLastChild( RowImpl child ) { assert (child != null); child.detach(); // do the DOM attach RowImpl lastChildRow = getLastChildDeep(); tbody.insertAfter( child.tr, lastChildRow.tr ); // do the logical attach (to the child list) child.parent = this; getChildren().add( child ); // ensure child's descendants are at a good place class ReplacingVisitor implements Action1<DataTable.RowImpl> { private Element previousTr = null; @Override public void exec( RowImpl row ) { TableCellElement td = row.tr.getChild( 0 ).cast(); td.getStyle().setPaddingLeft( 10 * row.getLevel(), Unit.PX ); if( previousTr == null ) { previousTr = row.tr; return; } tbody.insertAfter( row.tr, previousTr ); previousTr = row.tr; } } child.browseDeep( new ReplacingVisitor() ); }
@Override public TableCellElement getTd() { TableRowElement tr = getTr(); if( tr == null ) return null; return tr.getChild( getCellIndex() ).cast(); }
@Override public void setText( String text ) { clearCellWidget(); TableCellElement td = getTd(); if( td != null ) td.setInnerText( text ); }
@Override public void setHTML( String html ) { clearCellWidget(); TableCellElement td = getTd(); if( td != null ) td.setInnerHTML( html ); }
@Override public void scrollIntoView() { TableCellElement td = getTd(); if( td != null ) td.scrollIntoView(); }