/* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.google.gwt.core.shared.GWT; import com.google.gwt.user.client.ui.Button; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * A Renderer that displays buttons with textual captions. The values of the * corresponding column are used as the captions. Click handlers can be added to * the renderer, invoked when any of the rendered buttons is clicked. * * @since 7.4 * @author Vaadin Ltd */ public class ButtonRenderer extends ClickableRenderer { @Override public Button createWidget() { Button b = GWT.create(Button.class); b.addClickHandler(this); b.setStylePrimaryName("v-nativebutton"); return b; } @Override public void render(RendererCellReference cell, String text, Button button) { button.setText(text); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 7838 Content-Disposition: inline; filename="ClickableRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "6aa5b9ca40098a9b458aef97592a866f3fdcb668" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.google.gwt.dom.client.BrowserEvents; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.DomEvent; import com.google.gwt.event.dom.client.MouseEvent; import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.client.WidgetUtil; import com.vaadin.v7.client.widget.escalator.Cell; import com.vaadin.v7.client.widget.escalator.RowContainer; import com.vaadin.v7.client.widget.grid.CellReference; import com.vaadin.v7.client.widget.grid.EventCellReference; import com.vaadin.v7.client.widgets.Escalator; import com.vaadin.v7.client.widgets.Grid; import com.vaadin.v7.shared.ui.grid.GridConstants.Section; /** * An abstract superclass for renderers that render clickable widgets. Click * handlers can be added to a renderer to listen to click events emitted by all * widgets rendered by the renderer. * * @param * the presentation (column) type * @param * the widget type * * @since 7.4 * @author Vaadin Ltd */ public abstract class ClickableRenderer extends WidgetRenderer implements ClickHandler { /** * A handler for {@link RendererClickEvent renderer click events}. * * @param * the row type of the containing Grid * * @see ButtonRenderer#addClickHandler(RendererClickHandler) */ public interface RendererClickHandler extends EventHandler { /** * Called when a rendered button is clicked. * * @param event * the event representing the click */ void onClick(RendererClickEvent event); } /** * An event fired when a widget rendered by a ClickableWidgetRenderer * subclass is clicked. * * @param * the row type of the containing Grid */ @SuppressWarnings("rawtypes") public static class RendererClickEvent extends MouseEvent { @SuppressWarnings("unchecked") static final Type TYPE = new Type( BrowserEvents.CLICK, new RendererClickEvent()); private CellReference cell; private R row; private RendererClickEvent() { } /** * Returns the cell of the clicked button. * * @return the cell */ public CellReference getCell() { return cell; } /** * Returns the data object corresponding to the row of the clicked * button. * * @return the row data object */ public R getRow() { return row; } @Override public Type getAssociatedType() { return TYPE; } @Override @SuppressWarnings("unchecked") protected void dispatch(RendererClickHandler handler) { EventTarget target = getNativeEvent().getEventTarget(); if (!Element.is(target)) { return; } Element e = Element.as(target); Grid grid = (Grid) findClosestParentGrid(e); cell = findCell(grid, e); row = cell.getRow(); handler.onClick(this); } /** * Returns the cell the given element belongs to. * * @param grid * the grid instance that is queried * @param e * a cell element or the descendant of one * @return the cell or null if the element is not a grid cell or a * descendant of one */ private static CellReference findCell(Grid grid, Element e) { RowContainer container = getEscalator(grid).findRowContainer(e); if (container == null) { return null; } Cell cell = container.getCell(e); EventCellReference cellReference = new EventCellReference( grid); // FIXME: Section is currently always body. Might be useful for the // future to have an actual check. cellReference.set(cell, Section.BODY); return cellReference; } private static native Escalator getEscalator(Grid grid) /*-{ return grid.@com.vaadin.v7.client.widgets.Grid::escalator; }-*/; /** * Returns the Grid instance containing the given element, if any. *

* Note: This method may not work reliably if the grid * in question is wrapped in a {@link Composite} unless the * element is inside another widget that is a child of the wrapped grid; * please refer to the note in * {@link WidgetUtil#findWidget(Element, Class) Util.findWidget} for * details. * * @param e * the element whose parent grid to find * @return the parent grid or null if none found. */ private static Grid findClosestParentGrid(Element e) { Widget w = WidgetUtil.findWidget(e, null); while (w != null && !(w instanceof Grid)) { w = w.getParent(); } return (Grid) w; } } private HandlerManager handlerManager; /** * {@inheritDoc} *

* Implementation note: It is the implementing method's * responsibility to add {@code this} as a click handler of the returned * widget, or a widget nested therein, in order to make click events * propagate properly to handlers registered via * {@link #addClickHandler(RendererClickHandler) addClickHandler}. */ @Override public abstract W createWidget(); /** * Adds a click handler to this button renderer. The handler is invoked * every time one of the widgets rendered by this renderer is clicked. *

* Note that the row type of the click handler must match the row type of * the containing Grid. * * @param handler * the click handler to be added */ public HandlerRegistration addClickHandler( RendererClickHandler handler) { if (handlerManager == null) { handlerManager = new HandlerManager(this); } return handlerManager.addHandler(RendererClickEvent.TYPE, handler); } @Override public void onClick(ClickEvent event) { /* * The handler manager is lazily instantiated so it's null iff * addClickHandler is never called. */ if (handlerManager != null) { DomEvent.fireNativeEvent(event.getNativeEvent(), handlerManager); } } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 5610 Content-Disposition: inline; filename="ComplexRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "41745e8fdef4d31f5440c09b7d718157df8cc080" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import java.util.Collection; import java.util.Collections; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.Style.Visibility; import com.vaadin.v7.client.widget.escalator.Cell; import com.vaadin.v7.client.widget.escalator.FlyweightCell; import com.vaadin.v7.client.widget.grid.CellReference; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * Base class for renderers that needs initialization and destruction logic * (override {@link #init(FlyweightCell)} and {@link #destroy(FlyweightCell) } * and event handling (see {@link #onBrowserEvent(Cell, NativeEvent)}, * {@link #getConsumedEvents()} and {@link #onActivate()}. * *

* Also provides a helper method for hiding the cell contents by overriding * {@link #setContentVisible(FlyweightCell, boolean)} * * @since 7.4.0 * @author Vaadin Ltd */ public abstract class ComplexRenderer implements Renderer { /** * Called at initialization stage. Perform any initialization here e.g. * attach handlers, attach widgets etc. * * @param cell * The cell. Note that the cell is not to be stored outside of * the method as the cell instance will change. See * {@link FlyweightCell} */ public abstract void init(RendererCellReference cell); /** * Called after the cell is deemed to be destroyed and no longer used by the * Grid. Called after the cell element is detached from the DOM. *

* The row object in the cell reference will be null since the * row might no longer be present in the data source. * * @param cell * The cell. Note that the cell is not to be stored outside of * the method as the cell instance will change. See * {@link FlyweightCell} */ public void destroy(RendererCellReference cell) { // Implement if needed } /** * Returns the events that the renderer should consume. These are also the * events that the Grid will pass to * {@link #onBrowserEvent(Cell, NativeEvent)} when they occur. * * @return a list of consumed events * * @see com.google.gwt.dom.client.BrowserEvents */ public Collection getConsumedEvents() { return Collections.emptyList(); } /** * Called whenever a registered event is triggered in the column the * renderer renders. *

* The events that triggers this needs to be returned by the * {@link #getConsumedEvents()} method. *

* Returns boolean telling if the event has been completely handled and * should not cause any other actions. * * @param cell * Object containing information about the cell the event was * triggered on. * * @param event * The original DOM event * @return true if event should not be handled by grid */ public boolean onBrowserEvent(CellReference cell, NativeEvent event) { return false; } /** * Used by Grid to toggle whether to show actual data or just an empty * placeholder while data is loading. This method is invoked whenever a cell * changes between data being available and data missing. *

* Default implementation hides content by setting visibility: hidden to all * elements inside the cell. Text nodes are left as is - renderers that add * such to the root element need to implement explicit support hiding them. * * @param cell * The cell * @param hasData * Has the cell content been loaded from the data source * */ public void setContentVisible(RendererCellReference cell, boolean hasData) { Element cellElement = cell.getElement(); for (int n = 0; n < cellElement.getChildCount(); n++) { Node node = cellElement.getChild(n); if (Element.is(node)) { Element e = Element.as(node); if (hasData) { e.getStyle().clearVisibility(); } else { e.getStyle().setVisibility(Visibility.HIDDEN); } } } } /** * Called when the cell is activated by pressing enter, double * clicking or performing a double tap on the cell. * * @param cell * the activated cell * @return true if event was handled and should not be * interpreted as a generic gesture by Grid. */ public boolean onActivate(CellReference cell) { return false; } /** * Called when the renderer is deemed to be destroyed and no longer used by * the Grid. */ public void destroy() { // Implement if needed } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 3126 Content-Disposition: inline; filename="DateRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "6be4e435ee2d4c1aabf2012704bfafdd789a54b8" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import java.util.Date; import com.google.gwt.i18n.client.TimeZone; import com.google.gwt.i18n.shared.DateTimeFormat; import com.google.gwt.i18n.shared.DateTimeFormat.PredefinedFormat; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * A renderer for rendering dates into cells. * * @since 7.4 * @author Vaadin Ltd */ public class DateRenderer implements Renderer { private DateTimeFormat format; // Calendar is unavailable for GWT @SuppressWarnings("deprecation") private TimeZone timeZone = TimeZone .createTimeZone(new Date().getTimezoneOffset()); public DateRenderer() { this(PredefinedFormat.DATE_TIME_SHORT); } public DateRenderer(PredefinedFormat format) { this(DateTimeFormat.getFormat(format)); } public DateRenderer(DateTimeFormat format) { setFormat(format); } @Override public void render(RendererCellReference cell, Date date) { String dateStr = format.format(date, timeZone); cell.getElement().setInnerText(dateStr); } /** * Gets the format of how the date is formatted. * * @return the format * @see GWT * documentation on DateTimeFormat */ public DateTimeFormat getFormat() { return format; } /** * Sets the format used for formatting the dates. * * @param format * the format to set * @see GWT * documentation on DateTimeFormat */ public void setFormat(DateTimeFormat format) { if (format == null) { throw new IllegalArgumentException("Format should not be null"); } this.format = format; } /** * Returns the time zone of the date. * * @return the time zone */ public TimeZone getTimeZone() { return timeZone; } /** * Sets the time zone of the the date. By default uses the time zone of the * browser. * * @param timeZone * the timeZone to set */ public void setTimeZone(TimeZone timeZone) { if (timeZone == null) { throw new IllegalArgumentException("Timezone should not be null"); } this.timeZone = timeZone; } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1436 Content-Disposition: inline; filename="HtmlRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "0324ae6d91a0a64e38b98a275f2759e766e85924" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlUtils; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * Renders a string as HTML into a cell. *

* The html string is rendered as is without any escaping. It is up to the * developer to ensure that the html string honors the {@link SafeHtml} * contract. For more information see * {@link SafeHtmlUtils#fromSafeConstant(String)}. * * @since 7.4 * @author Vaadin Ltd * @see SafeHtmlUtils#fromSafeConstant(String) */ public class HtmlRenderer implements Renderer { @Override public void render(RendererCellReference cell, String htmlString) { cell.getElement() .setInnerSafeHtml(SafeHtmlUtils.fromSafeConstant(htmlString)); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1606 Content-Disposition: inline; filename="ImageRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "581f1d9acaebf552ace99fd1cddc9a532a15daad" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Image; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * A renderer that renders an image into a cell. Click handlers can be added to * the renderer, invoked every time any of the images rendered by that rendered * is clicked. * * @since 7.4 * @author Vaadin Ltd */ public class ImageRenderer extends ClickableRenderer { public static final String TRANSPARENT_GIF_1PX = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; @Override public Image createWidget() { Image image = GWT.create(Image.class); image.addClickHandler(this); return image; } @Override public void render(RendererCellReference cell, String url, Image image) { if (url == null) { image.setUrl(TRANSPARENT_GIF_1PX); } else { image.setUrl(url); } } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 2059 Content-Disposition: inline; filename="NumberRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "6f8d92fa17b14d11cee39181794781d8b87d92ee" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.google.gwt.i18n.client.NumberFormat; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * Renders a number into a cell using a specific {@link NumberFormat}. By * default uses the default number format returned by * {@link NumberFormat#getDecimalFormat()}. * * @since 7.4 * @author Vaadin Ltd */ public class NumberRenderer implements Renderer { private NumberFormat format; public NumberRenderer() { this(NumberFormat.getDecimalFormat()); } public NumberRenderer(NumberFormat format) { setFormat(format); } /** * Gets the number format that the number should be formatted in. * * @return the number format used to render the number */ public NumberFormat getFormat() { return format; } /** * Sets the number format to use for formatting the number. * * @param format * the format to use * @throws IllegalArgumentException * when the format is null */ public void setFormat(NumberFormat format) throws IllegalArgumentException { if (format == null) { throw new IllegalArgumentException("Format cannot be null"); } this.format = format; } @Override public void render(RendererCellReference cell, Number number) { cell.getElement().setInnerText(format.format(number)); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1516 Content-Disposition: inline; filename="ProgressBarRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "c8120cc809a4d349e2d98fe67104c6b246f6a152" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.google.gwt.core.shared.GWT; import com.vaadin.v7.client.ui.VProgressBar; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * A Renderer that represents a double value as a graphical progress bar. * * @since 7.4 * @author Vaadin Ltd */ public class ProgressBarRenderer extends WidgetRenderer { @Override public VProgressBar createWidget() { VProgressBar progressBar = GWT.create(VProgressBar.class); progressBar.addStyleDependentName("static"); return progressBar; } @Override public void render(RendererCellReference cell, Double data, VProgressBar progressBar) { if (data == null) { progressBar.setEnabled(false); } else { progressBar.setEnabled(true); progressBar.setState(data.floatValue()); } } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1915 Content-Disposition: inline; filename="Renderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "c79ee3ae1909ba44e1d9c48c0aaa980cdb7470cf" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.vaadin.v7.client.widget.escalator.Cell; import com.vaadin.v7.client.widget.grid.RendererCellReference; import com.vaadin.v7.client.widgets.Grid; /** * Renderer for rending a value <T> into cell. *

* You can add a renderer to any column by overring the * {@link GridColumn#getRenderer()} method and returning your own renderer. You * can retrieve the cell element using {@link Cell#getElement()}. * * @param * The column type * * @since 7.4 * @author Vaadin Ltd */ public interface Renderer { /** * Called whenever the {@link Grid} updates a cell. *

* For optimal performance, work done in this method should be kept to a * minimum since it will be called continuously while the user is scrolling. * It is recommended to set up the cell's DOM structure in * {@link ComplexRenderer#init(RendererCellReference)} and only make * incremental updates based on cell data in this method. * * @param cell * The cell. Note that the cell is a flyweight and should not be * stored outside of the method as it will change. * * @param data * The column data object */ void render(RendererCellReference cell, T data); } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 982 Content-Disposition: inline; filename="TextRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "5f4840a0f30a94d45a336c06f76131719bf5fd5e" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * Renderer that renders text into a cell. * * @since 7.4 * @author Vaadin Ltd */ public class TextRenderer implements Renderer { @Override public void render(RendererCellReference cell, String text) { cell.getElement().setInnerText(text); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 4026 Content-Disposition: inline; filename="WidgetRenderer.java" Last-Modified: Mon, 07 Jul 2025 04:11:49 GMT Expires: Mon, 07 Jul 2025 04:16:49 GMT ETag: "196c53e8a60da381d4f192210e5e97955ccb115e" /* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.v7.client.renderers; import com.google.gwt.dom.client.TableCellElement; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.WidgetUtil; import com.vaadin.v7.client.widget.grid.RendererCellReference; /** * A renderer for rendering widgets into cells. * * @since 7.4 * @author Vaadin Ltd * @param * the row data type * @param * the Widget type */ public abstract class WidgetRenderer extends ComplexRenderer { @Override public void init(RendererCellReference cell) { // Implement if needed } /** * Creates a widget to attach to a cell. The widgets will be attached to the * cell after the cell element has been attached to DOM. * * @return widget to attach to a cell. All returned instances should be new * widget instances without a parent. */ public abstract W createWidget(); @Override public void render(RendererCellReference cell, T data) { W w = getWidget(cell.getElement()); assert w != null : "Widget not found in cell (" + cell.getColumn() + "," + cell.getRow() + ")"; render(cell, data, w); } /** * Renders a cell with a widget. This provides a way to update any * information in the widget that is cell specific. Do not detach the Widget * here, it will be done automatically by the Grid when the widget is no * longer needed. *

* For optimal performance, work done in this method should be kept to a * minimum since it will be called continuously while the user is scrolling. * The renderer can use {@link Widget#setLayoutData(Object)} to store cell * data that might be needed in e.g. event listeners. * * @param cell * The cell to render. Note that the cell is a flyweight and * should not be stored and used outside of this method as its * contents will change. * @param data * the data of the cell * @param widget * the widget embedded in the cell */ public abstract void render(RendererCellReference cell, T data, W widget); /** * Returns the widget contained inside the given cell element. Cannot be * called for cells that do not contain a widget. * * @param e * the element inside which to find a widget * @return the widget inside the element */ protected W getWidget(TableCellElement e) { W w = getWidget(e, null); assert w != null : "Widget not found inside cell"; return w; } /** * Returns the widget contained inside the given cell element, or null if it * is not an instance of the given class. Cannot be called for cells that do * not contain a widget. * * @param e * the element inside to find a widget * @param klass * the type of the widget to find * @return the widget inside the element, or null if its type does not match */ protected static W getWidget(TableCellElement e, Class klass) { W w = WidgetUtil.findWidget(e.getFirstChildElement(), klass); assert w == null || w.getElement() == e .getFirstChildElement() : "Widget not found inside cell"; return w; } }