/* * 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.ui.renderers; import com.vaadin.server.AbstractJavaScriptExtension; import com.vaadin.server.JavaScriptCallbackHelper; import com.vaadin.server.JsonCodec; import com.vaadin.shared.JavaScriptExtensionState; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.ui.JavaScriptFunction; import elemental.json.Json; import elemental.json.JsonValue; /** * Base class for Renderers with all client-side logic implemented using * JavaScript. *

* When a new JavaScript renderer is initialized in the browser, the framework * will look for a globally defined JavaScript function that will initialize the * renderer. The name of the initialization function is formed by replacing . * with _ in the name of the server-side class. If no such function is defined, * each super class is used in turn until a match is found. The framework will * thus first attempt with com_example_MyRenderer for the * server-side * com.example.MyRenderer extends AbstractJavaScriptRenderer class. * If MyRenderer instead extends com.example.SuperRenderer , then * com_example_SuperRenderer will also be attempted if * com_example_MyRenderer has not been defined. *

* * In addition to the general JavaScript extension functionality explained in * {@link AbstractJavaScriptExtension}, this class also provides some * functionality specific for renderers. *

* The initialization function will be called with this pointing to * a connector wrapper object providing integration to Vaadin. Please note that * in JavaScript, this is not necessarily defined inside callback * functions and it might therefore be necessary to assign the reference to a * separate variable, e.g. var self = this;. In addition to the * extension functions described for {@link AbstractJavaScriptExtension}, the * connector wrapper object also provides this function: *

* The connector wrapper also supports these special functions that can be * implemented by the connector: * * *

* The cell object passed to functions defined by the renderer has these * properties: *

* * @param * the grid type this renderer can be attached to * @param * the type this renderer knows how to present * * @author Vaadin Ltd * @since 8.0 */ public abstract class AbstractJavaScriptRenderer extends AbstractRenderer { private JavaScriptCallbackHelper callbackHelper = new JavaScriptCallbackHelper( this); protected AbstractJavaScriptRenderer(Class presentationType, String nullRepresentation) { super(presentationType, nullRepresentation); } protected AbstractJavaScriptRenderer(Class presentationType) { super(presentationType, null); } @Override protected void registerRpc(R implementation, Class rpcInterfaceType) { super.registerRpc(implementation, rpcInterfaceType); callbackHelper.registerRpc(rpcInterfaceType); } /** * Register a {@link JavaScriptFunction} that can be called from the * JavaScript using the provided name. A JavaScript function with the * provided name will be added to the connector wrapper object (initially * available as this). Calling that JavaScript function will * cause the call method in the registered {@link JavaScriptFunction} to be * invoked with the same arguments. * * @param functionName * the name that should be used for client-side callback * @param function * the {@link JavaScriptFunction} object that will be invoked * when the JavaScript function is called */ protected void addFunction(String functionName, JavaScriptFunction function) { callbackHelper.registerCallback(functionName, function); } /** * Invoke a named function that the connector JavaScript has added to the * JavaScript connector wrapper object. The arguments can be any boxed * primitive type, String, {@link JsonValue} or arrays of any other * supported type. Complex types (e.g. List, Set, Map, Connector or any * JavaBean type) must be explicitly serialized to a {@link JsonValue} * before sending. This can be done either with * {@link JsonCodec#encode(Object, JsonValue, java.lang.reflect.Type, com.vaadin.ui.ConnectorTracker)} * or using the factory methods in {@link Json}. * * @param name * the name of the function * @param arguments * function arguments */ protected void callFunction(String name, Object... arguments) { callbackHelper.invokeCallback(name, arguments); } @Override protected JavaScriptExtensionState getState() { return (JavaScriptExtensionState) super.getState(); } @Override protected JavaScriptExtensionState getState(boolean markAsDirty) { return (JavaScriptExtensionState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 5736 Content-Disposition: inline; filename="AbstractRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "a0baf1c523c8a26d27866a454046e82be331f34f" /* * 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.ui.renderers; import java.util.Objects; import com.vaadin.server.AbstractClientConnector; import com.vaadin.server.AbstractExtension; import com.vaadin.server.JsonCodec; import com.vaadin.shared.ui.grid.renderers.AbstractRendererState; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; import elemental.json.JsonValue; /** * An abstract base class for server-side * {@link com.vaadin.ui.renderers.Renderer Grid renderers}. * *

* This class currently extends the AbstractExtension superclass, but this fact * should be regarded as an implementation detail and subject to change in a * future major or minor Vaadin version. * * @param * the grid type this renderer can be attached to * @param * the type this renderer knows how to present * @since 8.0 */ public abstract class AbstractRenderer extends AbstractExtension implements Renderer { private final Class presentationType; private final String nullRepresentation; /** * Creates a new renderer with the given presentation type and null * representation. * * @param presentationType * the data type that this renderer displays, not * null * @param nullRepresentation * a string that will be sent to the client instead of a regular * value in case the actual cell value is null. May * be null. */ protected AbstractRenderer(Class presentationType, String nullRepresentation) { Objects.requireNonNull(presentationType, "Presentation type cannot be null"); this.presentationType = presentationType; this.nullRepresentation = nullRepresentation; } /** * Creates a new renderer with the given presentation type. No null * representation will be used. * * @param presentationType * the data type that this renderer displays, not * null */ protected AbstractRenderer(Class presentationType) { this(presentationType, null); } /** * This method is inherited from AbstractExtension but should never be * called directly with an AbstractRenderer. */ @Deprecated @Override @SuppressWarnings("rawtypes") protected Class getSupportedParentType() { return Column.class; } /** * This method is inherited from AbstractExtension but should never be * called directly with an AbstractRenderer. */ @Deprecated @Override protected void extend(AbstractClientConnector target) { super.extend(target); } @Override public Class getPresentationType() { return presentationType; } @Override public JsonValue encode(V value) { if (value == null) { return encode(getNullRepresentation(), String.class); } else { return encode(value, getPresentationType()); } } /** * Null representation for the renderer. * * @return a textual representation of {@code null} */ protected String getNullRepresentation() { return nullRepresentation; } /** * Encodes the given value to JSON. *

* This is a helper method that can be invoked by an {@link #encode(Object) * encode(T)} override if serializing a value of type other than * {@link #getPresentationType() the presentation type} is desired. For * instance, a {@code Renderer} could first turn a date value into a * formatted string and return {@code encode(dateString, String.class)}. * * @param value * the value to be encoded * @param type * the type of the value * @return a JSON representation of the given value */ protected JsonValue encode(U value, Class type) { return JsonCodec .encode(value, null, type, getUI().getConnectorTracker()) .getEncodedValue(); } /** * Gets the {@link Grid} this renderer is attached to. Used internally for * indicating the source grid of possible events emitted by this renderer, * such as {@link RendererClickEvent}s. * * @return the grid this renderer is attached to or {@code null} if * unattached */ @SuppressWarnings("unchecked") protected Grid getParentGrid() { if (super.getParent() == null) { return null; } return (Grid) super.getParent().getParent(); } @Override public Column getParent() { return (Column) super.getParent(); } @Override protected AbstractRendererState getState() { return (AbstractRendererState) super.getState(); } @Override protected AbstractRendererState getState(boolean markAsDirty) { return (AbstractRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 3421 Content-Disposition: inline; filename="ButtonRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "fc1584a15c9064aa4a168c6b01282d8f0b0f95f6" /* * 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.ui.renderers; import com.vaadin.shared.ui.grid.renderers.ButtonRendererState; /** * A Renderer that displays a button with a textual caption. The value of the * corresponding property is used as the caption. Click listeners 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 { /** * Creates a new button renderer. * * @param nullRepresentation * the textual representation of {@code null} value */ public ButtonRenderer(String nullRepresentation) { super(String.class, nullRepresentation); } /** * Creates a new button renderer and adds the given click listener to it. * * @param listener * the click listener to register * @param nullRepresentation * the textual representation of {@code null} value */ public ButtonRenderer(RendererClickListener listener, String nullRepresentation) { this(nullRepresentation); addClickListener(listener); } /** * Creates a new button renderer. */ public ButtonRenderer() { this(""); } /** * Creates a new button renderer and adds the given click listener to it. * * @param listener * the click listener to register */ public ButtonRenderer(RendererClickListener listener) { this(listener, ""); } @Override public String getNullRepresentation() { return super.getNullRepresentation(); } @Override protected ButtonRendererState getState() { return (ButtonRendererState) super.getState(); } @Override protected ButtonRendererState getState(boolean markAsDirty) { return (ButtonRendererState) super.getState(markAsDirty); } /** * Sets whether the data should be rendered as HTML (instead of text). *

* By default everything is rendered as text. * * @param htmlContentAllowed * true to render as HTML, false to * render as text * * @since 8.0.3 */ public void setHtmlContentAllowed(boolean htmlContentAllowed) { getState().htmlContentAllowed = htmlContentAllowed; } /** * Gets whether the data should be rendered as HTML (instead of text). *

* By default everything is rendered as text. * * @return true if the renderer renders a HTML, * false if the content is rendered as text * * @since 8.0.3 */ public boolean isHtmlContentAllowed() { return getState(false).htmlContentAllowed; } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 5780 Content-Disposition: inline; filename="ClickableRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "1968d08aee30b895bd67d4cf6cd8d24f8ac96b0f" /* * 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.ui.renderers; import java.lang.reflect.Method; import com.vaadin.event.ConnectorEventListener; import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.Registration; import com.vaadin.shared.ui.grid.renderers.ClickableRendererState; import com.vaadin.shared.ui.grid.renderers.RendererClickRpc; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; import com.vaadin.util.ReflectTools; /** * An abstract superclass for {@link Renderer}s that render clickable items. * Click listeners can be added to a renderer to be notified when any of the * rendered items is clicked. * * @param * the type of the parent {@link Grid} * @param * the type presented by the renderer * * @since 7.4 * @author Vaadin Ltd */ public abstract class ClickableRenderer extends AbstractRenderer { /** * An interface for listening to {@link RendererClickEvent renderer click * events}. * * @see ButtonRenderer#addClickListener(RendererClickListener) */ @FunctionalInterface public interface RendererClickListener extends ConnectorEventListener { static final Method CLICK_METHOD = ReflectTools.findMethod( RendererClickListener.class, "click", RendererClickEvent.class); /** * Called when a rendered button is clicked. * * @param event * the event representing the click */ void click(RendererClickEvent event); } /** * An event fired when a clickable widget rendered by a ClickableRenderer is * clicked. * * @param * the item type associated with this click event */ public static class RendererClickEvent extends ClickEvent { private final T item; private final Column column; protected RendererClickEvent(Grid source, T item, Column column, MouseEventDetails mouseEventDetails) { super(source, mouseEventDetails); this.item = item; this.column = column; } /** * Returns the item of the row where the click event originated. * * @return the item of the clicked row * @since 8.0 */ public T getItem() { return item; } /** * Returns the {@link Column} where the click event originated. * * @return the column of the click event */ public Column getColumn() { return column; } } /** * Creates a new clickable renderer with the given presentation type. No * null representation will be used. * * @param presentationType * the data type that this renderer displays, not * null */ protected ClickableRenderer(Class presentationType) { this(presentationType, null); } /** * Creates a new clickable renderer with the given presentation type and * null representation. * * @param presentationType * the data type that this renderer displays, not * null * @param nullRepresentation * a string that will be sent to the client instead of a regular * value in case the actual cell value is null. May * be null. */ protected ClickableRenderer(Class presentationType, String nullRepresentation) { super(presentationType, nullRepresentation); registerRpc((RendererClickRpc) (String rowKey, String columnId, MouseEventDetails mouseDetails) -> { Grid grid = getParentGrid(); T item = grid.getDataCommunicator().getKeyMapper().get(rowKey); Column column = getParent(); fireEvent( new RendererClickEvent<>(grid, item, column, mouseDetails)); }); } /** * Adds a click listener to this button renderer. The listener is invoked * every time one of the buttons rendered by this renderer is clicked. * * @param listener * the click listener to be added, not null * @since 8.0 */ public Registration addClickListener(RendererClickListener listener) { return addListener(RendererClickEvent.class, listener, RendererClickListener.CLICK_METHOD); } /** * Removes the given click listener from this renderer. * * @param listener * the click listener to be removed */ @Deprecated public void removeClickListener(RendererClickListener listener) { removeListener(RendererClickEvent.class, listener); } @Override protected ClickableRendererState getState() { return (ClickableRendererState) super.getState(); } @Override protected ClickableRendererState getState(boolean markAsDirty) { return (ClickableRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 2481 Content-Disposition: inline; filename="ComponentRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "f4febfa5c5ab80c8c62ce937dbd9958bed15dc3d" /* * 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.ui.renderers; import com.vaadin.shared.ui.grid.renderers.ComponentRendererState; import com.vaadin.ui.Component; import com.vaadin.ui.Grid; import com.vaadin.ui.Label; import elemental.json.Json; import elemental.json.JsonValue; /** * A renderer for presenting Components. *

* Note: The use of ComponentRenderer causes the Grid to * generate components for all items currently available in the client-side. * This means that a number of components is always generated and sent to the * client. Using complex structures of many nested components might be heavy to * generate and store, which will lead to performance problems. *

* Note: Components will occasionally be generated again during * runtime e.g. when selection changes. If your component has an internal state * that is not stored into the object, you should reuse the same component * instances. *

* Example of how to add a {@link Label} component to {@link Grid}: * *

 * Grid grid;
 * grid.addColumn(person -> new Label(person.getFullName()),
 *         new ComponentRenderer()).setCaption("Full Name");
 * 
* * @author Vaadin Ltd * @since 8.1 */ @SuppressWarnings("serial") public class ComponentRenderer extends AbstractRenderer { /** * Constructor for ComponentRenderer. */ public ComponentRenderer() { super(Component.class); } @Override public JsonValue encode(Component value) { return value != null ? Json.create(value.getConnectorId()) : null; } @Override protected ComponentRendererState getState(boolean markAsDirty) { return (ComponentRendererState) super.getState(markAsDirty); } @Override protected ComponentRendererState getState() { return (ComponentRendererState) super.getState(); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 8119 Content-Disposition: inline; filename="DateRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "aabba3b0e897f6cbe4b963b0e8ce7e164f642437" /* * 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.ui.renderers; import java.text.DateFormat; import java.util.Date; import java.util.Locale; import com.vaadin.shared.ui.grid.renderers.DateRendererState; import elemental.json.JsonValue; /** * A renderer for presenting date values. * * @since 7.4 * @author Vaadin Ltd */ public class DateRenderer extends AbstractRenderer { private final Locale locale; private final String formatString; private final DateFormat dateFormat; /** * Creates a new date renderer. *

* The renderer is configured to render with the {@link Date#toString()} * representation for the default locale. */ public DateRenderer() { this(Locale.getDefault(), ""); } /** * Creates a new date renderer. *

* The renderer is configured to render with the {@link Date#toString()} * representation for the given locale. * * @param locale * the locale in which to present dates * @throws IllegalArgumentException * if {@code locale} is {@code null} */ public DateRenderer(Locale locale) throws IllegalArgumentException { this("%s", locale, ""); } /** * Creates a new date renderer. *

* The renderer is configured to render with the {@link Date#toString()} * representation for the given locale. * * @param locale * the locale in which to present dates * @param nullRepresentation * the textual representation of {@code null} value * @throws IllegalArgumentException * if {@code locale} is {@code null} */ public DateRenderer(Locale locale, String nullRepresentation) throws IllegalArgumentException { this("%s", locale, nullRepresentation); } /** * Creates a new date renderer. *

* The renderer is configured to render with the given string format, as * displayed in the default locale. * * @param formatString * the format string with which to format the date * @throws IllegalArgumentException * if {@code formatString} is {@code null} * @see * Format String Syntax */ public DateRenderer(String formatString) throws IllegalArgumentException { this(formatString, ""); } /** * Creates a new date renderer. *

* The renderer is configured to render with the given string format, as * displayed in the default locale. * * @param formatString * the format string with which to format the date * @param nullRepresentation * the textual representation of {@code null} value * @throws IllegalArgumentException * if {@code formatString} is {@code null} * @see * Format String Syntax */ public DateRenderer(String formatString, String nullRepresentation) throws IllegalArgumentException { this(formatString, Locale.getDefault(), nullRepresentation); } /** * Creates a new date renderer. *

* The renderer is configured to render with the given string format, as * displayed in the given locale. * * @param formatString * the format string to format the date with * @param locale * the locale to use * @throws IllegalArgumentException * if either argument is {@code null} * @see * Format String Syntax */ public DateRenderer(String formatString, Locale locale) throws IllegalArgumentException { this(formatString, locale, ""); } /** * Creates a new date renderer. *

* The renderer is configured to render with the given string format, as * displayed in the given locale. * * @param formatString * the format string to format the date with * @param locale * the locale to use * @param nullRepresentation * the textual representation of {@code null} value * @throws IllegalArgumentException * if either argument is {@code null} * @see * Format String Syntax */ public DateRenderer(String formatString, Locale locale, String nullRepresentation) throws IllegalArgumentException { super(Date.class, nullRepresentation); if (formatString == null) { throw new IllegalArgumentException("format string may not be null"); } if (locale == null) { throw new IllegalArgumentException("locale may not be null"); } this.locale = locale; this.formatString = formatString; dateFormat = null; } /** * Creates a new date renderer. *

* The renderer is configured to render with he given date format. * * @param dateFormat * the date format to use when rendering dates * @throws IllegalArgumentException * if {@code dateFormat} is {@code null} */ public DateRenderer(DateFormat dateFormat) throws IllegalArgumentException { this(dateFormat, ""); } /** * Creates a new date renderer. *

* The renderer is configured to render with he given date format. * * @param dateFormat * the date format to use when rendering dates * @throws IllegalArgumentException * if {@code dateFormat} is {@code null} */ public DateRenderer(DateFormat dateFormat, String nullRepresentation) throws IllegalArgumentException { super(Date.class, nullRepresentation); if (dateFormat == null) { throw new IllegalArgumentException("date format may not be null"); } locale = null; formatString = null; this.dateFormat = dateFormat; } @Override public String getNullRepresentation() { return super.getNullRepresentation(); } @Override public JsonValue encode(Date value) { String dateString; if (value == null) { dateString = getNullRepresentation(); } else if (dateFormat != null) { dateString = dateFormat.format(value); } else { dateString = String.format(locale, formatString, value); } return encode(dateString, String.class); } @Override public String toString() { final String fieldInfo; if (dateFormat != null) { fieldInfo = "dateFormat: " + dateFormat; } else { fieldInfo = "locale: " + locale + ", formatString: " + formatString; } return String.format("%s [%s]", getClass().getSimpleName(), fieldInfo); } @Override protected DateRendererState getState() { return (DateRendererState) super.getState(); } @Override protected DateRendererState getState(boolean markAsDirty) { return (DateRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1602 Content-Disposition: inline; filename="HtmlRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "9aef9c04fa9460cf5e2a32b2f66cd57965b3e17b" /* * 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.ui.renderers; import com.vaadin.shared.ui.grid.renderers.HtmlRendererState; /** * A renderer for presenting HTML content. * * @author Vaadin Ltd * @since 7.4 */ public class HtmlRenderer extends AbstractRenderer { /** * Creates a new HTML renderer. * * @param nullRepresentation * the html representation of {@code null} value */ public HtmlRenderer(String nullRepresentation) { super(String.class, nullRepresentation); } /** * Creates a new HTML renderer. */ public HtmlRenderer() { this(""); } @Override public String getNullRepresentation() { return super.getNullRepresentation(); } @Override protected HtmlRendererState getState() { return (HtmlRendererState) super.getState(); } @Override protected HtmlRendererState getState(boolean markAsDirty) { return (HtmlRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 2598 Content-Disposition: inline; filename="ImageRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "c2b80987a5be8a5a3d764d2bc15f26fa3809cccd" /* * 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.ui.renderers; import com.vaadin.server.ExternalResource; import com.vaadin.server.Resource; import com.vaadin.server.ResourceReference; import com.vaadin.server.ThemeResource; import com.vaadin.shared.communication.URLReference; import com.vaadin.shared.ui.grid.renderers.ImageRendererState; import elemental.json.JsonValue; /** * A renderer for presenting images. *

* The image for each rendered cell is read from a Resource-typed property in * the data source. Only {@link ExternalResource}s and {@link ThemeResource}s * are currently supported. * * @param * the type of the grid this renderer can be attached to * * @since 7.4 * @author Vaadin Ltd */ public class ImageRenderer extends ClickableRenderer { /** * Creates a new image renderer. */ public ImageRenderer() { super(Resource.class, null); } /** * Creates a new image renderer and adds the given click listener to it. * * @param listener * the click listener to register */ public ImageRenderer(RendererClickListener listener) { this(); addClickListener(listener); } @Override public JsonValue encode(Resource resource) { if (!(resource == null || resource instanceof ExternalResource || resource instanceof ThemeResource)) { throw new IllegalArgumentException( "ImageRenderer only supports ExternalResource and ThemeResource (" + resource.getClass().getSimpleName() + " given)"); } return encode(ResourceReference.create(resource, this, null), URLReference.class); } @Override protected ImageRendererState getState() { return (ImageRendererState) super.getState(); } @Override protected ImageRendererState getState(boolean markAsDirty) { return (ImageRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 9548 Content-Disposition: inline; filename="LocalDateRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "467c7055b1089b5280d109a290aec23d0ee73eee" /* * 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.ui.renderers; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.Locale; import com.vaadin.data.util.BeanUtil; import com.vaadin.server.SerializableSupplier; import com.vaadin.shared.ui.grid.renderers.LocalDateRendererState; import elemental.json.JsonValue; /** * A renderer for presenting date values. * * @author Vaadin Ltd * @since 8.1 */ public class LocalDateRenderer extends AbstractRenderer { private SerializableSupplier formatterSupplier; private boolean getLocaleFromGrid; /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the grid's locale it is * attached to, with the format style being {@code FormatStyle.LONG} and an * empty string as its null representation. * * @see * FormatStyle.LONG */ public LocalDateRenderer() { this(() -> DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG), ""); getLocaleFromGrid = true; } /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the given string format, as * displayed in the grid's locale it is attached to, with an empty string as * its null representation. * * @param formatPattern * the format pattern to format the date with, not {@code null} * * @throws IllegalArgumentException * if format pattern is null * * @see * Format Pattern Syntax */ public LocalDateRenderer(String formatPattern) { this(formatPattern, Locale.getDefault()); getLocaleFromGrid = true; } /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the given string format, as * displayed in the given locale, with an empty string as its null * representation. * * @param formatPattern * the format pattern to format the date with, not {@code null} * @param locale * the locale to use, not {@code null} * * @throws IllegalArgumentException * if format pattern is null * @throws IllegalArgumentException * if locale is null * * @see * Format Pattern Syntax */ public LocalDateRenderer(String formatPattern, Locale locale) { this(formatPattern, locale, ""); } /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the given string format, as * displayed in the given locale. * * @param formatPattern * the format pattern to format the date with, not {@code null} * @param locale * the locale to use, not {@code null} * @param nullRepresentation * the textual representation of the {@code null} value * * @throws IllegalArgumentException * if format pattern is null * @throws IllegalArgumentException * if locale is null * * @see * Format Pattern Syntax */ public LocalDateRenderer(String formatPattern, Locale locale, String nullRepresentation) { super(LocalDate.class, nullRepresentation); if (formatPattern == null) { throw new IllegalArgumentException( "format pattern may not be null"); } if (locale == null) { throw new IllegalArgumentException("locale may not be null"); } formatterSupplier = () -> DateTimeFormatter.ofPattern(formatPattern, locale); } /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the given formatter, with an * empty string as its null representation. * *

* Note the {@code DateTimeFormatter} is not a serializable class, so * using this method in an environment which requires session persistence * may produce {@link java.io.NotSerializableException}. * * @param formatter * the formatter to use, not {@code null} * * @throws IllegalArgumentException * if formatter is null * @deprecated the method is unsafe for serialization, may produce troubles * in a cluster environment * @see #LocalDateRenderer(SerializableSupplier) */ @Deprecated public LocalDateRenderer(DateTimeFormatter formatter) { this(formatter, ""); } /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the given formatterSupplier. * * @param formatterSupplier * the formatterSupplier supplier to use, not {@code null}, it * should not supply {@code null} either * @param nullRepresentation * the textual representation of the {@code null} value * * @throws IllegalArgumentException * if formatterSupplier is null */ public LocalDateRenderer( SerializableSupplier formatterSupplier, String nullRepresentation) { super(LocalDate.class, nullRepresentation); if (formatterSupplier == null) { throw new IllegalArgumentException( "formatterSupplier may not be null"); } this.formatterSupplier = formatterSupplier; assert BeanUtil.checkSerialization(formatterSupplier); } /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the given formatterSupplier. * * @param formatterSupplier * the formatterSupplier supplier to use, not {@code null}, it * should not supply {@code null} either * @throws IllegalArgumentException * if formatterSupplier is null */ public LocalDateRenderer( SerializableSupplier formatterSupplier) { this(formatterSupplier, ""); } /** * Creates a new LocalDateRenderer. *

* The renderer is configured to render with the given formatter. * *

* Note the {@code DateTimeFormatter} is not a serializable class, so * using this method in an environment which requires session persistence * may produce {@link java.io.NotSerializableException}. * * @param formatter * the formatter to use, not {@code null} * @param nullRepresentation * the textual representation of the {@code null} value * * @throws IllegalArgumentException * if formatter is null * @deprecated the method is unsafe for serialization, may produce troubles * in acluster environment * @see #LocalDateRenderer(SerializableSupplier, String) */ @Deprecated public LocalDateRenderer(DateTimeFormatter formatter, String nullRepresentation) { super(LocalDate.class, nullRepresentation); if (formatter == null) { throw new IllegalArgumentException("formatter may not be null"); } this.formatterSupplier = () -> formatter; } @Override public JsonValue encode(LocalDate value) { String dateString; if (value == null) { dateString = getNullRepresentation(); } else if (getLocaleFromGrid) { if (getParentGrid() == null) { throw new IllegalStateException( "Could not find a locale to format with: " + "this renderer should either be attached to a grid " + "or constructed with locale information"); } dateString = value.format(formatterSupplier.get() .withLocale(getParentGrid().getLocale())); } else { dateString = value.format(formatterSupplier.get()); } return encode(dateString, String.class); } @Override protected LocalDateRendererState getState() { return (LocalDateRendererState) super.getState(); } @Override protected LocalDateRendererState getState(boolean markAsDirty) { return (LocalDateRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 9970 Content-Disposition: inline; filename="LocalDateTimeRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "09b6300535840c7c64afda009edc4f41a8f53a3d" /* * 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.ui.renderers; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.Locale; import com.vaadin.server.SerializableSupplier; import com.vaadin.shared.ui.grid.renderers.LocalDateTimeRendererState; import elemental.json.JsonValue; import static com.vaadin.data.util.BeanUtil.checkSerialization; /** * A renderer for presenting {@code LocalDateTime} objects. * * @author Vaadin Ltd * @since 8.1 */ public class LocalDateTimeRenderer extends AbstractRenderer { private SerializableSupplier formatterSupplier; private boolean getLocaleFromGrid; /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the grid's locale it is * attached to, with the format style being {@code FormatStyle.LONG} for the * date and {@code FormatStyle.SHORT} for time, with an empty string as its * null representation. * * @see * FormatStyle.LONG * @see * FormatStyle.SHORT */ public LocalDateTimeRenderer() { this(() -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT), ""); getLocaleFromGrid = true; } /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the given formatter, with the * empty string as its null representation. * *

* Note the {@code DateTimeFormatter} is not a serializable class, so * using this method in an environment which requires session persistence * may produce {@link java.io.NotSerializableException}. * * @param formatter * the formatter to use, not {@code null} * * @throws IllegalArgumentException * if formatter is null * @deprecated the method is unsafe for serialization, may produce troubles * in a cluster environment * @see #LocalDateTimeRenderer(SerializableSupplier) */ @Deprecated public LocalDateTimeRenderer(DateTimeFormatter formatter) { this(formatter, ""); } /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the given formatter. * *

* Note the {@code DateTimeFormatter} is not a serializable class, so * using this method in an environment which requires session persistence * may produce {@link java.io.NotSerializableException}. * * * @param formatter * the formatter to use, not {@code null} * @param nullRepresentation * the textual representation of the {@code null} value * * @throws IllegalArgumentException * if formatter is null * @deprecated the method is unsafe for serialization, may produce troubles * in acluster environment * @see #LocalDateTimeRenderer(SerializableSupplier, String) */ @Deprecated public LocalDateTimeRenderer(DateTimeFormatter formatter, String nullRepresentation) { super(LocalDateTime.class, nullRepresentation); if (formatter == null) { throw new IllegalArgumentException("formatter may not be null"); } this.formatterSupplier = () -> formatter; } /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the given string format, as * displayed in the grid's locale it is attached to, with an empty string as * its null representation. * * @param formatPattern * the format pattern to format the date with, not {@code null} * * @throws IllegalArgumentException * if format pattern is null * * @see * Format Pattern Syntax */ public LocalDateTimeRenderer(String formatPattern) { this(formatPattern, Locale.getDefault()); getLocaleFromGrid = true; } /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the given string format, as * displayed in the given locale, with an empty string as its null * representation. * * @param formatPattern * the format pattern to format the date with, not {@code null} * @param locale * the locale to use, not {@code null} * * @throws IllegalArgumentException * if format pattern is null * @throws IllegalArgumentException * if locale is null * * @see * Format Pattern Syntax */ public LocalDateTimeRenderer(String formatPattern, Locale locale) { this(formatPattern, locale, ""); } /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the given string format, as * displayed in the given locale. * * @param formatPattern * the format pattern to format the date with, not {@code null} * @param locale * the locale to use, not {@code null} * @param nullRepresentation * the textual representation of the {@code null} value * * @throws IllegalArgumentException * if format pattern is null * @throws IllegalArgumentException * if locale is null * * @see * Format Pattern Syntax */ public LocalDateTimeRenderer(String formatPattern, Locale locale, String nullRepresentation) { super(LocalDateTime.class, nullRepresentation); if (formatPattern == null) { throw new IllegalArgumentException( "format pattern may not be null"); } if (locale == null) { throw new IllegalArgumentException("locale may not be null"); } formatterSupplier = () -> DateTimeFormatter.ofPattern(formatPattern, locale); } /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the given formatterSupplier. * * @param formatterSupplier * the formatterSupplier supplier to use, not {@code null}, it * should not supply {@code null} either * @throws IllegalArgumentException * if formatterSupplier is null */ public LocalDateTimeRenderer( SerializableSupplier formatterSupplier) { this(formatterSupplier, ""); } /** * Creates a new LocalDateTimeRenderer. *

* The renderer is configured to render with the given formatterSupplier. * * @param formatterSupplier * the formatterSupplier supplier to use, not {@code null}, it * should not supply {@code null} either * @param nullRepresentation * the textual representation of the {@code null} value * * @throws IllegalArgumentException * if formatterSupplier is null */ public LocalDateTimeRenderer( SerializableSupplier formatterSupplier, String nullRepresentation) { super(LocalDateTime.class, nullRepresentation); if (formatterSupplier == null) { throw new IllegalArgumentException( "formatterSupplier may not be null"); } this.formatterSupplier = formatterSupplier; assert checkSerialization(formatterSupplier); } @Override public JsonValue encode(LocalDateTime value) { String dateString; if (value == null) { dateString = getNullRepresentation(); } else if (getLocaleFromGrid) { if (getParentGrid() == null) { throw new IllegalStateException( "Could not find a locale to format with: " + "this renderer should either be attached to a grid " + "or constructed with locale information"); } dateString = value.format(formatterSupplier.get() .withLocale(getParentGrid().getLocale())); } else { dateString = value.format(formatterSupplier.get()); } return encode(dateString, String.class); } @Override protected LocalDateTimeRendererState getState() { return (LocalDateTimeRendererState) super.getState(); } @Override protected LocalDateTimeRendererState getState(boolean markAsDirty) { return (LocalDateTimeRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 7092 Content-Disposition: inline; filename="NumberRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "ff31a3ddc5f37694f3d6996e78ecc13618df27ce" /* * 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.ui.renderers; import java.text.NumberFormat; import java.util.Locale; import com.vaadin.shared.ui.grid.renderers.NumberRendererState; import elemental.json.JsonValue; /** * A renderer for presenting number values. * * @since 7.4 * @author Vaadin Ltd */ public class NumberRenderer extends AbstractRenderer { private final Locale locale; private final NumberFormat numberFormat; private final String formatString; /** * Creates a new number renderer. *

* The renderer is configured to render with the number's natural string * representation in the default locale. */ public NumberRenderer() { this(Locale.getDefault()); } /** * Creates a new number renderer. *

* The renderer is configured to render the number as defined with the given * number format. * * @param numberFormat * the number format with which to display numbers * @throws IllegalArgumentException * if {@code numberFormat} is {@code null} */ public NumberRenderer(NumberFormat numberFormat) { this(numberFormat, ""); } /** * Creates a new number renderer. *

* The renderer is configured to render the number as defined with the given * number format. * * @param numberFormat * the number format with which to display numbers * @param nullRepresentation * the textual representation of {@code null} value * @throws IllegalArgumentException * if {@code numberFormat} is {@code null} */ public NumberRenderer(NumberFormat numberFormat, String nullRepresentation) throws IllegalArgumentException { super(Number.class, nullRepresentation); if (numberFormat == null) { throw new IllegalArgumentException("Number format may not be null"); } locale = null; this.numberFormat = numberFormat; formatString = null; } /** * Creates a new number renderer. *

* The renderer is configured to render with the number's natural string * representation in the given locale. * * @param locale * the locale in which to display numbers * @throws IllegalArgumentException * if {@code locale} is {@code null} */ public NumberRenderer(Locale locale) throws IllegalArgumentException { this("%s", locale); } /** * Creates a new number renderer. *

* The renderer is configured to render with the number's natural string * representation in the given locale. * * @param formatString * the format string with which to format the number * @param locale * the locale in which to display numbers * @throws IllegalArgumentException * if {@code locale} is {@code null} */ public NumberRenderer(String formatString, Locale locale) throws IllegalArgumentException { // This will call #toString() during formatting this(formatString, locale, ""); } /** * Creates a new number renderer. *

* The renderer is configured to render with the given format string in the * default locale. * * @param formatString * the format string with which to format the number * @throws IllegalArgumentException * if {@code formatString} is {@code null} * @see * Format String Syntax */ public NumberRenderer(String formatString) throws IllegalArgumentException { this(formatString, Locale.getDefault(), ""); } /** * Creates a new number renderer. *

* The renderer is configured to render with the given format string in the * given locale. * * @param formatString * the format string with which to format the number * @param locale * the locale in which to present numbers * @throws IllegalArgumentException * if either argument is {@code null} * @see * Format String Syntax */ public NumberRenderer(String formatString, Locale locale, String nullRepresentation) { super(Number.class, nullRepresentation); if (formatString == null) { throw new IllegalArgumentException("Format string may not be null"); } if (locale == null) { throw new IllegalArgumentException("Locale may not be null"); } this.locale = locale; numberFormat = null; this.formatString = formatString; } @Override public JsonValue encode(Number value) { String stringValue; if (value == null) { stringValue = getNullRepresentation(); } else if (formatString != null && locale != null) { stringValue = String.format(locale, formatString, value); } else if (numberFormat != null) { stringValue = numberFormat.format(value); } else { throw new IllegalStateException(String.format("Internal bug: " + "%s is in an illegal state: " + "[locale: %s, numberFormat: %s, formatString: %s]", getClass().getSimpleName(), locale, numberFormat, formatString)); } return encode(stringValue, String.class); } @Override public String toString() { final String fieldInfo; if (numberFormat != null) { fieldInfo = "numberFormat: " + numberFormat; } else { fieldInfo = "locale: " + locale + ", formatString: " + formatString; } return String.format("%s [%s]", getClass().getSimpleName(), fieldInfo); } @Override public String getNullRepresentation() { return super.getNullRepresentation(); } @Override protected NumberRendererState getState() { return (NumberRendererState) super.getState(); } @Override protected NumberRendererState getState(boolean markAsDirty) { return (NumberRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1610 Content-Disposition: inline; filename="ProgressBarRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "eb01680110b70acff5c2fb24a07a7e3667d3ee6f" /* * 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.ui.renderers; import com.vaadin.shared.ui.grid.renderers.ProgressBarRendererState; import elemental.json.JsonValue; /** * A renderer that represents double values between 0 and 1 as a graphical * progress bar. * * @author Vaadin Ltd * @since 7.4 */ public class ProgressBarRenderer extends AbstractRenderer { /** * Creates a new text renderer. */ public ProgressBarRenderer() { super(Double.class, null); } @Override public JsonValue encode(Double value) { if (value != null) { value = Math.max(Math.min(value, 1), 0); } else { value = 0d; } return super.encode(value); } @Override protected ProgressBarRendererState getState() { return (ProgressBarRendererState) super.getState(); } @Override protected ProgressBarRendererState getState(boolean markAsDirty) { return (ProgressBarRendererState) super.getState(markAsDirty); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1987 Content-Disposition: inline; filename="Renderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "96b0c50ae667e2df5efb435dca4500adc8936773" /* * 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.ui.renderers; import com.vaadin.server.ClientConnector; import com.vaadin.server.Extension; import elemental.json.JsonValue; /** * A ClientConnector for controlling client-side * {@link com.vaadin.client.renderers.Renderer Grid renderers}. Renderers * currently extend the Extension interface, but this fact should be regarded as * an implementation detail and subject to change in a future major or minor * Vaadin revision. * * @param * the type this renderer knows how to present * * @since 7.4 * @author Vaadin Ltd */ public interface Renderer extends Extension { /** * Returns the class literal corresponding to the presentation type T. * * @return the class literal of T */ Class getPresentationType(); /** * Encodes the given value into a {@link JsonValue}. * * @param value * the value to encode * @return a JSON representation of the given value */ JsonValue encode(T value); /** * This method is inherited from Extension but should never be called * directly with a Renderer. */ @Override @Deprecated void remove(); /** * This method is inherited from Extension but should never be called * directly with a Renderer. */ @Override @Deprecated void setParent(ClientConnector parent); } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 2194 Content-Disposition: inline; filename="TextRenderer.java" Last-Modified: Sun, 05 Jan 2025 10:35:46 GMT Expires: Sun, 05 Jan 2025 10:40:46 GMT ETag: "6349af6e3c3f659d297498c47980d9df9f7956d8" /* * 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.ui.renderers; import com.vaadin.shared.ui.grid.renderers.TextRendererState; import elemental.json.Json; import elemental.json.JsonValue; /** * A renderer for presenting a plain text representation of any value. * {@link Object#toString()} is used for determining the text to show. * * @since 7.4 * @author Vaadin Ltd */ public class TextRenderer extends AbstractRenderer { /** * Creates a new text renderer that uses "" to represent null * values. */ public TextRenderer() { this(""); } /** * Creates a new text renderer with the given string to represent null * values. * * @param nullRepresentation * the textual representation of {@code null} value */ public TextRenderer(String nullRepresentation) { super(Object.class, nullRepresentation); } @Override public JsonValue encode(Object value) { if (value == null) { return super.encode(null); } String stringValue = value.toString(); if (stringValue == null) { return super.encode(null); } return Json.create(stringValue); } @Override public String getNullRepresentation() { return super.getNullRepresentation(); } @Override protected TextRendererState getState() { return (TextRendererState) super.getState(); } @Override protected TextRendererState getState(boolean markAsDirty) { return (TextRendererState) super.getState(markAsDirty); } }