Browse Source

Checkstyle fixes (#12339)

- 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.
tags/8.14.0.alpha1
Anna Koskinen 2 years ago
parent
commit
512703d56c
No account linked to committer's email address
52 changed files with 1177 additions and 88 deletions
  1. 8
    0
      client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
  2. 3
    5
      client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java
  3. 0
    4
      client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
  4. 3
    3
      client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
  5. 1
    0
      client/src/main/java/com/vaadin/client/connectors/grid/TreeRendererConnector.java
  6. 3
    0
      client/src/main/java/com/vaadin/client/connectors/grid/UnsafeHtmlRendererConnector.java
  7. 13
    0
      client/src/main/java/com/vaadin/client/renderers/ButtonRenderer.java
  8. 2
    0
      client/src/main/java/com/vaadin/client/renderers/ClickableRenderer.java
  9. 3
    0
      client/src/main/java/com/vaadin/client/renderers/ComplexRenderer.java
  10. 15
    0
      client/src/main/java/com/vaadin/client/renderers/DateRenderer.java
  11. 9
    0
      client/src/main/java/com/vaadin/client/renderers/HierarchyRenderer.java
  12. 1
    0
      client/src/main/java/com/vaadin/client/renderers/ImageRenderer.java
  13. 9
    0
      client/src/main/java/com/vaadin/client/renderers/NumberRenderer.java
  14. 3
    1
      client/src/main/java/com/vaadin/client/renderers/WidgetRenderer.java
  15. 26
    0
      client/src/main/java/com/vaadin/client/widget/escalator/FlyweightCell.java
  16. 30
    0
      client/src/main/java/com/vaadin/client/widget/escalator/FlyweightRow.java
  17. 45
    0
      client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java
  18. 2
    0
      client/src/main/java/com/vaadin/client/widget/escalator/Spacer.java
  19. 5
    0
      client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedEvent.java
  20. 5
    0
      client/src/main/java/com/vaadin/client/widget/escalator/events/SpacerIndexChangedEvent.java
  21. 5
    0
      client/src/main/java/com/vaadin/client/widget/escalator/events/SpacerVisibilityChangedEvent.java
  22. 15
    0
      client/src/main/java/com/vaadin/client/widget/grid/AutoScroller.java
  23. 6
    0
      client/src/main/java/com/vaadin/client/widget/grid/CellReference.java
  24. 7
    0
      client/src/main/java/com/vaadin/client/widget/grid/DataAvailableEvent.java
  25. 40
    0
      client/src/main/java/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java
  26. 18
    2
      client/src/main/java/com/vaadin/client/widget/grid/EventCellReference.java
  27. 1
    0
      client/src/main/java/com/vaadin/client/widget/grid/RendererCellReference.java
  28. 4
    0
      client/src/main/java/com/vaadin/client/widget/grid/datasources/ListDataSource.java
  29. 11
    0
      client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java
  30. 30
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/AbstractGridKeyEventHandler.java
  31. 18
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/AbstractGridMouseEventHandler.java
  32. 16
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/ColumnReorderEvent.java
  33. 8
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/ColumnResizeEvent.java
  34. 17
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeEvent.java
  35. 3
    3
      client/src/main/java/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeHandler.java
  36. 6
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/GridClickEvent.java
  37. 6
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java
  38. 7
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledEvent.java
  39. 6
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/GridKeyDownEvent.java
  40. 6
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/GridKeyPressEvent.java
  41. 6
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/GridKeyUpEvent.java
  42. 3
    0
      client/src/main/java/com/vaadin/client/widget/grid/events/SelectAllHandler.java
  43. 4
    0
      client/src/main/java/com/vaadin/client/widget/grid/selection/ClickSelectHandler.java
  44. 3
    0
      client/src/main/java/com/vaadin/client/widget/grid/selection/HasSelectionHandlers.java
  45. 31
    2
      client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
  46. 3
    0
      client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionEvent.java
  47. 7
    1
      client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModel.java
  48. 4
    0
      client/src/main/java/com/vaadin/client/widget/grid/sort/SortEvent.java
  49. 4
    0
      client/src/main/java/com/vaadin/client/widget/grid/sort/SortHandler.java
  50. 213
    22
      client/src/main/java/com/vaadin/client/widgets/Escalator.java
  51. 483
    42
      client/src/main/java/com/vaadin/client/widgets/Grid.java
  52. 0
    3
      server/src/main/java/com/vaadin/ui/dnd/FileDropTarget.java

+ 8
- 0
client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java View File

@@ -38,6 +38,9 @@ import elemental.json.JsonValue;
@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> {

@@ -48,6 +51,11 @@ public class ColumnConnector extends AbstractExtensionConnector {
this.connectorId = connectorId;
}

/**
* Returns the id for the corresponding connector.
*
* @return the id for the connector
*/
public String getConnectorId() {
return connectorId;
}

+ 3
- 5
client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java View File

@@ -17,7 +17,6 @@ package com.vaadin.client.connectors.grid;

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;
@@ -28,7 +27,6 @@ import com.vaadin.client.ConnectorMap;
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;
@@ -119,9 +117,9 @@ public class ComponentRendererConnector
}

private void unregisterHierarchyHandler() {
if (this.handlerRegistration != null) {
this.handlerRegistration.removeHandler();
this.handlerRegistration = null;
if (handlerRegistration != null) {
handlerRegistration.removeHandler();
handlerRegistration = null;
}
}


+ 0
- 4
client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java View File

@@ -47,9 +47,6 @@ import elemental.json.JsonObject;
@Connect(EditorImpl.class)
public class EditorConnector extends AbstractExtensionConnector {

private Integer currentEditedRow = null;
private boolean waitingForAvailableData = false;

/**
* EditorHandler for communicating with the server-side implementation.
*/
@@ -132,7 +129,6 @@ public class EditorConnector extends AbstractExtensionConnector {
// a confirmation from the server
rpc.cancel(afterBeingSaved);
}
currentEditedRow = null;
}

@Override

+ 3
- 3
client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java View File

@@ -497,7 +497,7 @@ public class GridConnector extends AbstractListingConnector
}

private void updateStaticRow(RowState rowState,
Grid.StaticSection.StaticRow row) {
Grid.StaticSection.StaticRow<?> row) {
rowState.cells
.forEach((columnId, cellState) -> updateStaticCellFromState(
row.getCell(getColumn(columnId)), cellState));
@@ -794,11 +794,11 @@ public class GridConnector extends AbstractListingConnector
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) {

+ 1
- 0
client/src/main/java/com/vaadin/client/connectors/grid/TreeRendererConnector.java View File

@@ -33,6 +33,7 @@ import elemental.json.JsonObject;
* @author Vaadin Ltd
* @since 8.1
*/
@SuppressWarnings("deprecation")
@Connect(TreeRenderer.class)
public class TreeRendererConnector
extends AbstractGridRendererConnector<String> {

+ 3
- 0
client/src/main/java/com/vaadin/client/connectors/grid/UnsafeHtmlRendererConnector.java View File

@@ -30,6 +30,9 @@ import com.vaadin.shared.ui.grid.renderers.HtmlRendererState;
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) {

+ 13
- 0
client/src/main/java/com/vaadin/client/renderers/ButtonRenderer.java View File

@@ -39,10 +39,23 @@ public class ButtonRenderer extends ClickableRenderer<String, Button> {
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;
}

+ 2
- 0
client/src/main/java/com/vaadin/client/renderers/ClickableRenderer.java View File

@@ -211,6 +211,8 @@ public abstract class ClickableRenderer<T, W extends Widget>
*
* @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) {

+ 3
- 0
client/src/main/java/com/vaadin/client/renderers/ComplexRenderer.java View File

@@ -37,6 +37,9 @@ import com.vaadin.client.widget.grid.RendererCellReference;
* 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
*/

+ 15
- 0
client/src/main/java/com/vaadin/client/renderers/DateRenderer.java View File

@@ -37,14 +37,29 @@ public class DateRenderer implements Renderer<Date> {
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);
}

+ 9
- 0
client/src/main/java/com/vaadin/client/renderers/HierarchyRenderer.java View File

@@ -91,6 +91,7 @@ public class HierarchyRenderer extends ClickableRenderer<Object, Widget> {
private static final String CLASS_EXPANDED = "expanded";
private static final String CLASS_DEPTH = "depth-";

@SuppressWarnings("rawtypes")
private Renderer innerRenderer;

/**
@@ -148,6 +149,7 @@ public class HierarchyRenderer extends ClickableRenderer<Object, Widget> {
return new HierarchyItem(nodeStyleName);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void render(RendererCellReference cell, Object data, Widget widget) {

@@ -234,6 +236,7 @@ public class HierarchyRenderer extends ClickableRenderer<Object, Widget> {
* @param innerRenderer
* Renderer to be wrapped.
*/
@SuppressWarnings("rawtypes")
public void setInnerRenderer(Renderer innerRenderer) {
this.innerRenderer = innerRenderer;
}
@@ -243,12 +246,18 @@ public class HierarchyRenderer extends ClickableRenderer<Object, Widget> {
*
* @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);

+ 1
- 0
client/src/main/java/com/vaadin/client/renderers/ImageRenderer.java View File

@@ -29,6 +29,7 @@ import com.vaadin.client.widget.grid.RendererCellReference;
*/
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

+ 9
- 0
client/src/main/java/com/vaadin/client/renderers/NumberRenderer.java View File

@@ -30,10 +30,19 @@ public class NumberRenderer implements Renderer<Number> {

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);
}

+ 3
- 1
client/src/main/java/com/vaadin/client/renderers/WidgetRenderer.java View File

@@ -26,7 +26,7 @@ import com.vaadin.client.widget.grid.RendererCellReference;
* @since 7.4
* @author Vaadin Ltd
* @param <T>
* the row data type
* the column data type
* @param <W>
* the Widget type
*/
@@ -96,6 +96,8 @@ public abstract class WidgetRenderer<T, W extends Widget>
* 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

+ 26
- 0
client/src/main/java/com/vaadin/client/widget/escalator/FlyweightCell.java View File

@@ -38,6 +38,7 @@ import com.vaadin.client.widgets.Escalator;
* @author Vaadin Ltd
*/
public class FlyweightCell {
/** The column span property name. */
public static final String COLSPAN_ATTR = "colSpan";

private final int column;
@@ -46,6 +47,17 @@ public class FlyweightCell {
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;
@@ -53,6 +65,8 @@ public class FlyweightCell {

/**
* Returns the row index of the cell.
*
* @return the row index
*/
public int getRow() {
assertSetup();
@@ -61,6 +75,8 @@ public class FlyweightCell {

/**
* Returns the column index of the cell.
*
* @return the column index
*/
public int getColumn() {
assertSetup();
@@ -70,6 +86,8 @@ public class FlyweightCell {
/**
* 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();
@@ -78,6 +96,8 @@ public class FlyweightCell {

/**
* Return the colspan attribute of the element of the cell.
*
* @return the colspan attribute
*/
public int getColSpan() {
assertSetup();
@@ -148,6 +168,12 @@ public class FlyweightCell {
+ "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(

+ 30
- 0
client/src/main/java/com/vaadin/client/widget/escalator/FlyweightRow.java View File

@@ -144,6 +144,18 @@ public class FlyweightRow implements Row {
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;
@@ -186,6 +198,15 @@ public class FlyweightRow implements Row {
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;
@@ -194,6 +215,15 @@ public class FlyweightRow implements Row {
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);

+ 45
- 0
client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java View File

@@ -111,6 +111,7 @@ public abstract class ScrollbarBundle implements DeferredWorker {
* The orientation of the scrollbar.
*/
public enum Direction {
/** Scrollbar orientation, indicated by the name. */
VERTICAL, HORIZONTAL;
}

@@ -147,8 +148,12 @@ public abstract class ScrollbarBundle implements DeferredWorker {
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() {
@@ -335,8 +340,14 @@ public abstract class ScrollbarBundle implements DeferredWorker {
}
}

/** 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;
@@ -362,6 +373,12 @@ public abstract class ScrollbarBundle implements DeferredWorker {
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();

/**
@@ -495,6 +512,10 @@ public abstract class ScrollbarBundle implements DeferredWorker {
* 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) {
@@ -512,6 +533,15 @@ public abstract class ScrollbarBundle implements DeferredWorker {
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);

/**
@@ -523,6 +553,12 @@ public abstract class ScrollbarBundle implements DeferredWorker {
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();

/**
@@ -765,6 +801,10 @@ public abstract class ScrollbarBundle implements DeferredWorker {
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();
@@ -804,6 +844,11 @@ public abstract class ScrollbarBundle implements DeferredWorker {
}
}

/**
* Returns the handler manager for this scrollbar bundle.
*
* @return the handler manager
*/
protected HandlerManager getHandlerManager() {
if (handlerManager == null) {
handlerManager = new HandlerManager(this);

+ 2
- 0
client/src/main/java/com/vaadin/client/widget/escalator/Spacer.java View File

@@ -35,6 +35,8 @@ public interface Spacer {

/**
* Gets the decorative element for this spacer.
*
* @return the decorative element
*/
Element getDecoElement();


+ 5
- 0
client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedEvent.java View File

@@ -31,6 +31,11 @@ public class RowHeightChangedEvent extends GwtEvent<RowHeightChangedHandler> {
*/
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;
}

+ 5
- 0
client/src/main/java/com/vaadin/client/widget/escalator/events/SpacerIndexChangedEvent.java View File

@@ -31,6 +31,11 @@ public class SpacerIndexChangedEvent
*/
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;
}

+ 5
- 0
client/src/main/java/com/vaadin/client/widget/escalator/events/SpacerVisibilityChangedEvent.java View File

@@ -31,6 +31,11 @@ public class SpacerVisibilityChangedEvent
*/
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;
}

+ 15
- 0
client/src/main/java/com/vaadin/client/widget/grid/AutoScroller.java View File

@@ -73,7 +73,11 @@ public class AutoScroller {
void onAutoScrollReachedMax();
}

/**
* Scroll direction for automatic scrolling.
*/
public enum ScrollAxis {
/** Scroll should happen to the direction indicated by the name. */
VERTICAL, HORIZONTAL
}

@@ -131,6 +135,9 @@ public class AutoScroller {
// TODO investigate if this works as desired
stop();
break;
default:
// NOP
break;
}
}

@@ -437,6 +444,9 @@ public class AutoScroller {
case Event.ONTOUCHCANCEL:
stop();
break;
default:
// NOP
break;
}
};

@@ -606,6 +616,11 @@ public class AutoScroller {
}
}

/**
* Returns how wide the frozen columns are all counted together.
*
* @return the width of frozen columns
*/
public double getFrozenColumnsWidth() {
double value = 0;


+ 6
- 0
client/src/main/java/com/vaadin/client/widget/grid/CellReference.java View File

@@ -38,6 +38,12 @@ public class CellReference<T> {
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;
}

+ 7
- 0
client/src/main/java/com/vaadin/client/widget/grid/DataAvailableEvent.java View File

@@ -27,8 +27,15 @@ import com.vaadin.shared.Range;
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;
}

+ 40
- 0
client/src/main/java/com/vaadin/client/widget/grid/DefaultEditorEventHandler.java View File

@@ -38,15 +38,24 @@ import com.vaadin.client.widgets.Grid.EditorDomEvent;
* 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;
@@ -134,9 +143,12 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> {
* 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) {
@@ -144,6 +156,12 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> {
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;
}
@@ -267,6 +285,15 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> {
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;
@@ -403,6 +430,19 @@ public class DefaultEditorEventHandler<T> implements Editor.EventHandler<T> {
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();

+ 18
- 2
client/src/main/java/com/vaadin/client/widget/grid/EventCellReference.java View File

@@ -29,6 +29,10 @@ import com.vaadin.shared.ui.grid.GridConstants.Section;
* 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
*/
@@ -37,15 +41,27 @@ public class EventCellReference<T> extends CellReference<T> {
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();

+ 1
- 0
client/src/main/java/com/vaadin/client/widget/grid/RendererCellReference.java View File

@@ -54,6 +54,7 @@ public class RendererCellReference extends CellReference<Object> {
* @param column
* the column to reference
*/
@SuppressWarnings("unchecked")
public void set(FlyweightCell cell, int columnIndex,
Grid.Column<?, ?> column) {
this.cell = cell;

+ 4
- 0
client/src/main/java/com/vaadin/client/widget/grid/datasources/ListDataSource.java View File

@@ -56,6 +56,9 @@ import com.vaadin.shared.util.SharedUtil;
* 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
*/
@@ -356,6 +359,7 @@ public class ListDataSource<T> implements DataSource<T> {
* @param rows
* The rows to initially add to the data source
*/
@SuppressWarnings("unchecked")
public ListDataSource(T... rows) {
if (rows == null) {
ds = new ArrayList<>();

+ 11
- 0
client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java View File

@@ -43,6 +43,12 @@ public class ListSorter<T> {
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) {
@@ -76,6 +82,8 @@ public class ListSorter<T> {
* 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
@@ -98,6 +106,8 @@ public class ListSorter<T> {
/**
* 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
@@ -126,6 +136,7 @@ public class ListSorter<T> {
* @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)) {

+ 30
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/AbstractGridKeyEventHandler.java View File

@@ -26,18 +26,48 @@ import com.vaadin.client.widgets.Grid.AbstractGridKeyEvent;
*/
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);
}


+ 18
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/AbstractGridMouseEventHandler.java View File

@@ -26,13 +26,31 @@ import com.vaadin.client.widgets.Grid.AbstractGridMouseEvent;
*/
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);
}


+ 16
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/ColumnReorderEvent.java View File

@@ -36,6 +36,11 @@ public class ColumnReorderEvent<T> extends GwtEvent<ColumnReorderHandler<T>> {
*/
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;
}
@@ -46,6 +51,17 @@ public class ColumnReorderEvent<T> extends GwtEvent<ColumnReorderHandler<T>> {

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;

+ 8
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/ColumnResizeEvent.java View File

@@ -37,12 +37,20 @@ public class ColumnResizeEvent<T> extends GwtEvent<ColumnResizeHandler<T>> {
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;
}

+ 17
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeEvent.java View File

@@ -33,6 +33,11 @@ public class ColumnVisibilityChangeEvent<T>

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;
}
@@ -43,6 +48,18 @@ public class ColumnVisibilityChangeEvent<T>

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;

+ 3
- 3
client/src/main/java/com/vaadin/client/widget/grid/events/ColumnVisibilityChangeHandler.java View File

@@ -21,9 +21,9 @@ import com.google.gwt.event.shared.EventHandler;
* 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

+ 6
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/GridClickEvent.java View File

@@ -30,6 +30,7 @@ import com.vaadin.shared.ui.grid.GridConstants.Section;
*/
public class GridClickEvent extends AbstractGridMouseEvent<GridClickHandler> {

/** DOM event type. */
public static final Type<GridClickHandler> TYPE = new Type<GridClickHandler>(
BrowserEvents.CLICK, new GridClickEvent());

@@ -42,6 +43,11 @@ public class GridClickEvent extends AbstractGridMouseEvent<GridClickHandler> {
/**
* @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) {

+ 6
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/GridDoubleClickEvent.java View File

@@ -31,6 +31,7 @@ import com.vaadin.shared.ui.grid.GridConstants.Section;
public class GridDoubleClickEvent
extends AbstractGridMouseEvent<GridDoubleClickHandler> {

/** DOM event type. */
public static final Type<GridDoubleClickHandler> TYPE = new Type<GridDoubleClickHandler>(
BrowserEvents.DBLCLICK, new GridDoubleClickEvent());

@@ -43,6 +44,11 @@ public class 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) {

+ 7
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledEvent.java View File

@@ -30,6 +30,13 @@ public class GridEnabledEvent extends GwtEvent<GridEnabledHandler> {
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;
}

+ 6
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/GridKeyDownEvent.java View File

@@ -31,6 +31,7 @@ import com.vaadin.shared.ui.grid.GridConstants.Section;
*/
public class GridKeyDownEvent extends AbstractGridKeyEvent<GridKeyDownHandler> {

/** DOM event type. */
public static final Type<GridKeyDownHandler> TYPE = new Type<GridKeyDownHandler>(
BrowserEvents.KEYDOWN, new GridKeyDownEvent());

@@ -43,6 +44,11 @@ public class GridKeyDownEvent extends AbstractGridKeyEvent<GridKeyDownHandler> {
/**
* @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) {

+ 6
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/GridKeyPressEvent.java View File

@@ -31,6 +31,7 @@ import com.vaadin.shared.ui.grid.GridConstants.Section;
public class GridKeyPressEvent
extends AbstractGridKeyEvent<GridKeyPressHandler> {

/** DOM event type. */
public static final Type<GridKeyPressHandler> TYPE = new Type<GridKeyPressHandler>(
BrowserEvents.KEYPRESS, new GridKeyPressEvent());

@@ -43,6 +44,11 @@ public class 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) {

+ 6
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/GridKeyUpEvent.java View File

@@ -31,6 +31,7 @@ import com.vaadin.shared.ui.grid.GridConstants.Section;
*/
public class GridKeyUpEvent extends AbstractGridKeyEvent<GridKeyUpHandler> {

/** DOM event type. */
public static final Type<GridKeyUpHandler> TYPE = new Type<GridKeyUpHandler>(
BrowserEvents.KEYUP, new GridKeyUpEvent());

@@ -43,6 +44,11 @@ public class GridKeyUpEvent extends AbstractGridKeyEvent<GridKeyUpHandler> {
/**
* @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) {

+ 3
- 0
client/src/main/java/com/vaadin/client/widget/grid/events/SelectAllHandler.java View File

@@ -21,6 +21,9 @@ import com.google.gwt.event.shared.EventHandler;
* 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
*/

+ 4
- 0
client/src/main/java/com/vaadin/client/widget/grid/selection/ClickSelectHandler.java View File

@@ -23,6 +23,9 @@ import com.vaadin.client.widgets.Grid;
/**
* 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
*/
@@ -39,6 +42,7 @@ public class ClickSelectHandler<T> {
if (!grid.getSelectionModel().isSelectionAllowed()) {
return;
}
@SuppressWarnings("unchecked")
T row = (T) event.getTargetCell().getRow();
if (!grid.isSelected(row)) {
grid.select(row);

+ 3
- 0
client/src/main/java/com/vaadin/client/widget/grid/selection/HasSelectionHandlers.java View File

@@ -20,6 +20,9 @@ import com.google.gwt.event.shared.HandlerRegistration;
/**
* Marker interface for widgets that fires selection events.
*
* @param <T>
* the type of the items in the Grid
*
* @author Vaadin Ltd
* @since 7.4
*/

+ 31
- 2
client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java View File

@@ -42,7 +42,6 @@ import com.google.gwt.user.client.Event;
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;
@@ -58,7 +57,7 @@ import com.vaadin.client.widgets.Grid;
*
* @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>
@@ -196,6 +195,9 @@ public class MultiSelectionRenderer<T>
event.cancel();
}
break;
default:
// NOP
break;
}
}

@@ -525,6 +527,9 @@ public class MultiSelectionRenderer<T>
case Event.ONTOUCHCANCEL:
stop();
break;
default:
// NOP
break;
}
};

@@ -599,6 +604,13 @@ public class MultiSelectionRenderer<T>

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;
}
@@ -785,10 +797,27 @@ public class MultiSelectionRenderer<T>
+ 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) {

+ 3
- 0
client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionEvent.java View File

@@ -26,6 +26,9 @@ import com.vaadin.client.widgets.Grid;
/**
* 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
*/

+ 7
- 1
client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModel.java View File

@@ -26,11 +26,17 @@ import elemental.json.JsonObject;
* @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

+ 4
- 0
client/src/main/java/com/vaadin/client/widget/grid/sort/SortEvent.java View File

@@ -24,6 +24,10 @@ import com.vaadin.client.widgets.Grid;
* 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
*/

+ 4
- 0
client/src/main/java/com/vaadin/client/widget/grid/sort/SortHandler.java View File

@@ -21,6 +21,10 @@ import com.google.gwt.event.shared.EventHandler;
* 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
*/

+ 213
- 22
client/src/main/java/com/vaadin/client/widgets/Escalator.java View File

@@ -479,7 +479,8 @@ public class Escalator extends Widget
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;
}
}
@@ -764,13 +765,13 @@ public class Escalator extends Widget
/*-{
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.
@@ -791,29 +792,29 @@ public class Escalator extends Widget
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);
});
}-*/;
@@ -1230,8 +1231,31 @@ public class Escalator extends Widget
*/
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;

@@ -1249,15 +1273,18 @@ public class Escalator extends Widget
}
}

/**
* 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>&lt;tr&gt;</code> tags) are
* contained in.
* The table section element (<code>&lt;thead&gt;</code>,
* <code>&lt;tbody&gt;</code> or <code>&lt;tfoot&gt;</code>) the rows
* (i.e. <code>&lt;tr&gt;</code> tags) are contained in.
*/
protected final TableSectionElement root;

@@ -1275,6 +1302,13 @@ public class Escalator extends Widget

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;
@@ -1434,6 +1468,19 @@ public class Escalator extends Widget

}

/**
* 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 {
@@ -1543,6 +1590,18 @@ public class Escalator extends Widget
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";
@@ -1653,10 +1712,19 @@ public class Escalator extends Widget
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();
@@ -1679,6 +1747,14 @@ public class Escalator extends Widget
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);

@@ -1743,6 +1819,14 @@ public class Escalator extends Widget
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++) {
@@ -1766,6 +1850,18 @@ public class Escalator extends Widget
}
}

/**
* 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) {

@@ -1843,6 +1939,16 @@ public class Escalator extends Widget
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");

@@ -1871,10 +1977,27 @@ public class Escalator extends Widget
}
}

/**
* 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();

@@ -2076,6 +2199,14 @@ public class Escalator extends Widget
*/
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";
@@ -2092,6 +2223,16 @@ public class Escalator extends Widget
*/
}

/**
* 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);
@@ -2113,6 +2254,12 @@ public class Escalator extends Widget
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);
}
@@ -6231,7 +6378,6 @@ public class Escalator extends Widget
* 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.";
@@ -6391,7 +6537,22 @@ public class Escalator extends Widget
}
}

@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) {

@@ -6433,7 +6594,6 @@ public class Escalator extends Widget
* @param removedRange
* logical range of spacers to remove
*/
@SuppressWarnings("boxing")
public void removeSpacers(Range removedRange) {

Map<Integer, SpacerImpl> removedSpacers = rowIndexToSpacer.subMap(
@@ -6497,7 +6657,6 @@ public class Escalator extends Widget
* @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<>(
@@ -6708,7 +6867,6 @@ public class Escalator extends Widget
* 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());
@@ -6743,7 +6901,6 @@ public class Escalator extends Widget
return rowIndexToSpacer.containsKey(Integer.valueOf(rowIndex));
}

@SuppressWarnings("boxing")
private void insertNewSpacer(int rowIndex, double height) {

if (spacerScrollerRegistration == null) {
@@ -6873,7 +7030,6 @@ public class Escalator extends Widget
return body.getRowTop(logicalIndex) + body.getDefaultRowHeight();
}

@SuppressWarnings("boxing")
private void shiftSpacerPositionsAfterRow(int changedRowIndex,
double diffPx) {
for (SpacerImpl spacer : rowIndexToSpacer
@@ -7027,18 +7183,53 @@ public class Escalator extends Widget
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);
}

+ 483
- 42
client/src/main/java/com/vaadin/client/widgets/Grid.java
File diff suppressed because it is too large
View File


+ 0
- 3
server/src/main/java/com/vaadin/ui/dnd/FileDropTarget.java View File

@@ -169,18 +169,15 @@ public class FileDropTarget<T extends AbstractComponent>
* @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;
}


Loading…
Cancel
Save