Browse Source

Applied save actions to Grid client-side classes. (#12388)

tags/7.7.28
Anna Koskinen 2 years ago
parent
commit
e60f055be8
No account linked to committer's email address

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

@@ -18,6 +18,8 @@ package com.vaadin.client.widget.escalator;

import java.util.Map;

import com.vaadin.client.widgets.Escalator;

/**
* A representation of the columns in an instance of {@link Escalator}.
*

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

@@ -16,6 +16,8 @@

package com.vaadin.client.widget.escalator;

import com.vaadin.client.widgets.Escalator;

/**
* An interface that allows client code to define how a certain row in Escalator
* will be displayed. The contents of an escalator's header, body and footer are

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

@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.List;

import com.google.gwt.dom.client.TableRowElement;
import com.vaadin.client.widgets.Escalator;

/**
* An internal implementation of the {@link Row} interface.

+ 1
- 0
client/src/main/java/com/vaadin/client/widget/escalator/Row.java View File

@@ -17,6 +17,7 @@
package com.vaadin.client.widget.escalator;

import com.google.gwt.dom.client.TableRowElement;
import com.vaadin.client.widgets.Escalator;

/**
* A representation of a row in an {@link Escalator}.

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

@@ -42,10 +42,10 @@ public class SpacerVisibilityChangedEvent
* Creates a spacer visibility changed event.
*
* @param rowIndex
* index of row to which the spacer belongs
* index of row to which the spacer belongs
* @param visible
* {@code true} if the spacer element is shown, {@code false} if the
* spacer element is hidden
* {@code true} if the spacer element is shown, {@code false} if
* the spacer element is hidden
*/
public SpacerVisibilityChangedEvent(int rowIndex, boolean visible) {
this.rowIndex = rowIndex;
@@ -65,7 +65,7 @@ public class SpacerVisibilityChangedEvent
* Gets whether the spacer element is displayed.
*
* @return {@code true} if the spacer element is shown, {@code false} if the
* spacer element is hidden
* spacer element is hidden
*/
public boolean isVisible() {
return visible;

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

@@ -159,7 +159,8 @@ public class ListSorter<T> {

if (result != 0) {
return o.getDirection() == SortDirection.ASCENDING
? result : -result;
? result
: -result;
}
}


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

@@ -21,14 +21,14 @@ package com.vaadin.client.widget.grid.selection;
*
* @param <T>
* Grid's row type
*
*
* @since 7.7.7
*/
public interface HasUserSelectionAllowed<T> extends SelectionModel<T> {

/**
* Checks if the user is allowed to change the selection.
*
*
* @return <code>true</code> if the user is allowed to change the selection,
* <code>false</code> otherwise
*/
@@ -36,7 +36,7 @@ public interface HasUserSelectionAllowed<T> extends SelectionModel<T> {

/**
* Sets whether the user is allowed to change the selection.
*
*
* @param userSelectionAllowed
* <code>true</code> if the user is allowed to change the
* selection, <code>false</code> otherwise

+ 31
- 32
client/src/main/java/com/vaadin/client/widgets/Escalator.java View File

@@ -132,7 +132,7 @@ import com.vaadin.shared.util.SharedUtil;

Each RowContainer can be thought to have three levels of
indices for any given displayed row (but the distinction
matters primarily for the BodyRowContainerImpl, because of
matters primarily for the BodyRowContainerImpl, because of
the way it scrolls through data):

- Logical index
@@ -151,8 +151,8 @@ import com.vaadin.shared.util.SharedUtil;
(because of 0-based indices). In Header and
FooterRowContainers, you are safe to assume that the logical
index is the same as the physical index. But because the
BodyRowContainerImpl never displays large data sources
entirely in the DOM, a physical index usually has no
BodyRowContainerImpl never displays large data sources
entirely in the DOM, a physical index usually has no
apparent direct relationship with its logical index.

VISUAL INDEX is the index relating to the order that you
@@ -703,13 +703,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 || e.srcElement; // IE8 uses e.scrElement
// 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.
@@ -730,29 +730,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);
});
}-*/;
@@ -1143,8 +1143,8 @@ public class Escalator extends Widget

/**
* The table section element ({@code <thead>}, {@code <tbody>} or
* {@code <tfoot>}) the rows (i.e. {@code
*
* {@code <tfoot>}) the rows (i.e. {@code
*
<tr>
* } tags) are contained in.
*/
@@ -1829,8 +1829,8 @@ public class Escalator extends Widget
* Applies the total length of the columns to each row element.
* <p>
* <em>Note:</em> In contrast to {@link #reapplyColumnWidths()}, this
* method only modifies the width of the {@code
*
* method only modifies the width of the {@code
*
<tr>
* } element, not the cells within.
*/
@@ -2158,7 +2158,7 @@ public class Escalator extends Widget

/**
* Gets the logical row index for the given table row element.
*
*
* @param tr
* the table row element inside this container.
* @return the logical index of the given element
@@ -3319,7 +3319,7 @@ public class Escalator extends Widget
* |3| ==> |*| ==> |5| <- newly rendered
* |4| |*|
* 5 5
*
*
* 1 1 |1| <- newly rendered
* |2| |*| |4|
* |3| ==> |*| ==> |5| <- newly rendered
@@ -3366,7 +3366,7 @@ public class Escalator extends Widget
* 1 |1| <-- newly rendered (by scrolling)
* |4| |4|
* |*| ==> |*|
* |*|
* |*|
* 5 5
*/
final double newScrollTop = contentBottom
@@ -3398,7 +3398,7 @@ public class Escalator extends Widget
* |1| |1|
* |4| ==> |4|
* |*| |5| <-- newly rendered
*
*
* 5
*/

@@ -3471,7 +3471,7 @@ public class Escalator extends Widget
* : : |4| <- newly rendered
* |5| |5| |5|
* |6| ==> |*| ==> |7|
* |7| |7|
* |7| |7|
*/

final int logicalTargetIndex = getLogicalRowIndex(
@@ -4556,11 +4556,11 @@ public class Escalator extends Widget
}

if (index < 0 || index + numberOfColumns > getColumnCount()) {
throw new IndexOutOfBoundsException(
"The given " + "column range (" + index + ".."
+ (index + numberOfColumns)
+ ") was outside of the current number of columns ("
+ getColumnCount() + ")");
throw new IndexOutOfBoundsException("The given "
+ "column range (" + index + ".."
+ (index + numberOfColumns)
+ ") was outside of the current number of columns ("
+ getColumnCount() + ")");
}

header.refreshColumns(index, numberOfColumns);
@@ -4822,15 +4822,13 @@ public class Escalator extends Widget
public void show() {
getRootElement().getStyle().clearDisplay();
getDecoElement().getStyle().clearDisplay();
Escalator.this.fireEvent(
new SpacerVisibilityChangedEvent(getRow(), true));
fireEvent(new SpacerVisibilityChangedEvent(getRow(), true));
}

public void hide() {
getRootElement().getStyle().setDisplay(Display.NONE);
getDecoElement().getStyle().setDisplay(Display.NONE);
Escalator.this.fireEvent(
new SpacerVisibilityChangedEvent(getRow(), false));
fireEvent(new SpacerVisibilityChangedEvent(getRow(), false));
}

/**
@@ -6543,7 +6541,8 @@ public class Escalator extends Widget
double footerHeight = footer.getHeightOfSection();
double bodyHeight = body.getDefaultRowHeight() * heightByRows;
double scrollbar = horizontalScrollbar.showsScrollHandle()
? horizontalScrollbar.getScrollbarThickness() : 0;
? horizontalScrollbar.getScrollbarThickness()
: 0;
double spacerHeight = 0; // ignored if HeightMode.ROW
if (heightMode == HeightMode.UNDEFINED) {
spacerHeight = body.spacerContainer.getSpacerHeightsSum();
@@ -6937,7 +6936,7 @@ public class Escalator extends Widget

/**
* Internal method for checking whether the browser is IE11 or Edge
*
*
* @return true only if the current browser is IE11, or Edge
*/
private static boolean isCurrentBrowserIE11OrEdge() {

+ 63
- 53
client/src/main/java/com/vaadin/client/widgets/Grid.java View File

@@ -181,7 +181,6 @@ import com.vaadin.client.widget.grid.sort.SortOrder;
import com.vaadin.client.widgets.Escalator.AbstractRowContainer;
import com.vaadin.client.widgets.Escalator.SubPartArguments;
import com.vaadin.client.widgets.Grid.Editor.State;
import com.vaadin.client.widgets.Grid.StaticSection.StaticCell;
import com.vaadin.client.widgets.Grid.StaticSection.StaticRow;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.grid.ColumnResizeMode;
@@ -270,8 +269,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
* a plain text caption
*/
public void setText(String text) {
this.content = text;
this.type = GridStaticCellType.TEXT;
content = text;
type = GridStaticCellType.TEXT;
section.requestSectionRefresh();
}

@@ -348,8 +347,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
* The html content of the cell
*/
public void setHtml(String html) {
this.content = html;
this.type = GridStaticCellType.HTML;
content = html;
type = GridStaticCellType.HTML;
section.requestSectionRefresh();
}

@@ -381,16 +380,16 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
* null).
*/
public void setWidget(Widget widget) {
if (this.content == widget) {
if (content == widget) {
return;
}

if (this.content instanceof Widget) {
if (content instanceof Widget) {
// Old widget in the cell, detach it first
section.getGrid().detachWidget((Widget) this.content);
section.getGrid().detachWidget((Widget) content);
}
this.content = widget;
this.type = GridStaticCellType.WIDGET;
content = widget;
type = GridStaticCellType.WIDGET;
section.requestSectionRefresh();
}

@@ -431,9 +430,9 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
* @since 7.6.3
*/
void detach() {
if (this.content instanceof Widget) {
if (content instanceof Widget) {
// Widget in the cell, detach it
section.getGrid().detachWidget((Widget) this.content);
section.getGrid().detachWidget((Widget) content);
}
}
}
@@ -1648,8 +1647,9 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
}
});
grid.scrollToRow(rowIndex, isBuffered()
? ScrollDestination.MIDDLE : ScrollDestination.ANY);
grid.scrollToRow(rowIndex,
isBuffered() ? ScrollDestination.MIDDLE
: ScrollDestination.ANY);
}
}

@@ -2141,15 +2141,16 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
cellWrapper.getStyle().setLeft(newLeft, Unit.PX);

try {
// sometimes focus handling twists the editor row out of alignment
// with the grid itself and the position needs to be compensated for
// sometimes focus handling twists the editor row out of
// alignment with the grid itself and the position needs to be
// compensated for
TableRowElement rowElement = grid.getEscalator().getBody()
.getRowElement(grid.getEditor().getRow());
.getRowElement(grid.getEditor().getRow());
int rowLeft = rowElement.getAbsoluteLeft();
int editorLeft = cellWrapper.getAbsoluteLeft();
if (editorLeft != rowLeft + frozenWidth) {
cellWrapper.getStyle().setLeft(newLeft + rowLeft - editorLeft,
Unit.PX);
cellWrapper.getStyle()
.setLeft(newLeft + rowLeft - editorLeft, Unit.PX);
}
} catch (IllegalStateException e) {
// IllegalStateException may occur if user has scrolled Grid so
@@ -2991,24 +2992,28 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
});
selectAllCheckBox.setValue(selected);

headerClickHandler = addHeaderClickHandler(new HeaderClickHandler() {
@Override
public void onClick(GridClickEvent event) {
if (!userSelectionAllowed) {
return;
}

CellReference<?> targetCell = event.getTargetCell();
int defaultRowIndex = getHeader().getRows()
.indexOf(getDefaultHeaderRow());
headerClickHandler = addHeaderClickHandler(
new HeaderClickHandler() {
@Override
public void onClick(GridClickEvent event) {
if (!userSelectionAllowed) {
return;
}

if (targetCell.getColumnIndex() == 0 && targetCell
.getRowIndex() == defaultRowIndex) {
selectAllCheckBox.setValue(
!selectAllCheckBox.getValue(), true);
}
}
});
CellReference<?> targetCell = event
.getTargetCell();
int defaultRowIndex = getHeader().getRows()
.indexOf(getDefaultHeaderRow());

if (targetCell.getColumnIndex() == 0
&& targetCell
.getRowIndex() == defaultRowIndex) {
selectAllCheckBox.setValue(
!selectAllCheckBox.getValue(),
true);
}
}
});

// Select all with space when "select all" cell is active
addHeaderKeyUpHandler(new HeaderKeyUpHandler() {
@@ -4532,7 +4537,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
if (focusedColumnIndex == draggedColumnIndex) {
// move with the dragged column
int adjustedDropIndex = latestColumnDropIndex > draggedColumnIndex
? latestColumnDropIndex - 1 : latestColumnDropIndex;
? latestColumnDropIndex - 1
: latestColumnDropIndex;
// remove hidden columns from indexing
adjustedDropIndex = getVisibleColumns()
.indexOf(getColumn(adjustedDropIndex));
@@ -4789,7 +4795,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
private Grid<T> grid;

/**
* Width of column in pixels as {@link #setWidth(double)} has been called.
* Width of column in pixels as {@link #setWidth(double)} has been
* called.
*/
protected double widthUser = GridConstants.DEFAULT_COLUMN_WIDTH_PX;

@@ -4848,7 +4855,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
*/
protected int expandRatio = GridConstants.DEFAULT_EXPAND_RATIO;


/**
* Constructs a new column with a simple TextRenderer.
*/
@@ -5955,11 +5961,12 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,

// Need to wait for column width recalculation
// scheduled by setWidth() before firing the event
Scheduler.get().scheduleDeferred(
new ScheduledCommand() {
Scheduler.get()
.scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
fireEvent(new ColumnResizeEvent<T>(col));
fireEvent(new ColumnResizeEvent<T>(
col));
}
});
}
@@ -6475,7 +6482,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
addColumnsSkipSelectionColumnCheck(Arrays.asList(columns), count);
}


/**
* Checks the given column is valid to add at the given index.
*/
@@ -6516,17 +6522,18 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
*/
public <C extends Column<?, T>> C addColumn(C column, int index) {
checkColumnIsValidToAdd(column, index);
addColumnsSkipSelectionColumnCheck(Collections.singleton(column), index);
addColumnsSkipSelectionColumnCheck(Collections.singleton(column),
index);
return column;
}

private <C extends Column<?, T>> void addColumnsSkipSelectionColumnCheck(Collection<C> columnCollection, int index) {
private <C extends Column<?, T>> void addColumnsSkipSelectionColumnCheck(
Collection<C> columnCollection, int index) {
int visibleNewColumns = 0;
int currentIndex = index;

//prevent updates of hiding toggles.
//it will be updated finally all at once.
// prevent updates of hiding toggles.
// it will be updated finally all at once.
this.columnHider.hidingColumn = true;

for (final Column<?, T> column : columnCollection) {
@@ -6549,8 +6556,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
escalatorIndex--;
}
}
final ColumnConfiguration columnConfiguration = this.escalator.getColumnConfiguration();
columnConfiguration.insertColumns(escalatorIndex, visibleNewColumns);
final ColumnConfiguration columnConfiguration = this.escalator
.getColumnConfiguration();
columnConfiguration.insertColumns(escalatorIndex,
visibleNewColumns);
}

for (final Column<?, T> column : columnCollection) {
@@ -6565,7 +6574,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
sinkEvents(events);
}
//now we do the update of the hiding toggles.
// now we do the update of the hiding toggles.
this.columnHider.hidingColumn = false;
this.columnHider.updateTogglesOrder();
refreshHeader();
@@ -7968,7 +7977,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
cellFocusHandler.offsetRangeBy(1);
selectionColumn = new SelectionColumn(selectColumnRenderer);

addColumnsSkipSelectionColumnCheck(Collections.singleton(selectionColumn), 0);
addColumnsSkipSelectionColumnCheck(
Collections.singleton(selectionColumn), 0);

selectionColumn.setEnabled(isEnabled());
selectionColumn.initDone();
@@ -8558,7 +8568,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
* Adds a spacer visibility changed handler to the underlying escalator.
*
* @param handler
* the handler to be called when a spacer's visibility changes
* the handler to be called when a spacer's visibility changes
* @return the registration object with which the handler can be removed
* @since 7.7.13
*/

Loading…
Cancel
Save