All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.v7.client.renderers.ComplexRenderer Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2023 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * 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 } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy