- Added missing default sections to switch blocks.
- Added missing JavaDocs and JavaDoc parameters.
- Added wildcards where possible.
- Deprecated unused method.
- Fixed JavaDoc formatting.
- Removed inner assignments.
- Removed unused imports.
- Removed unused variables.
- Removed warning suppressions that were unnecessary or about boxing
(not tracked by coding conventions).
- Suppressed warnings about rawtypes, deprecation, and unchecked where
couldn't be avoided.
@Connect(com.vaadin.ui.Grid.Column.class)
public class ColumnConnector extends AbstractExtensionConnector {
+ /**
+ * Class for representing a custom column.
+ */
public abstract static class CustomColumn
extends Column<Object, JsonObject> {
this.connectorId = connectorId;
}
+ /**
+ * Returns the id for the corresponding connector.
+ *
+ * @return the id for the connector
+ */
public String getConnectorId() {
return connectorId;
}
import java.util.HashSet;
import java.util.Iterator;
-import java.util.logging.Logger;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerRegistration;
import com.vaadin.client.renderers.Renderer;
import com.vaadin.client.renderers.WidgetRenderer;
import com.vaadin.client.ui.AbstractComponentConnector;
-import com.vaadin.client.ui.AbstractConnector;
import com.vaadin.client.widget.grid.RendererCellReference;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.grid.renderers.ComponentRendererState;
}
private void unregisterHierarchyHandler() {
- if (this.handlerRegistration != null) {
- this.handlerRegistration.removeHandler();
- this.handlerRegistration = null;
+ if (handlerRegistration != null) {
+ handlerRegistration.removeHandler();
+ handlerRegistration = null;
}
}
@Connect(EditorImpl.class)
public class EditorConnector extends AbstractExtensionConnector {
- private Integer currentEditedRow = null;
- private boolean waitingForAvailableData = false;
-
/**
* EditorHandler for communicating with the server-side implementation.
*/
// a confirmation from the server
rpc.cancel(afterBeingSaved);
}
- currentEditedRow = null;
}
@Override
}
private void updateStaticRow(RowState rowState,
- Grid.StaticSection.StaticRow row) {
+ Grid.StaticSection.StaticRow<?> row) {
rowState.cells
.forEach((columnId, cellState) -> updateStaticCellFromState(
row.getCell(getColumn(columnId)), cellState));
return null;
}
- private TooltipInfo getHeaderFooterTooltip(CellReference cell) {
+ private TooltipInfo getHeaderFooterTooltip(CellReference<?> cell) {
Section section = Section.BODY;
if (cell instanceof EventCellReference) {
// Header or footer
- section = ((EventCellReference) cell).getSection();
+ section = ((EventCellReference<?>) cell).getSection();
}
StaticCell staticCell = null;
if (section == Section.HEADER) {
* @author Vaadin Ltd
* @since 8.1
*/
+@SuppressWarnings("deprecation")
@Connect(TreeRenderer.class)
public class TreeRendererConnector
extends AbstractGridRendererConnector<String> {
public class UnsafeHtmlRendererConnector
extends AbstractGridRendererConnector<String> {
+ /**
+ * Constructs a renderer for unsafe html content.
+ */
public static class UnsafeHtmlRenderer implements Renderer<String> {
@Override
public void render(RendererCellReference cell, String data) {
return b;
}
+ /**
+ * Sets whether HTML content is allowed.
+ *
+ * @param htmlContentAllowed
+ * {@code true} if HTML content allowed, {@code false} if
+ * contents should be rendered as plain text
+ */
public void setHtmlContentAllowed(boolean htmlContentAllowed) {
this.htmlContentAllowed = htmlContentAllowed;
}
+ /**
+ * Returns whether HTML content is allowed.
+ *
+ * @return {@code true} if HTML content allowed, {@code false} if contents
+ * are rendered as plain text
+ */
public boolean isHtmlContentAllowed() {
return htmlContentAllowed;
}
*
* @param handler
* the click handler to be added
+ * @return the handler registration, can be stored in order to remove the
+ * handler later
*/
public HandlerRegistration addClickHandler(
RendererClickHandler<?> handler) {
* Also provides a helper method for hiding the cell contents by overriding
* {@link #setContentVisible(FlyweightCell, boolean)}
*
+ * @param <T>
+ * the column data type
+ *
* @since 7.4.0
* @author Vaadin Ltd
*/
private TimeZone timeZone = TimeZone
.createTimeZone(new Date().getTimezoneOffset());
+ /**
+ * Constructs a renderer for displaying date data.
+ */
public DateRenderer() {
this(PredefinedFormat.DATE_TIME_SHORT);
}
+ /**
+ * Constructs a renderer for displaying date data.
+ *
+ * @param format
+ * the required display format
+ */
public DateRenderer(PredefinedFormat format) {
this(DateTimeFormat.getFormat(format));
}
+ /**
+ * Constructs a renderer for displaying date data.
+ *
+ * @param format
+ * the required display format
+ */
public DateRenderer(DateTimeFormat format) {
setFormat(format);
}
private static final String CLASS_EXPANDED = "expanded";
private static final String CLASS_DEPTH = "depth-";
+ @SuppressWarnings("rawtypes")
private Renderer innerRenderer;
/**
return new HierarchyItem(nodeStyleName);
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void render(RendererCellReference cell, Object data, Widget widget) {
* @param innerRenderer
* Renderer to be wrapped.
*/
+ @SuppressWarnings("rawtypes")
public void setInnerRenderer(Renderer innerRenderer) {
this.innerRenderer = innerRenderer;
}
*
* @return Wrapped renderer.
*/
+ @SuppressWarnings("rawtypes")
public Renderer getInnerRenderer() {
return innerRenderer;
}
/**
* Decides whether the element was rendered by {@link HierarchyRenderer}.
+ *
+ * @param element
+ * the element to check
+ * @return {@code true} if the element was rendered by a HierarchyRenderer,
+ * {@code false} otherwise.
*/
public static boolean isElementInHierarchyWidget(Element element) {
Widget w = WidgetUtil.findWidget(element);
*/
public class ImageRenderer extends ClickableRenderer<String, Image> {
+ /** Placeholder URL for the image. Used if URL data is set to null. */
public static final String TRANSPARENT_GIF_1PX = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
@Override
private NumberFormat format;
+ /**
+ * Constructs a renderer for presenting number data.
+ */
public NumberRenderer() {
this(NumberFormat.getDecimalFormat());
}
+ /**
+ * Constructs a renderer for presenting number data.
+ *
+ * @param format
+ * the format to use when the number is displayed
+ */
public NumberRenderer(NumberFormat format) {
setFormat(format);
}
* @since 7.4
* @author Vaadin Ltd
* @param <T>
- * the row data type
+ * the column data type
* @param <W>
* the Widget type
*/
* is not an instance of the given class. Cannot be called for cells that do
* not contain a widget.
*
+ * @param <W>
+ * the Widget type
* @param e
* the element inside to find a widget
* @param klass
* @author Vaadin Ltd
*/
public class FlyweightCell {
+ /** The column span property name. */
public static final String COLSPAN_ATTR = "colSpan";
private final int column;
private TableCellElement element = null;
private CellIterator currentIterator = null;
+ /**
+ * Creates a cell representation that follows the
+ * <code>Flyweight</code>-pattern.
+ *
+ * @param row
+ * representation of the row that contains the cell
+ * @param column
+ * the column index of the cell
+ *
+ * @see FlyweightCell
+ */
public FlyweightCell(final FlyweightRow row, final int column) {
this.row = row;
this.column = column;
/**
* Returns the row index of the cell.
+ *
+ * @return the row index
*/
public int getRow() {
assertSetup();
/**
* Returns the column index of the cell.
+ *
+ * @return the column index
*/
public int getColumn() {
assertSetup();
/**
* Returns the element of the cell. Can be either a <code>TD</code> element
* or a <code>TH</code> element.
+ *
+ * @return the element
*/
public TableCellElement getElement() {
assertSetup();
/**
* Return the colspan attribute of the element of the cell.
+ *
+ * @return the colspan attribute
*/
public int getColSpan() {
assertSetup();
+ "inappropriately.";
}
+ /**
+ * Set the colspan attribute for the element of the cell.
+ *
+ * @param numberOfCells
+ * spanned cell count, must be at least 1
+ */
public void setColSpan(final int numberOfCells) {
if (numberOfCells < 1) {
throw new IllegalArgumentException(
private double[] columnWidths = null;
private final List<FlyweightCell> cells = new ArrayList<>();
+ /**
+ * Configure this FlyweightRow for the current use. This method is expected
+ * to be called multiple times during the Grid's life-cycle.
+ *
+ * @param e
+ * the root element for this row
+ * @param row
+ * the row index
+ * @param columnWidths
+ * widths for each column on the row
+ * @see FlyweightRow
+ */
public void setup(final TableRowElement e, final int row,
double[] columnWidths) {
element = e;
return element;
}
+ /**
+ * Adds cell representations (i.e. new columns) for the indicated cell range
+ * and updates the subsequent indexing.
+ *
+ * @param index
+ * start index of the range
+ * @param numberOfColumns
+ * length of the range
+ */
public void addCells(final int index, final int numberOfColumns) {
for (int i = 0; i < numberOfColumns; i++) {
final int col = index + i;
updateRestOfCells(index + numberOfColumns);
}
+ /**
+ * Removes cell representations (i.e. removed columns) from the indicated
+ * cell range and updates the subsequent indexing.
+ *
+ * @param index
+ * start index of the range
+ * @param numberOfColumns
+ * length of the range
+ */
public void removeCells(final int index, final int numberOfColumns) {
cells.subList(index, index + numberOfColumns).clear();
updateRestOfCells(index);
* The orientation of the scrollbar.
*/
public enum Direction {
+ /** Scrollbar orientation, indicated by the name. */
VERTICAL, HORIZONTAL;
}
void visibilityChanged(VisibilityChangeEvent event);
}
+ /**
+ * Event for scrollbar visibility changes.
+ */
public static class VisibilityChangeEvent
extends GwtEvent<VisibilityHandler> {
+ /** Event type. */
public static final Type<VisibilityHandler> TYPE = new Type<ScrollbarBundle.VisibilityHandler>() {
@Override
public String toString() {
}
}
+ /** Root element for the scrollbar-composition. */
protected final Element root = DOM.createDiv();
+ /**
+ * Scroll size element. The size of this element determines the number of
+ * pixels the scrollbar is able to scroll through
+ */
protected final Element scrollSizeElement = DOM.createDiv();
+ /** Is the scrollbar "invisible" (thickness set to 0). */
protected boolean isInvisibleScrollbar = false;
private double scrollPos = 0;
root.setTabIndex(-1);
}
+ /**
+ * Returns the width (for horizontal) or height (for vertical) css property
+ * for the scroll size element.
+ *
+ * @return the relevant size property based on orientation
+ */
protected abstract String internalGetScrollSize();
/**
* is hidden, so the event must be fired manually.
* <p>
* When IE8 support is dropped, this should really be simplified.
+ *
+ * @param enable
+ * {@code true} if the scrollbar should be forced to be visible,
+ * {@code false} otherwise.
*/
protected void forceScrollbar(boolean enable) {
if (enable) {
internalForceScrollbar(enable);
}
+ /**
+ * Sets the overflow-x (for horizontal) or overflow-y (for vertical)
+ * property to {@code "scroll"} if enabled, or clears the property if
+ * disabled.
+ *
+ * @param enable
+ * {@code true} if the overflow property should be set,
+ * {@code false} otherwise.
+ */
protected abstract void internalForceScrollbar(boolean enable);
/**
return parseCssDimensionToPixels(internalGetOffsetSize());
}
+ /**
+ * Returns the width (for horizontal) or height (for vertical) css property
+ * for the root element.
+ *
+ * @return the relevant size property based on orientation
+ */
public abstract String internalGetOffsetSize();
/**
return getScrollSize() - getOffsetSize() > WidgetUtil.PIXEL_EPSILON;
}
+ /**
+ * Calculates and sets maximum scroll position based on the current scroll
+ * size and the scrollbar's length.
+ */
public void recalculateMaxScrollPos() {
double scrollSize = getScrollSize();
double offsetSize = getOffsetSize();
}
}
+ /**
+ * Returns the handler manager for this scrollbar bundle.
+ *
+ * @return the handler manager
+ */
protected HandlerManager getHandlerManager() {
if (handlerManager == null) {
handlerManager = new HandlerManager(this);
/**
* Gets the decorative element for this spacer.
+ *
+ * @return the decorative element
*/
Element getDecoElement();
*/
public static final Type<RowHeightChangedHandler> TYPE = new Type<>();
+ /**
+ * Returns the associated handler type.
+ *
+ * @return the handler type
+ */
public static final Type<RowHeightChangedHandler> getType() {
return TYPE;
}
*/
public static final Type<SpacerIndexChangedHandler> TYPE = new Type<>();
+ /**
+ * Returns the associated handler type.
+ *
+ * @return the handler type
+ */
public static final Type<SpacerIndexChangedHandler> getType() {
return TYPE;
}
*/
public static final Type<SpacerVisibilityChangedHandler> TYPE = new Type<>();
+ /**
+ * Returns the associated handler type.
+ *
+ * @return the handler type
+ */
public static final Type<SpacerVisibilityChangedHandler> getType() {
return TYPE;
}
void onAutoScrollReachedMax();
}
+ /**
+ * Scroll direction for automatic scrolling.
+ */
public enum ScrollAxis {
+ /** Scroll should happen to the direction indicated by the name. */
VERTICAL, HORIZONTAL
}
// TODO investigate if this works as desired
stop();
break;
+ default:
+ // NOP
+ break;
}
}
case Event.ONTOUCHCANCEL:
stop();
break;
+ default:
+ // NOP
+ break;
}
};
}
}
+ /**
+ * Returns how wide the frozen columns are all counted together.
+ *
+ * @return the width of frozen columns
+ */
public double getFrozenColumnsWidth() {
double value = 0;
private Grid.Column<?, T> column;
private final RowReference<T> rowReference;
+ /**
+ * Constructs a new cell reference for the given row.
+ *
+ * @param rowReference
+ * the row that requires a new cell
+ */
public CellReference(RowReference<T> rowReference) {
this.rowReference = rowReference;
}
public class DataAvailableEvent extends GwtEvent<DataAvailableHandler> {
private Range rowsAvailable;
+ /** Handler type for DataAvailableEvents. */
public static final Type<DataAvailableHandler> TYPE = new Type<>();
+ /**
+ * Constructs a data availability event for the given row range.
+ *
+ * @param rowsAvailable
+ * the range of available rows
+ */
public DataAvailableEvent(Range rowsAvailable) {
this.rowsAvailable = rowsAvailable;
}
* The default handler for Grid editor events. Offers several overridable
* protected methods for easier customization.
*
+ * @param <T>
+ * The row type of the grid. The row type is the POJO type from where
+ * the data is retrieved into the column cells.
+ *
* @since 7.6
* @author Vaadin Ltd
*/
public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> {
+ /** Default key code for showing the editor. */
public static final int KEYCODE_OPEN = KeyCodes.KEY_ENTER;
+ /** Default key code for moving the editor up or down. */
public static final int KEYCODE_MOVE_VERTICAL = KeyCodes.KEY_ENTER;
+ /** Default key code for hiding the editor. */
public static final int KEYCODE_CLOSE = KeyCodes.KEY_ESCAPE;
+ /** Default key code for moving cursor horizontally within the editor. */
public static final int KEYCODE_MOVE_HORIZONTAL = KeyCodes.KEY_TAB;
+ /** Default key code for triggering save in buffered mode. */
public static final int KEYCODE_BUFFERED_SAVE = KeyCodes.KEY_ENTER;
private double lastTouchEventTime = 0;
* Specifies the direction at which the focus should move.
*/
public enum CursorMoveDelta {
+ /** Move focus one step to the direction indicated by name. */
UP(-1, 0), RIGHT(0, 1), DOWN(1, 0), LEFT(0, -1);
+ /** Vertical change. */
public final int rowDelta;
+ /** Horizontal change. */
public final int colDelta;
CursorMoveDelta(int rowDelta, int colDelta) {
this.colDelta = colDelta;
}
+ /**
+ * Returns whether the cursor move has either horizontal or vertical
+ * changes.
+ *
+ * @return {@code true} if there are changes, {@code false} otherwise
+ */
public boolean isChanged() {
return rowDelta != 0 || colDelta != 0;
}
return -1;
}
+ /**
+ * Checks whether the field within the given editor column is editable.
+ *
+ * @param grid
+ * the grid that is being edited
+ * @param column
+ * the column to investigate
+ * @return {@code true} if the field is editable, {@code false} otherwise
+ */
protected boolean isEditable(Grid<T> grid, Grid.Column<?, T> column) {
if (!column.isEditable()) {
return false;
return false;
}
+ /**
+ * Opens the editor over the row with the given index and attempts to focus
+ * the editor widget in the given column index. If the given indices are
+ * outside of the existing range, the closest value within the range is
+ * used.
+ *
+ * @param event
+ * the wrapped DOM event
+ * @param rowIndex
+ * index of the row to edit
+ * @param colIndex
+ * index of the editor column to focus
+ */
protected void editRow(EditorDomEvent<T> event, int rowIndex,
int colIndex) {
int rowCount = event.getGrid().getDataSource().size();
* this object is subject to change without the user knowing it and so should
* not be stored anywhere outside of the method providing these instances.
*
+ * @param <T>
+ * The row type of the grid. The row type is the POJO type from where
+ * the data is retrieved into the column cells.
+ *
* @since 7.4
* @author Vaadin Ltd
*/
private Section section;
private TableCellElement element;
+ /**
+ * Constructs a cell reference for an event targeting a grid cell. Needs to
+ * be populated using {@link #set(Cell, Section)}.
+ *
+ * @param grid
+ * the grid the event originates from
+ *
+ * @see EventCellReference
+ */
public EventCellReference(Grid<T> grid) {
super(new RowReference<>(grid));
}
/**
- * Sets the RowReference and CellReference to point to given Cell.
+ * Configures this CellReference and its internal RowReference to point to
+ * the given Cell.
*
* @param targetCell
- * cell to point to
+ * the cell to point to
+ * @param section
+ * the section the cell belongs to
*/
public void set(Cell targetCell, Section section) {
Grid<T> grid = getGrid();
* @param column
* the column to reference
*/
+ @SuppressWarnings("unchecked")
public void set(FlyweightCell cell, int columnIndex,
Grid.Column<?, ?> column) {
this.cell = cell;
* ds.asList().addAll(Arrays.asList(5, 6, 7));
* </pre>
*
+ * @param <T>
+ * the type of the items in the grid
+ *
* @since 7.4
* @author Vaadin Ltd
*/
* @param rows
* The rows to initially add to the data source
*/
+ @SuppressWarnings("unchecked")
public ListDataSource(T... rows) {
if (rows == null) {
ds = new ArrayList<>();
private Map<Grid.Column<?, T>, Comparator<?>> comparators;
private HandlerRegistration sortHandlerRegistration;
+ /**
+ * Constructs a sorting facility for the given Grid.
+ *
+ * @param grid
+ * the Grid that needs sort handling
+ */
public ListSorter(Grid<T> grid) {
if (grid == null) {
* and Dates). Any existing comparator can be removed by passing in a
* non-null GridColumn and a null Comparator.
*
+ * @param <C>
+ * the column data type
* @param column
* a grid column. May not be null.
* @param comparator
/**
* Retrieve the comparator assigned for a specific grid column.
*
+ * @param <C>
+ * the column data type
* @param column
* a grid column. May not be null.
* @return a comparator, or null if no comparator for the specified grid
* @param order
* the sort order list provided by the grid sort event
*/
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private void sort(final List<SortOrder> order) {
DataSource<T> ds = grid.getDataSource();
if (!(ds instanceof ListDataSource)) {
*/
public abstract interface AbstractGridKeyEventHandler extends EventHandler {
+ /**
+ * Handler for Grid key down events.
+ */
public abstract interface GridKeyDownHandler
extends AbstractGridKeyEventHandler {
+ /**
+ * Perform actions that should happen when a key down event is triggered
+ * within a Grid.
+ *
+ * @param event
+ * the key down event
+ */
public void onKeyDown(GridKeyDownEvent event);
}
+ /**
+ * Handler for Grid key up events.
+ */
public abstract interface GridKeyUpHandler
extends AbstractGridKeyEventHandler {
+ /**
+ * Perform actions that should happen when a key up event is triggered
+ * within a Grid.
+ *
+ * @param event
+ * the key up event
+ */
public void onKeyUp(GridKeyUpEvent event);
}
+ /**
+ * Handler for Grid key press events.
+ */
public abstract interface GridKeyPressHandler
extends AbstractGridKeyEventHandler {
+ /**
+ * Perform actions that should happen when a key press event is
+ * triggered within a Grid.
+ *
+ * @param event
+ * the key press event
+ */
public void onKeyPress(GridKeyPressEvent event);
}
*/
public abstract interface AbstractGridMouseEventHandler extends EventHandler {
+ /**
+ * Handler for Grid click events.
+ */
public abstract interface GridClickHandler
extends AbstractGridMouseEventHandler {
+ /**
+ * Perform actions that should happen when the Grid is clicked.
+ *
+ * @param event
+ * the click event
+ */
public void onClick(GridClickEvent event);
}
+ /**
+ * Handler for Grid double-click events.
+ */
public abstract interface GridDoubleClickHandler
extends AbstractGridMouseEventHandler {
+ /**
+ * Perform actions that should happen when the Grid is double-clicked.
+ *
+ * @param event
+ * the double-click event
+ */
public void onDoubleClick(GridDoubleClickEvent event);
}
*/
private static final Type<ColumnReorderHandler<?>> TYPE = new Type<>();
+ /**
+ * Returns the associated handler type.
+ *
+ * @return the handler type
+ */
public static final Type<ColumnReorderHandler<?>> getType() {
return TYPE;
}
private final boolean userOriginated;
+ /**
+ * Constructs a reorder event for grid columns.
+ *
+ * @param oldColumnOrder
+ * the old order
+ * @param newColumnOrder
+ * the new order
+ * @param userOriginated
+ * {@code true} if the event was triggered by user interaction,
+ * {@code false} otherwise
+ */
public ColumnReorderEvent(List<Column<?, T>> oldColumnOrder,
List<Column<?, T>> newColumnOrder, boolean userOriginated) {
this.oldColumnOrder = oldColumnOrder;
private Column<?, T> column;
/**
+ * Constructs a resize event for a grid column.
+ *
* @param column
+ * the updated column
*/
public ColumnResizeEvent(Column<?, T> column) {
this.column = column;
}
+ /**
+ * Returns the associated handler type.
+ *
+ * @return the handler type
+ */
public static final Type<ColumnResizeHandler<?>> getType() {
return TYPE;
}
private static final Type<ColumnVisibilityChangeHandler<?>> TYPE = new Type<>();
+ /**
+ * Returns the associated handler type.
+ *
+ * @return the handler type
+ */
public static final Type<ColumnVisibilityChangeHandler<?>> getType() {
return TYPE;
}
private final boolean hidden;
+ /**
+ * Constructs a visibility change event for a grid column.
+ *
+ * @param column
+ * the updated column
+ * @param hidden
+ * {@code true} if the column is now hidden, {@code false}
+ * otherwise
+ * @param userOriginated
+ * {@code true} if the event was triggered by user interaction,
+ * {@code false} otherwise
+ */
public ColumnVisibilityChangeEvent(Column<?, T> column, boolean hidden,
boolean userOriginated) {
this.column = column;
* Handler for a Grid column visibility change event, called when the Grid's
* columns have changed visibility to hidden or visible.
*
- * @param<T> The
- * row type of the grid. The row type is the POJO type from where
- * the data is retrieved into the column cells.
+ * @param <T>
+ * The row type of the grid. The row type is the POJO type from where
+ * the data is retrieved into the column cells.
*
* @since 7.5.0
* @author Vaadin Ltd
*/
public class GridClickEvent extends AbstractGridMouseEvent<GridClickHandler> {
+ /** DOM event type. */
public static final Type<GridClickHandler> TYPE = new Type<GridClickHandler>(
BrowserEvents.CLICK, new GridClickEvent());
/**
* @deprecated This constructor's arguments are no longer used. Use the
* no-args constructor instead.
+ *
+ * @param grid
+ * the grid the event occurred in, not used
+ * @param targetCell
+ * the cell the event targets, not used
*/
@Deprecated
public GridClickEvent(Grid<?> grid, CellReference<?> targetCell) {
public class GridDoubleClickEvent
extends AbstractGridMouseEvent<GridDoubleClickHandler> {
+ /** DOM event type. */
public static final Type<GridDoubleClickHandler> TYPE = new Type<GridDoubleClickHandler>(
BrowserEvents.DBLCLICK, new GridDoubleClickEvent());
/**
* @deprecated This constructor's arguments are no longer used. Use the
* no-args constructor instead.
+ *
+ * @param grid
+ * the grid the event occurred in, not used
+ * @param targetCell
+ * the cell the event targets, not used
*/
@Deprecated
public GridDoubleClickEvent(Grid<?> grid, CellReference<?> targetCell) {
public static final Type<GridEnabledHandler> TYPE = new Type<>();
private final boolean enabled;
+ /**
+ * Constructs an event that informs about Grid's enabled status change.
+ *
+ * @param enabled
+ * {@code true} if the Grid is now enabled, {@code false} if the
+ * Grid is now disabled
+ */
public GridEnabledEvent(boolean enabled) {
this.enabled = enabled;
}
*/
public class GridKeyDownEvent extends AbstractGridKeyEvent<GridKeyDownHandler> {
+ /** DOM event type. */
public static final Type<GridKeyDownHandler> TYPE = new Type<GridKeyDownHandler>(
BrowserEvents.KEYDOWN, new GridKeyDownEvent());
/**
* @deprecated This constructor's arguments are no longer used. Use the
* no-args constructor instead.
+ *
+ * @param grid
+ * the grid the event occurred in, not used
+ * @param targetCell
+ * the cell the event targets, not used
*/
@Deprecated
public GridKeyDownEvent(Grid<?> grid, CellReference<?> targetCell) {
public class GridKeyPressEvent
extends AbstractGridKeyEvent<GridKeyPressHandler> {
+ /** DOM event type. */
public static final Type<GridKeyPressHandler> TYPE = new Type<GridKeyPressHandler>(
BrowserEvents.KEYPRESS, new GridKeyPressEvent());
/**
* @deprecated This constructor's arguments are no longer used. Use the
* no-args constructor instead.
+ *
+ * @param grid
+ * the grid the event occurred in, not used
+ * @param targetCell
+ * the cell the event targets, not used
*/
@Deprecated
public GridKeyPressEvent(Grid<?> grid, CellReference<?> targetCell) {
*/
public class GridKeyUpEvent extends AbstractGridKeyEvent<GridKeyUpHandler> {
+ /** DOM event type. */
public static final Type<GridKeyUpHandler> TYPE = new Type<GridKeyUpHandler>(
BrowserEvents.KEYUP, new GridKeyUpEvent());
/**
* @deprecated This constructor's arguments are no longer used. Use the
* no-args constructor instead.
+ *
+ * @param grid
+ * the grid the event occurred in, not used
+ * @param targetCell
+ * the cell the event targets, not used
*/
@Deprecated
public GridKeyUpEvent(Grid<?> grid, CellReference<?> targetCell) {
* Handler for a Grid select all event, called when the Grid needs all rows in
* data source to be selected.
*
+ * @param <T>
+ * the type of the items in the Grid
+ *
* @since 7.4
* @author Vaadin Ltd
*/
/**
* Generic class to perform selections when clicking on cells in body of Grid.
*
+ * @param <T>
+ * the type of the items in the Grid
+ *
* @since 7.4
* @author Vaadin Ltd
*/
if (!grid.getSelectionModel().isSelectionAllowed()) {
return;
}
+ @SuppressWarnings("unchecked")
T row = (T) event.getTargetCell().getRow();
if (!grid.isSelected(row)) {
grid.select(row);
/**
* Marker interface for widgets that fires selection events.
*
+ * @param <T>
+ * the type of the items in the Grid
+ *
* @author Vaadin Ltd
* @since 7.4
*/
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.ui.CheckBox;
-import com.vaadin.client.VConsole;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.renderers.ClickableRenderer;
import com.vaadin.client.widget.grid.CellReference;
*
* @author Vaadin Ltd
* @param <T>
- * the type of the associated grid
+ * the type of the items in the associated Grid
* @since 7.4
*/
public class MultiSelectionRenderer<T>
event.cancel();
}
break;
+ default:
+ // NOP
+ break;
}
}
case Event.ONTOUCHCANCEL:
stop();
break;
+ default:
+ // NOP
+ break;
}
};
private final AutoScrollHandler autoScrollHandler = new AutoScrollHandler();
+ /**
+ * Constructs a renderer for a selection column with multi-selection
+ * CheckBoxes.
+ *
+ * @param grid
+ * the parent grid
+ */
public MultiSelectionRenderer(final Grid<T> grid) {
this.grid = grid;
}
+ getTheadElement().getOffsetHeight() + 1;
}
+ /**
+ * Checks whether the given row is selected.
+ *
+ * @param logicalRow
+ * logical index of the row to check
+ * @return {@code true} if the current selection model considers the row
+ * selected, {@code false} otherwise
+ */
protected boolean isSelected(final int logicalRow) {
return grid.isSelected(grid.getDataSource().getRow(logicalRow));
}
+ /**
+ * Updates selection status for the given row.
+ *
+ * @param logicalRow
+ * logical index of the row to update
+ * @param select
+ * {@code true} if the row should be marked selected,
+ * {@code false} otherwise
+ */
protected void setSelected(final int logicalRow, final boolean select) {
T row = grid.getDataSource().getRow(logicalRow);
if (select) {
/**
* Event object describing a change in Grid row selection state.
*
+ * @param <T>
+ * the type of the items in the Grid
+ *
* @since 7.4
* @author Vaadin Ltd
*/
* @author Vaadin Ltd.
*
* @param <T>
- * the type of the items to select
+ * the type of the items in the Grid
* @since 8.0
*/
public interface SelectionModel<T> {
+ /**
+ * Selection model that does not allow any selection.
+ *
+ * @param <T>
+ * the type of the items to select
+ */
public static class NoSelectionModel<T> implements SelectionModel<T> {
@Override
* A sort event, fired by the Grid when it needs its data source to provide data
* sorted in a specific manner.
*
+ * @param <T>
+ * The row type of the Grid. The row type is the POJO type from where
+ * the data is retrieved into the column cells.
+ *
* @since 7.4
* @author Vaadin Ltd
*/
* Handler for a Grid sort event, called when the Grid needs its data source to
* provide data sorted in a specific manner.
*
+ * @param <T>
+ * The row type of the Grid. The row type is the POJO type from where
+ * the data is retrieved into the column cells.
+ *
* @since 7.4
* @author Vaadin Ltd
*/
void validate(Movement other) {
if (!run || other.velocity > 0
&& Math.abs(velocity / other.velocity) < F_AXIS) {
- delta = offset = 0;
+ delta = 0;
+ offset = 0;
run = false;
}
}
/*-{
var vScroll = esc.@com.vaadin.client.widgets.Escalator::verticalScrollbar;
var vScrollElem = vScroll.@com.vaadin.client.widget.escalator.ScrollbarBundle::getElement()();
-
+
var hScroll = esc.@com.vaadin.client.widgets.Escalator::horizontalScrollbar;
var hScrollElem = hScroll.@com.vaadin.client.widget.escalator.ScrollbarBundle::getElement()();
-
+
return $entry(function(e) {
var target = e.target;
-
+
// in case the scroll event was native (i.e. scrollbars were dragged, or
// the scrollTop/Left was manually modified), the bundles have old cache
// values. We need to make sure that the caches are kept up to date.
return $entry(function(e) {
var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX;
var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY;
-
+
// Delta mode 0 is in pixels; we don't need to do anything...
-
+
// A delta mode of 1 means we're scrolling by lines instead of pixels
// We need to scale the number of lines by the default line height
if (e.deltaMode === 1) {
var brc = esc.@com.vaadin.client.widgets.Escalator::body;
deltaY *= brc.@com.vaadin.client.widgets.Escalator.AbstractRowContainer::getDefaultRowHeight()();
}
-
+
// Other delta modes aren't supported
if ((e.deltaMode !== undefined) && (e.deltaMode >= 2 || e.deltaMode < 0)) {
var msg = "Unsupported wheel delta mode \"" + e.deltaMode + "\"";
-
+
// Print warning message
esc.@com.vaadin.client.widgets.Escalator::logWarning(*)(msg);
}
-
+
// IE8 has only delta y
if (isNaN(deltaY)) {
deltaY = -0.5*e.wheelDelta;
}
-
+
@com.vaadin.client.widgets.Escalator.JsniUtil::moveScrollFromEvent(*)(esc, deltaX, deltaY, e);
});
}-*/;
*/
public enum AriaGridRole {
- ROW("row"), ROWHEADER("rowheader"), ROWGROUP("rowgroup"), GRIDCELL(
- "gridcell"), COLUMNHEADER("columnheader");
+ /**
+ * Aria role for grid row elements except within the header.
+ *
+ * @see AriaGridRole#ROWHEADER
+ */
+ ROW("row"),
+ /**
+ * Aria role for grid row elements within the header.
+ */
+ ROWHEADER("rowheader"),
+ /**
+ * Aria role for grid row group elements, i.e. each root element that
+ * contains all the rows per section (header, body, or footer).
+ */
+ ROWGROUP("rowgroup"),
+ /**
+ * Aria role for grid cell elements except within the header.
+ *
+ * @see AriaGridRole#COLUMNHEADER
+ */
+ GRIDCELL("gridcell"),
+ /**
+ * Aria role for grid column header cell elements.
+ */
+ COLUMNHEADER("columnheader");
private final String name;
}
}
+ /**
+ * A representation of the rows within a section (header, body, or footer).
+ */
public abstract class AbstractRowContainer implements RowContainer {
private EscalatorUpdater updater = EscalatorUpdater.NULL;
private int rows;
/**
- * The table section element ({@code <thead>}, {@code <tbody>} or
- * {@code <tfoot>}) the rows (i.e. <code><tr></code> tags) are
- * contained in.
+ * The table section element (<code><thead></code>,
+ * <code><tbody></code> or <code><tfoot></code>) the rows
+ * (i.e. <code><tr></code> tags) are contained in.
*/
protected final TableSectionElement root;
private boolean autodetectingRowHeightLater = false;
+ /**
+ * Constructs a row container that uses the given table section element
+ * as the root element for the rows.
+ *
+ * @param rowContainerElement
+ * the table section element
+ */
public AbstractRowContainer(
final TableSectionElement rowContainerElement) {
root = rowContainerElement;
}
+ /**
+ * Checks validity of the given arguments for a row range that needs
+ * handling. Throws an exception if the arguments are not valid.
+ *
+ * @param index
+ * the start index of the range
+ * @param numberOfRows
+ * the number of rows within the range
+ * @throws IllegalArgumentException
+ * if the range doesn't have a positive length
+ * @throws IndexOutOfBoundsException
+ * if the entire range doesn't fit within the existing rows
+ */
protected void assertArgumentsAreValidAndWithinRange(final int index,
final int numberOfRows)
throws IllegalArgumentException, IndexOutOfBoundsException {
protected abstract void paintInsertRows(final int visualIndex,
final int numberOfRows);
+ /**
+ * Add static rows into the DOM. Usually this would be considered to
+ * mean only header or footer rows, but the body row container
+ * implementation also uses this method to get a starting point for
+ * further modifications.
+ *
+ * @param visualIndex
+ * the DOM index to add rows into
+ * @param numberOfRows
+ * the number of rows to insert
+ * @return a list of added row elements
+ */
protected List<TableRowElement> paintInsertStaticRows(
final int visualIndex, final int numberOfRows) {
assert isAttached() : "Can't paint rows if Escalator is not attached";
return elem;
}
+ /**
+ * Triggers section height calculation. Does nothing by default if
+ * called for the body row section, because body section height handling
+ * has more complicated logic. Note that updating header or footer
+ * height triggers a check that the body has correct amount of rows and
+ * their spacers.
+ */
protected abstract void recalculateSectionHeight();
/**
* Returns the height of all rows in the row container.
+ *
+ * @return total height of container's rows
*/
protected double calculateTotalRowHeight() {
return getDefaultRowHeight() * getRowCount();
refreshCells(rowRange, colRange);
}
+ /**
+ * Refresh cells within the given row and column ranges.
+ *
+ * @param logicalRowRange
+ * the range within the logical row indexes
+ * @param colRange
+ * the range within the column indexes
+ */
protected abstract void refreshCells(Range logicalRowRange,
Range colRange);
protected abstract TableRowElement getTrByVisualIndex(int index)
throws IndexOutOfBoundsException;
+ /**
+ * Remove the given number of columns starting from the given index.
+ *
+ * @param offset
+ * the index of the first column to remove
+ * @param numberOfColumns
+ * the number of columns to remove
+ */
protected void paintRemoveColumns(final int offset,
final int numberOfColumns) {
for (int i = 0; i < getDomRowCount(); i++) {
}
}
+ /**
+ * Add the given number of columns starting from the given index. Frozen
+ * columns shouldn't be added after non-frozen columns.
+ *
+ * @param offset
+ * the index of the first column to add
+ * @param numberOfColumns
+ * the number of columns to add
+ * @param frozen
+ * {@code true} if the added columns should be frozen,
+ * {@code false} otherwise
+ */
protected void paintInsertColumns(final int offset,
final int numberOfColumns, boolean frozen) {
assert flyweightRow.teardown();
}
+ /**
+ * Sets a column's frozen status. Frozen columns shouldn't be added
+ * after non-frozen columns.
+ *
+ * @param column
+ * the index of the column
+ * @param frozen
+ * {@code true} if the column should be frozen, {@code false}
+ * otherwise
+ */
public void setColumnFrozen(int column, boolean frozen) {
toggleFrozenColumnClass(column, frozen, "frozen");
}
}
+ /**
+ * Sets the last frozen state of the given column.
+ *
+ * @param column
+ * the index of the column
+ * @param lastFrozen
+ * {@code true} if the column is the last frozen one,
+ * {@code false} otherwise
+ */
public void setColumnLastFrozen(int column, boolean lastFrozen) {
toggleFrozenColumnClass(column, lastFrozen, "last-frozen");
}
+ /**
+ * Updates the freeze position for the given column.
+ *
+ * @param column
+ * the index of the column
+ * @param scrollLeft
+ * the x coordinate, in pixels
+ */
public void updateFreezePosition(int column, double scrollLeft) {
final NodeList<TableRowElement> childRows = root.getRows();
*/
protected abstract void reapplyDefaultRowHeights();
+ /**
+ * Updates the cells within the row to the given height.
+ *
+ * @param tr
+ * the row to update
+ * @param heightPx
+ * the height to set, in pixels
+ */
protected void reapplyRowHeight(final TableRowElement tr,
final double heightPx) {
assert heightPx >= 0 : "Height must not be negative";
*/
}
+ /**
+ * Updates the position of the given row to the given coordinates.
+ *
+ * @param tr
+ * the row to update
+ * @param x
+ * the x coordinate, in pixels
+ * @param y
+ * the y coordinate, in pixels
+ */
protected void setRowPosition(final TableRowElement tr, final int x,
final double y) {
positions.set(tr, x, y);
return positions.getTop(tr);
}
+ /**
+ * Removes the given row from the position bookkeeping.
+ *
+ * @param tr
+ * the row to remove
+ */
protected void removeRowPosition(TableRowElement tr) {
positions.remove(tr);
}
* Sets a new row index for this spacer. Also updates the
* bookkeeping at {@link SpacerContainer#rowIndexToSpacer}.
*/
- @SuppressWarnings("boxing")
public void setRowIndex(int rowIndex) {
SpacerImpl spacer = rowIndexToSpacer.remove(this.rowIndex);
assert this == spacer : "trying to move an unexpected spacer.";
}
}
- @SuppressWarnings("boxing")
+ /**
+ * @deprecated This method is no longer used by Escalator and is likely
+ * to be removed soon. Use
+ * {@link Escalator#scrollToSpacer(int, ScrollDestination, int)}
+ * instead
+ *
+ * @param spacerIndex
+ * the index of the logical row to scroll to, -1 takes the
+ * topmost spacer into account as well
+ * @param destination
+ * where the row should be aligned visually after scrolling
+ * @param padding
+ * the number pixels to place between the scrolled-to row and
+ * the viewport edge
+ */
+ @Deprecated
void scrollToSpacer(int spacerIndex, ScrollDestination destination,
int padding) {
* @param removedRange
* logical range of spacers to remove
*/
- @SuppressWarnings("boxing")
public void removeSpacers(Range removedRange) {
Map<Integer, SpacerImpl> removedSpacers = rowIndexToSpacer.subMap(
* @return the sum of all spacers from {@code logicalRowIndex} and
* onwards, or 0 if no suitable spacers were found
*/
- @SuppressWarnings("boxing")
public Collection<SpacerImpl> getSpacersForRowAndAfter(
int logicalRowIndex) {
return new ArrayList<>(
* a logical row index
* @return the pixels occupied by spacers up until {@code logicalIndex}
*/
- @SuppressWarnings("boxing")
public double getSpacerHeightsSumUntilIndex(int logicalIndex) {
return getHeights(
rowIndexToSpacer.headMap(logicalIndex, false).values());
return rowIndexToSpacer.containsKey(Integer.valueOf(rowIndex));
}
- @SuppressWarnings("boxing")
private void insertNewSpacer(int rowIndex, double height) {
if (spacerScrollerRegistration == null) {
return body.getRowTop(logicalIndex) + body.getDefaultRowHeight();
}
- @SuppressWarnings("boxing")
private void shiftSpacerPositionsAfterRow(int changedRowIndex,
double diffPx) {
for (SpacerImpl spacer : rowIndexToSpacer
this.indices = indices;
}
+ /**
+ * Returns type of the element, e.g. "header", "cell", or "spacer".
+ *
+ * @return type
+ */
public String getType() {
return type;
}
+ /**
+ * Returns how many indices there are within these arguments.
+ *
+ * @return index count
+ */
public int getIndicesLength() {
return indices.length;
}
+ /**
+ * Returns the indicated index within the indices array.
+ *
+ * @param i
+ * the index of the required member of the indices array
+ * @return the indicated index
+ */
public int getIndex(int i) {
return indices[i];
}
+ /**
+ * Returns indices that define which particular element is being
+ * targeted. If the array is empty, the target is the row container
+ * itself.
+ * <p>
+ * result[0] - index of a row element <br>
+ * result[1] - column index of a cell within that row <br>
+ * result[2..n] - child index within the previous element <br>
+ * <p>
+ * Spacer types should have exactly one index, which is for row index,
+ * and targets the spacer element of that row.
+ * <p>
+ * Editor types can have one index, which is for column index of a cell
+ * within the editor row. If no index is given, the target is the editor
+ * overlay itself.
+ *
+ * @return array of indices
+ */
public int[] getIndices() {
return Arrays.copyOf(indices, indices.length);
}
* @since 7.4
* @author Vaadin Ltd
*/
+@SuppressWarnings("deprecation")
public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
SubPartAware, DeferredWorker, Focusable,
com.google.gwt.user.client.ui.Focusable, HasWidgets, HasEnabled {
return (String) content;
}
+ /**
+ * Returns the section where this cell belongs.
+ *
+ * @return the section
+ */
protected StaticSection<?> getSection() {
assert section != null;
return section;
}
+ /**
+ * Sets the section where this cell belongs. Should not be null.
+ *
+ * @param section
+ * the section to set
+ */
protected void setSection(StaticSection<?> section) {
this.section = section;
}
* @return The remaining visible cell after the merge, or the first
* cell if all columns are hidden
*/
+ @SuppressWarnings("unchecked")
public CELLTYPE join(CELLTYPE... cells) {
if (cells.length <= 1) {
throw new IllegalArgumentException(
return null;
}
+ /**
+ * Returns the size of the cell group for the given column. Zero if
+ * no cell group is set.
+ *
+ * @param column
+ * the column whose cell group size is being investigated
+ * @return size of the cell group, default is {@code 0}
+ */
protected int getSizeOfCellGroup(Column<?, ?> column) {
for (Entry<CELLTYPE, Set<Column<?, ?>>> entry : cellGroups
.entrySet()) {
return false;
}
+ /**
+ * Creates and adds a cell to this row for the given column.
+ *
+ * @param column
+ * the column that requires a new cell
+ */
protected void addCell(Column<?, ?> column) {
CELLTYPE cell = createCell();
cell.setSection(getSection());
cells.put(column, cell);
}
+ /**
+ * Removes a cell for the given column from this row.
+ *
+ * @param column
+ * the column that should have its cell reference cleared
+ */
protected void removeCell(Column<?, ?> column) {
cells.remove(column);
}
+ /**
+ * Creates a cell of a type that matches this row.
+ *
+ * @return a new cell
+ */
protected abstract CELLTYPE createCell();
+ /**
+ * Returns the section where this row belongs.
+ *
+ * @return the section
+ */
protected StaticSection<?> getSection() {
return section;
}
+ /**
+ * Sets the section where this row belongs. Should not be null.
+ *
+ * @param section
+ * the section to set
+ */
protected void setSection(StaticSection<?> section) {
this.section = section;
}
return rows.size();
}
+ /**
+ * Returns the current list of rows within this section.
+ *
+ * @return list of rows
+ */
protected List<ROWTYPE> getRows() {
return rows;
}
+ /**
+ * Returns how many visible rows there are within this section (all or
+ * nothing, visibility cannot be set on the row level).
+ *
+ * @return amount of visible rows
+ */
protected int getVisibleRowCount() {
return isVisible() ? getRowCount() : 0;
}
+ /**
+ * Adds cells for the given column to all the rows within this section.
+ *
+ * @param column
+ * the column that requires cells
+ */
protected void addColumn(Column<?, ?> column) {
for (ROWTYPE row : rows) {
row.addCell(column);
}
}
+ /**
+ * Removes cells for the given column from all the rows within this
+ * section.
+ *
+ * @param column
+ * the column that should have its cells removed
+ */
protected void removeColumn(Column<?, ?> column) {
for (ROWTYPE row : rows) {
row.removeCell(column);
}
}
+ /**
+ * Sets the grid this section belongs to. Should not be null.
+ *
+ * @param grid
+ * the parent grid
+ */
protected void setGrid(Grid<?> grid) {
this.grid = grid;
}
+ /**
+ * Returns the grid this section belongs to.
+ *
+ * @return the parent grid
+ */
protected Grid<?> getGrid() {
assert grid != null;
return grid;
}
+ /**
+ * Triggers column span calculation for all the rows within this section
+ * that contain spanned cells.
+ */
protected void updateColSpans() {
for (ROWTYPE row : rows) {
if (row.hasSpannedCells()) {
private boolean isDefault = false;
+ /**
+ * Sets whether this is the default header row or not. Setting this
+ * value to {@code true} resets the cell contents for this row to column
+ * header captions. Setting this value to {@code false} doesn't update
+ * the cell contents.
+ *
+ * @param isDefault
+ * {@code true} if this row should be default header row,
+ * {@code false} otherwise
+ */
protected void setDefault(boolean isDefault) {
this.isDefault = isDefault;
if (isDefault) {
}
}
+ /**
+ * Returns whether this is the default header row or not.
+ *
+ * @return {@code true} if this row is the default header row,
+ * {@code false} otherwise
+ */
public boolean isDefault() {
return isDefault;
}
private EventCellReference<T> cell;
private boolean handled = false;
+ /**
+ * Constructs a new {@link GridEvent}.
+ *
+ * @param event
+ * a native event
+ * @param cell
+ * the cell the event targets
+ */
protected GridEvent(Event event, EventCellReference<T> cell) {
this.event = event;
this.cell = cell;
* marks this event as having already been handled.
*
* @param handled
+ * {@code true} if the event has already been handled,
+ * {@code false} otherwise
*/
public void setHandled(boolean handled) {
this.handled = handled;
private final Widget editorWidget;
+ /**
+ * Constructs a new {@link EditorDomEvent}.
+ *
+ * @param event
+ * a native event
+ * @param cell
+ * the cell the event targets
+ * @param editorWidget
+ * the editor widget of that cell
+ */
protected EditorDomEvent(Event event, EventCellReference<T> cell,
Widget editorWidget) {
super(event, cell);
*/
public static class Editor<T> implements DeferredWorker {
+ /**
+ * @deprecated use {@link DefaultEditorEventHandler#KEYCODE_OPEN}
+ * instead
+ */
+ @Deprecated
public static final int KEYCODE_SHOW = KeyCodes.KEY_ENTER;
+ /**
+ * @deprecated use {@link DefaultEditorEventHandler#KEYCODE_CLOSE}
+ * instead
+ */
+ @Deprecated
public static final int KEYCODE_HIDE = KeyCodes.KEY_ESCAPE;
private static final String ERROR_CLASS_NAME = "error";
void confirmValidity(boolean isValid);
}
+ /**
+ * The internal state options for the editor.
+ */
protected enum State {
- INACTIVE, ACTIVATING, BINDING, ACTIVE, SAVING
+ /** Editor is closed or disabled and as such not in edit mode. */
+ INACTIVE,
+ /**
+ * Editor is getting activated. If activation is successful, next
+ * state will be {@link State#BINDING} .
+ */
+ ACTIVATING,
+ /**
+ * Editor binding is being set up. If binding is successful, next
+ * state will be {@link State#ACTIVE}.
+ */
+ BINDING,
+ /** Editor is open and enabled and in edit mode. */
+ ACTIVE,
+ /**
+ * Editor is saving changes. If saving is successful, state will be
+ * updated to {@link State#INACTIVE}.
+ */
+ SAVING
}
private Grid<T> grid;
private double originalScrollTop;
private RowHandle<T> pinnedRowHandle;
+ /**
+ * Constructs a new {@link Editor}.
+ */
public Editor() {
saveButton = new Button();
saveButton.setText(GridConstants.DEFAULT_SAVE_CAPTION);
});
}
+ /**
+ * Sets an error message for the editor, or removes it if the given
+ * message is {@code null}. If the editor is in edit mode or currently
+ * processing a save operation, updates the editor cells to show error
+ * styles for the given columns and clears error styles from any other
+ * columns.
+ *
+ * @param errorMessage
+ * the message to set, or {@code null} if no message should
+ * be shown
+ * @param errorColumns
+ * the columns that currently contain errors
+ */
public void setEditorError(String errorMessage,
Collection<Column<?, T>> errorColumns) {
}
}
+ /**
+ * Returns the index of the row that is currently assigned to the
+ * editor. If the editor is open and in the edit mode, that row's
+ * contents can be edited via the editor cells. -1 if the editor is
+ * closed.
+ *
+ * @return currently assigned row index, or -1 if not set
+ */
public int getRow() {
return rowIndex;
}
* If a Grid cell was not focused prior to calling this method, it will
* be equivalent to {@code editRow(rowIndex, -1)}.
*
+ * @param rowIndex
+ * the index of the row to be edited
+ *
* @see #editRow(int, int)
*/
public void editRow(int rowIndex) {
handler = rowHandler;
}
+ /**
+ * Returns the enabled state of this editor.
+ *
+ * @return {@code true} if enabled, {@code false} otherwise
+ */
public boolean isEnabled() {
return enabled;
}
* Sets the enabled state of this editor.
*
* @param enabled
- * true if enabled, false otherwise
+ * {@code true} if enabled, {@code false} otherwise
*
* @throws IllegalStateException
* if in edit mode and trying to disable
this.enabled = enabled;
}
+ /**
+ * If the Editor is still activating, proceeds to the binding phase.
+ * Otherwise does nothing.
+ *
+ * @param rowIndex
+ * the index of the row to be edited
+ * @param columnIndex
+ * the column index (excluding hidden columns) of the editor
+ * widget that should be initially focused or -1 to not set
+ * focus
+ */
protected void show(int rowIndex, int columnIndex) {
if (state == State.ACTIVATING) {
state = State.BINDING;
}
}
+ /**
+ * Sets the grid this editor belongs to. Should not be null. Should only
+ * be called once.
+ *
+ * @param grid
+ * the parent grid
+ */
protected void setGrid(final Grid<T> grid) {
assert grid != null : "Grid cannot be null";
assert this.grid == null : "Can only attach editor to Grid once";
this.grid = grid;
}
+ /**
+ * Returns the internal state of the editor.
+ *
+ * @return the state
+ */
protected State getState() {
return state;
}
+ /**
+ * Sets the internal state of the editor.
+ *
+ * @param state
+ * the state to set
+ */
protected void setState(State state) {
this.state = state;
}
}
/**
- * Opens the editor overlay over the table row indicated by
+ * Opens the editor overlay over the grid row indicated by
* {@link #getRow()}.
*
* @since 7.5
return bottomOfButtons < tfootPageTop;
}
+ /**
+ * Hides the editor overlay and clears its contents.
+ */
protected void hideOverlay() {
if (editorOverlay.getParentElement() == null) {
return;
}
}
+ /**
+ * Sets the editor's primary style name and updates all dependent style
+ * names.
+ *
+ * @param primaryName
+ * the new primary style name
+ */
protected void setStylePrimaryName(String primaryName) {
if (styleName != null) {
editorOverlay.removeClassName(styleName);
editorOverlay.getStyle().setTop(newTop, Unit.PX);
}
+ /**
+ * Sets the editor's buttons enabled. Does not update the enabled status
+ * of the grid this editor belongs to, nor ask the enabled status from
+ * it.
+ *
+ * @param enabled
+ * {@code true} to enable the buttons, {@code false} to
+ * disable them
+ */
protected void setGridEnabled(boolean enabled) {
// TODO: This should be informed to handler as well so possible
// fields can be disabled.
cancelButton.setEnabled(enabled);
}
+ /**
+ * Sets the caption of the save button. Should not be {@code null}.
+ *
+ * @param saveCaption
+ * the new caption text
+ * @throws IllegalArgumentException
+ * if the given text is {@code null}
+ */
public void setSaveCaption(String saveCaption)
throws IllegalArgumentException {
if (saveCaption == null) {
saveButton.setText(saveCaption);
}
+ /**
+ * Returns the caption of the save button.
+ *
+ * @return the caption text
+ */
public String getSaveCaption() {
return saveButton.getText();
}
+ /**
+ * Sets the caption of the cancel button. Should not be {@code null}.
+ *
+ * @param cancelCaption
+ * the new caption text
+ * @throws IllegalArgumentException
+ * if the given text is {@code null}
+ */
public void setCancelCaption(String cancelCaption)
throws IllegalArgumentException {
if (cancelCaption == null) {
cancelButton.setText(cancelCaption);
}
+ /**
+ * Returns the caption of the cancel button.
+ *
+ * @return the caption text
+ */
public String getCancelCaption() {
return cancelButton.getText();
}
+ /**
+ * If the given column is indicated to have an error in the editor, sets
+ * the error styles to the corresponding editor cell and lists the
+ * column as having an error. Otherwise removes the error styles from
+ * the cell and removes the column from the error collection.
+ *
+ * @param column
+ * the column which should have its editor error status
+ * updated
+ * @param hasError
+ * {@code true} if the cell should get error styles,
+ * {@code false} if the error styles should be removed from
+ * the cell
+ */
public void setEditorColumnError(Column<?, T> column,
boolean hasError) {
if (state != State.ACTIVE && state != State.SAVING) {
}
}
+ /**
+ * Clears all editor error styles from the editor cells and clears the
+ * error column collection.
+ */
public void clearEditorColumnErrors() {
/*
columnErrors.clear();
}
+ /**
+ * Returns true if the column has been listed as containing an error.
+ *
+ * @param column
+ * the column whose error status is checked
+ * @return {@code true} if the column is listed as containing an error,
+ * {@code false} otherwise
+ */
public boolean isEditorColumnError(Column<?, T> column) {
return columnErrors.contains(column);
}
+ /**
+ * Sets the buffered mode. When the editor is in buffered mode, edits
+ * are only committed when the user clicks the save button. In
+ * unbuffered mode valid changes are automatically committed.
+ *
+ * @param buffered
+ * {@code true} if editor should be buffered, {@code false}
+ * otherwise
+ */
public void setBuffered(boolean buffered) {
this.buffered = buffered;
setMessageAndButtonsWrapperVisible(buffered);
}
+ /**
+ * Returns whether this editor is buffered or not.
+ *
+ * @return {@code true} if editor is buffered, {@code false} otherwise
+ *
+ * @see #setBuffered(boolean)
+ */
public boolean isBuffered() {
return buffered;
}
return saveTimeout.isRunning() || bindTimeout.isRunning();
}
+ /**
+ * Returns the column index of the editor cell that contains the given
+ * element, or -1 if the element can't be found within the editor cells.
+ *
+ * @param e
+ * the element to be located
+ * @return the column index of the associated editor cell, or -1 if not
+ * found
+ */
protected int getElementColumn(Element e) {
int frozenCells = frozenCellWrapper.getChildCount();
if (frozenCellWrapper.isOrHasChild(e)) {
}
}
+ /**
+ * Event class for key events that happen within the grid.
+ *
+ * @param <HANDLER>
+ * the event handler type
+ */
public abstract static class AbstractGridKeyEvent<HANDLER extends AbstractGridKeyEventHandler>
extends KeyEvent<HANDLER> {
}
/**
+ * @param grid
+ * the grid where the event occurred
+ * @param targetCell
+ * the cell that the event targeted
+ *
* @deprecated This constructor's arguments are no longer used. Use the
* no-args constructor instead.
*/
public AbstractGridKeyEvent(Grid<?> grid, CellReference<?> targetCell) {
}
+ /**
+ * Returns the {@link BrowserEvents} type that corresponds with this
+ * event.
+ *
+ * @return the browser event type
+ */
protected abstract String getBrowserEventType();
/**
}
}
+ /**
+ * The given handler processes the event if the handler type matches the
+ * given section.
+ *
+ * @param handler
+ * handler
+ * @param section
+ * the section where the target element is located
+ */
protected abstract void doDispatch(HANDLER handler, Section section);
}
+ /**
+ * Event class for mouse events that happen within the grid.
+ *
+ * @param <HANDLER>
+ * the event handler type
+ */
public abstract static class AbstractGridMouseEvent<HANDLER extends AbstractGridMouseEventHandler>
extends MouseEvent<HANDLER> {
}
/**
+ * @param grid
+ * the grid where the event occurred
+ * @param targetCell
+ * the cell that the event targeted
+ *
* @deprecated This constructor's arguments are no longer used. Use the
* no-args constructor instead.
*/
CellReference<?> targetCell) {
}
+ /**
+ * Returns the {@link BrowserEvents} type that corresponds with this
+ * event.
+ *
+ * @return the browser event type
+ */
protected abstract String getBrowserEventType();
/**
return childWidget && !handleWidgetEvent;
}
+ /**
+ * The given handler processes the event if the handler type matches the
+ * given section.
+ *
+ * @param handler
+ * handler
+ * @param section
+ * the section where the target element is located
+ */
protected abstract void doDispatch(HANDLER handler, Section section);
}
private EventCellReference<T> eventCell = new EventCellReference<T>(this);
+ /**
+ * Focus handler for Grid's cells. Updates focus style names and handles
+ * focus scrolling.
+ */
private class CellFocusHandler {
private RowContainer containerWithFocus = escalator.getBody();
}
}
+ /**
+ * A column that contains CheckBoxes for representing Grid's row selection.
+ * By default only used with MultiSelectionModel.
+ *
+ */
public final class SelectionColumn extends Column<Boolean, T>
implements GridEnabledHandler, GridSelectionAllowedHandler {
*/
private class AutoColumnWidthsRecalculator {
private double lastCalculatedInnerWidth = -1;
- private double lastCalculatedInnerHeight = -1;
private final ScheduledCommand calculateCommand = new ScheduledCommand() {
// Update latest width to prevent recalculate on height change.
lastCalculatedInnerWidth = escalator.getInnerWidth();
- lastCalculatedInnerHeight = escalator.getInnerHeight();
}
private boolean columnsAreGuaranteedToBeWiderThanGrid() {
return freeSpace < 0;
}
- @SuppressWarnings("boxing")
private void applyColumnWidths() {
/* Step 1: Apply all column widths as they are. */
*/
private SelectionModel<T> selectionModel;
+ /**
+ * Focus handler for Grid's cells. Updates focus style names and handles
+ * focus scrolling.
+ */
protected final CellFocusHandler cellFocusHandler;
private final UserSorter sorter = new UserSorter();
private RowStyleGenerator<T> rowStyleGenerator;
private RowReference<T> rowReference = new RowReference<>(this);
private CellReference<T> cellReference = new CellReference<>(rowReference);
+ @SuppressWarnings("unchecked")
private RendererCellReference rendererCellReference = new RendererCellReference(
(RowReference<Object>) rowReference);
.indexOf(getVisibleColumn(focusedCell.getColumn()));
}
+ @SuppressWarnings("unchecked")
Column<?, T>[] array = reordered
.toArray(new Column[reordered.size()]);
setColumnOrder(true, array);
transferCellFocusOnDrop();
- } // else
- // no
- // reordering
+ } // else no reordering
}
private void transferCellFocusOnDrop() {
}
}
- @SuppressWarnings("boxing")
private void calculatePossibleDropPositions() {
possibleDropPositions.clear();
// Complex renderers need to be destroyed.
if (bodyRenderer instanceof ComplexRenderer) {
- ((ComplexRenderer) bodyRenderer).destroy();
+ ((ComplexRenderer<? super C>) bodyRenderer).destroy();
}
bodyRenderer = renderer;
}
+ /**
+ * EscalatorUpdater implementation for Grid's body section.
+ *
+ * @see EscalatorUpdater
+ *
+ */
protected class BodyUpdater implements EscalatorUpdater {
@Override
}
@Override
+ @SuppressWarnings("unchecked")
public void update(Row row, Iterable<FlyweightCell> cellsToUpdate) {
int rowIndex = row.getRow();
TableRowElement rowElement = row.getElement();
setCustomStyleName(cell.getElement(), null);
}
+ @SuppressWarnings("rawtypes")
Renderer renderer = column.getRenderer();
try {
rendererCellReference.set(cell, columnIndex, column);
if (renderer instanceof ComplexRenderer) {
// Hide cell content if needed
- ComplexRenderer clxRenderer = (ComplexRenderer) renderer;
+ @SuppressWarnings("rawtypes")
+ ComplexRenderer clxRenderer = (ComplexRenderer<?>) renderer;
if (hasData) {
if (!usedToHaveData) {
// Prepare cell for rendering
cell.getColumn());
rendererCellReference.set(cell,
getColumns().indexOf(column), column);
- ((ComplexRenderer) renderer)
+ ((ComplexRenderer<?>) renderer)
.destroy(rendererCellReference);
} catch (RuntimeException e) {
getLogger().log(Level.SEVERE,
}
}
+ /**
+ * EscalatorUpdater implementation for Grid's static sections (header and
+ * footer).
+ *
+ * @see EscalatorUpdater
+ *
+ */
protected class StaticSectionUpdater implements EscalatorUpdater {
private StaticSection<?> section;
private RowContainer container;
+ /**
+ * Constructs an updater instance for the given section.
+ *
+ * @param section
+ * the section that needs an updater
+ * @param container
+ * the row container of the given section
+ */
public StaticSectionUpdater(StaticSection<?> section,
RowContainer container) {
super();
// Wrap text or html content in default header to isolate
// the content from the possible column resize drag handle
// next to it
- if (metadata.getType() != GridStaticCellType.WIDGET) {
+ GridStaticCellType metaDataType = metadata.getType();
+ if (metaDataType != GridStaticCellType.WIDGET) {
content = DOM.createDiv();
if (staticRow instanceof HeaderRow) {
content = td;
}
- switch (metadata.getType()) {
+ switch (metaDataType) {
case TEXT:
content.setInnerText(metadata.getText());
break;
content.setInnerHTML("");
postAttach(row, Arrays.asList(cell));
break;
+ default:
+ getLogger().severe("Unhandled metadata type: "
+ + (metaDataType == null ? "null"
+ : metaDataType.name()));
+ break;
}
// XXX: Should add only once in preAttach/postAttach or when
}
}
+ /**
+ * Returns the Grid instance for this updater.
+ *
+ * @return the grid that is being updated
+ */
+ @SuppressWarnings("rawtypes")
protected Grid getGrid() {
return section.grid;
}
* @param columns
* the columns to add
*/
+ @SuppressWarnings("unchecked")
public void addColumns(Column<?, T>... columns) {
if (columns.length == 0) {
// Nothing to add.
/**
* Adds a column as the last column in the grid.
*
+ * @param <C>
+ * class that extends Column
* @param column
* the column to add
* @return given column
/**
* Inserts a column into a specific position in the grid.
*
- * @param index
- * the index where the column should be inserted into
+ * @param <C>
+ * class that extends Column
* @param column
* the column to add
+ * @param index
+ * the index where the column should be inserted into
* @return given column
*
* @throws IllegalStateException
return footer.isVisible();
}
+ /**
+ * Returns the {@link Editor} for this Grid.
+ *
+ * @return editor
+ */
public Editor<T> getEditor() {
return editor;
}
return frozenColumnCount;
}
+ /**
+ * Adds an event handler that gets notified when the range of visible rows
+ * changes e.g. because of scrolling, row resizing or spacers
+ * appearing/disappearing.
+ *
+ * @param handler
+ * the event handler
+ * @return a handler registration for the added handler
+ */
public HandlerRegistration addRowVisibilityChangeHandler(
RowVisibilityChangeHandler handler) {
/*
};
@Override
- @SuppressWarnings("deprecation")
public com.google.gwt.user.client.Element getSubPartElement(
String subPart) {
}
@Override
- @SuppressWarnings("deprecation")
public String getSubPartName(
com.google.gwt.user.client.Element subElement) {
/**
* Sorts the Grid data in ascending order along one column.
*
+ * @param <C>
+ * the column type
* @param column
* a grid column reference
*/
/**
* Sorts the Grid data along one column.
*
+ * @param <C>
+ * the column type
* @param column
* a grid column reference
* @param direction
*
* @param handler
* a sort event handler
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addSortHandler(SortHandler<T> handler) {
return addHandler(handler, SortEvent.getType());
*
* @param handler
* a select all event handler
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addSelectAllHandler(
SelectAllHandler<T> handler) {
*
* @param handler
* a data available event handler
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addDataAvailableHandler(
final DataAvailableHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addBodyKeyDownHandler(
BodyKeyDownHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addBodyKeyUpHandler(BodyKeyUpHandler handler) {
return addHandler(handler, GridKeyUpEvent.TYPE);
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addBodyKeyPressHandler(
BodyKeyPressHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addHeaderKeyDownHandler(
HeaderKeyDownHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addHeaderKeyUpHandler(
HeaderKeyUpHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addHeaderKeyPressHandler(
HeaderKeyPressHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addFooterKeyDownHandler(
FooterKeyDownHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addFooterKeyUpHandler(
FooterKeyUpHandler handler) {
*
* @param handler
* the key handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addFooterKeyPressHandler(
FooterKeyPressHandler handler) {
*
* @param handler
* the click handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addBodyClickHandler(BodyClickHandler handler) {
return addHandler(handler, GridClickEvent.TYPE);
*
* @param handler
* the click handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addHeaderClickHandler(
HeaderClickHandler handler) {
*
* @param handler
* the click handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addFooterClickHandler(
FooterClickHandler handler) {
*
* @param handler
* the double click handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addBodyDoubleClickHandler(
BodyDoubleClickHandler handler) {
*
* @param handler
* the double click handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addHeaderDoubleClickHandler(
HeaderDoubleClickHandler handler) {
*
* @param handler
* the double click handler to register
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addFooterDoubleClickHandler(
FooterDoubleClickHandler handler) {
* @since 7.5.0
* @param handler
* the handler for the event
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addColumnReorderHandler(
ColumnReorderHandler<T> handler) {
* @since 7.5.0
* @param handler
* the handler for the event
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addColumnVisibilityChangeHandler(
ColumnVisibilityChangeHandler<T> handler) {
* @since 7.6
* @param handler
* the handler for the event
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addColumnResizeHandler(
ColumnResizeHandler<T> handler) {
*
* @param handler
* the handler for the event
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addEnabledHandler(GridEnabledHandler handler) {
return addHandler(handler, GridEnabledEvent.TYPE);
*
* @param handler
* the handler for the event
- * @return the registration for the event
+ * @return the registration for the handler
*/
public HandlerRegistration addSelectionAllowedHandler(
GridSelectionAllowedHandler handler) {
return addHandler(handler, GridSelectionAllowedEvent.TYPE);
}
+ /**
+ * Register a row height changed handler to this Grid. The event for this
+ * handler is fired when the row height is changed in the Grid's header,
+ * body or footer.
+ *
+ * @param handler
+ * the handler for the event
+ * @return the registration for the handler
+ */
public HandlerRegistration addRowHeightChangedHandler(
RowHeightChangedHandler handler) {
return escalator.addHandler(handler, RowHeightChangedEvent.TYPE);
* @param orderedColumns
* array of columns in wanted order
*/
+ @SuppressWarnings("unchecked")
public void setColumnOrder(Column<?, T>... orderedColumns) {
setColumnOrder(false, orderedColumns);
}
+ @SuppressWarnings("unchecked")
private void setColumnOrder(boolean isUserOriginated,
Column<?, T>... orderedColumns) {
List<Column<?, T>> newOrder = new ArrayList<>();
* @return Extended component.
*/
@Override
- @SuppressWarnings("unchecked")
public T getParent() {
return super.getParent();
}
private class FileReceiver implements StreamVariable {
- private final String id;
private Html5File file;
public FileReceiver(String id, Html5File file) {
- this.id = id;
this.file = file;
}