Просмотр исходного кода

Fix issues from API review for 8.2 (#10342)

* Rename HierarchicalDataCommunicator#getMapper to getHierarchyMapper

* Make rpc field in Notification private

* Change DropIndexCalculator.ALWAYS_DROP_TO_END to a generic static method

* Move EditorImpl#editRow documentation to the interface level

* Correct GridDragEndEvent, GridDragStartEvent constructor javadocs

* Revert SharedState.registeredEventListeners to a Set

* Rename GridDropTarget dropAllowedOnSortedGridRows

* Rename ColumnState.contentMode to tooltipContentMode
tags/8.3.0.alpha1
Aleksi Hietanen 6 лет назад
Родитель
Сommit
f805482c60
Аккаунт пользователя с таким Email не найден
23 измененных файлов: 97 добавлений и 114 удалений
  1. 0
    1
      all/src/main/templates/release-notes.html
  2. 9
    9
      client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
  3. 1
    1
      client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
  4. 3
    3
      client/src/main/java/com/vaadin/client/ui/AbstractConnector.java
  5. 3
    3
      server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java
  6. 3
    3
      server/src/main/java/com/vaadin/event/EventRouter.java
  7. 3
    3
      server/src/main/java/com/vaadin/ui/Grid.java
  8. 8
    8
      server/src/main/java/com/vaadin/ui/Notification.java
  9. 7
    4
      server/src/main/java/com/vaadin/ui/components/grid/DropIndexCalculator.java
  10. 13
    3
      server/src/main/java/com/vaadin/ui/components/grid/Editor.java
  11. 0
    16
      server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
  12. 1
    1
      server/src/main/java/com/vaadin/ui/components/grid/GridDragEndEvent.java
  13. 1
    1
      server/src/main/java/com/vaadin/ui/components/grid/GridDragStartEvent.java
  14. 9
    9
      server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java
  15. 1
    1
      server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java
  16. 13
    13
      server/src/test/java/com/vaadin/tests/components/grid/GridDropTargetTest.java
  17. 3
    3
      server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java
  18. 3
    3
      server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerTwoGridsTest.java
  19. 3
    5
      shared/src/main/java/com/vaadin/shared/communication/SharedState.java
  20. 9
    20
      shared/src/main/java/com/vaadin/shared/ui/ComponentStateUtil.java
  21. 1
    1
      shared/src/main/java/com/vaadin/shared/ui/grid/ColumnState.java
  22. 2
    2
      uitest/src/main/java/com/vaadin/tests/components/grid/AbstractGridDnD.java
  23. 1
    1
      uitest/src/main/java/com/vaadin/tests/components/grid/GridRowDraggerTwoGrids.java

+ 0
- 1
all/src/main/templates/release-notes.html Просмотреть файл

<li>Error indicators are now <tt>&lt;span class="v-errorindicator"&gt;&lt;/span&gt;</tt> elements.</li> <li>Error indicators are now <tt>&lt;span class="v-errorindicator"&gt;&lt;/span&gt;</tt> elements.</li>
<li><tt>Embedded</tt> is not a <tt>LegacyComponent</tt> anymore.</li> <li><tt>Embedded</tt> is not a <tt>LegacyComponent</tt> anymore.</li>
<li><tt>Notification</tt> method <tt>show</tt> returns <tt>Notification</tt>, instead of <tt>void</tt>.</li> <li><tt>Notification</tt> method <tt>show</tt> returns <tt>Notification</tt>, instead of <tt>void</tt>.</li>
<li><tt>SharedState</tt> field <tt>registeredEventListeners</tt> is a <tt>Map</tt> instead of <tt>Set</tt>.</li>
<li>The client side <tt>SelectionModel</tt> interface has a new method <tt>isMultiSelectionAllowed</tt>.</li> <li>The client side <tt>SelectionModel</tt> interface has a new method <tt>isMultiSelectionAllowed</tt>.</li>
<li><tt>AbstractDateField</tt> is not a <tt>LegacyComponent</tt> anymore.</li> <li><tt>AbstractDateField</tt> is not a <tt>LegacyComponent</tt> anymore.</li>
<li><tt>AbstractDateField</tt>.<tt>formatDate</tt> is now abstract.</li> <li><tt>AbstractDateField</tt>.<tt>formatDate</tt> is now abstract.</li>

+ 9
- 9
client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java Просмотреть файл

extends Column<Object, JsonObject> { extends Column<Object, JsonObject> {


private final String connectorId; private final String connectorId;
private ContentMode contentMode;
private ContentMode tooltipContentMode;


CustomColumn(String connectorId) { CustomColumn(String connectorId) {
this.connectorId = connectorId; this.connectorId = connectorId;
* *
* @since 8.2 * @since 8.2
*/ */
public ContentMode getContentMode() {
return contentMode;
public ContentMode getTooltipContentMode() {
return tooltipContentMode;
} }


/** /**
* Sets the content mode for tooltips in this column. * Sets the content mode for tooltips in this column.
* *
* @param contentMode
* @param tooltipContentMode
* the content mode for tooltips * the content mode for tooltips
* *
* @since 8.2 * @since 8.2
*/ */
public void setContentMode(ContentMode contentMode) {
this.contentMode = contentMode;
public void setTooltipContentMode(ContentMode tooltipContentMode) {
this.tooltipContentMode = tooltipContentMode;
} }
} }


column.setEditable(getState().editable); column.setEditable(getState().editable);
} }


@OnStateChange("contentMode")
void updateContentMode() {
column.setContentMode(getState().contentMode);
@OnStateChange("tooltipContentMode")
void updateTooltipContentMode() {
column.setTooltipContentMode(getState().tooltipContentMode);
} }


@Override @Override

+ 1
- 1
client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java Просмотреть файл

if (cellDescriptions != null if (cellDescriptions != null
&& cellDescriptions.hasKey(id)) { && cellDescriptions.hasKey(id)) {
return new TooltipInfo(cellDescriptions.getString(id), return new TooltipInfo(cellDescriptions.getString(id),
((CustomColumn) column).getContentMode());
((CustomColumn) column).getTooltipContentMode());
} else if (row.hasKey(GridState.JSONKEY_ROWDESCRIPTION)) { } else if (row.hasKey(GridState.JSONKEY_ROWDESCRIPTION)) {
return new TooltipInfo( return new TooltipInfo(
row.getString(GridState.JSONKEY_ROWDESCRIPTION), row.getString(GridState.JSONKEY_ROWDESCRIPTION),

+ 3
- 3
client/src/main/java/com/vaadin/client/ui/AbstractConnector.java Просмотреть файл

import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;


import com.google.gwt.core.client.JsArrayString; import com.google.gwt.core.client.JsArrayString;
*/ */
@Override @Override
public boolean hasEventListener(String eventIdentifier) { public boolean hasEventListener(String eventIdentifier) {
Map<String, Integer> reg = getState().registeredEventListeners;
return reg != null && reg.containsKey(eventIdentifier);
Set<String> reg = getState().registeredEventListeners;
return reg != null && reg.contains(eventIdentifier);
} }


/** /**

+ 3
- 3
server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java Просмотреть файл

} }


/** /**
* Returns active {@code HierarchyMapper}
* Returns the {@code HierarchyMapper} used by this data communicator.
* *
* @return the mapper
* @return the hierarchy mapper used by this data communicator
*/ */
protected HierarchyMapper<T, ?> getMapper() {
protected HierarchyMapper<T, ?> getHierarchyMapper() {
return mapper; return mapper;
} }
} }

+ 3
- 3
server/src/main/java/com/vaadin/event/EventRouter.java Просмотреть файл

.addRegisteredEventListener(state, eventIdentifier); .addRegisteredEventListener(state, eventIdentifier);


return () -> { return () -> {
registration.remove();

listenerList.remove(listenerMethod); listenerList.remove(listenerMethod);
if (!hasListeners(eventType)) {
registration.remove();
}
}; };
} }


} }
return listeners; return listeners;
} }

} }

+ 3
- 3
server/src/main/java/com/vaadin/ui/Grid.java Просмотреть файл

* @param cellDescriptionGenerator * @param cellDescriptionGenerator
* the cell description generator to set, or {@code null} to * the cell description generator to set, or {@code null} to
* remove a previously set generator * remove a previously set generator
* @param contentMode
* @param tooltipContentMode
* the content mode for tooltips * the content mode for tooltips
* @return this column * @return this column
* *
*/ */
public Column<T, V> setDescriptionGenerator( public Column<T, V> setDescriptionGenerator(
DescriptionGenerator<T> cellDescriptionGenerator, DescriptionGenerator<T> cellDescriptionGenerator,
ContentMode contentMode) {
ContentMode tooltipContentMode) {
this.descriptionGenerator = cellDescriptionGenerator; this.descriptionGenerator = cellDescriptionGenerator;
getState().contentMode = contentMode;
getState().tooltipContentMode = tooltipContentMode;
getGrid().getDataCommunicator().reset(); getGrid().getDataCommunicator().reset();
return this; return this;
} }

+ 8
- 8
server/src/main/java/com/vaadin/ui/Notification.java Просмотреть файл

*/ */
public class Notification extends AbstractExtension { public class Notification extends AbstractExtension {


/**
* The server RPC.
*
* @since 8.2
*/
protected NotificationServerRpc rpc = () -> fireEvent(
new CloseEvent(Notification.this));

public enum Type { public enum Type {
HUMANIZED_MESSAGE("humanized"), WARNING_MESSAGE( HUMANIZED_MESSAGE("humanized"), WARNING_MESSAGE(
"warning"), ERROR_MESSAGE("error"), TRAY_NOTIFICATION("tray"), "warning"), ERROR_MESSAGE("error"), TRAY_NOTIFICATION("tray"),
public static final int DELAY_FOREVER = -1; public static final int DELAY_FOREVER = -1;
public static final int DELAY_NONE = 0; public static final int DELAY_NONE = 0;


/**
* The server RPC.
*
* @since 8.2
*/
private NotificationServerRpc rpc = () -> fireEvent(
new CloseEvent(Notification.this));

/** /**
* Creates a "humanized" notification message. * Creates a "humanized" notification message.
* *

+ 7
- 4
server/src/main/java/com/vaadin/ui/components/grid/DropIndexCalculator.java Просмотреть файл

public interface DropIndexCalculator<T> extends Serializable { public interface DropIndexCalculator<T> extends Serializable {


/** /**
* Calculator for always dropping items to the end of the target grid,
* regardless of drop position.
* Returns a calculator for always dropping items to the end of the target
* grid, regardless of drop position.
*
* @return the created drop index calculator
*/ */
@SuppressWarnings("rawtypes")
static DropIndexCalculator ALWAYS_DROP_TO_END = (event -> Integer.MAX_VALUE);
static <T> DropIndexCalculator<T> alwaysDropToEnd() {
return (GridDropEvent<T> event) -> Integer.MAX_VALUE;
}


/** /**
* Called when Items are dropped onto a target grid. * Called when Items are dropped onto a target grid.

+ 13
- 3
server/src/main/java/com/vaadin/ui/components/grid/Editor.java Просмотреть файл

public void cancel(); public void cancel();


/** /**
* Edits the selected row
* Opens the editor interface for the provided row. Scrolls the Grid to
* bring the row to view if it is not already visible.
* *
* @param rowNumber
* the row to edit
* Note that any cell content rendered by a WidgetRenderer will not be
* visible in the editor row.
* *
* @see #setEnabled(boolean)
* @since 8.2 * @since 8.2
*
* @param rowNumber
* the row number of the edited item
* @throws IllegalStateException
* if the editor is not enabled or already editing a different
* item in buffered mode
* @throws IllegalArgumentException
* if the {@code rowNumber} is not in the backing data provider
*/ */
public void editRow(int rowNumber); public void editRow(int rowNumber);



+ 0
- 16
server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java Просмотреть файл

rpc.cancel(); rpc.cancel();
} }


/**
* Opens the editor interface for the provided row. Scrolls the Grid to
* bring the row to view if it is not already visible.
*
* Note that any cell content rendered by a WidgetRenderer will not be
* visible in the editor row.
*
* @param rowNumber
* the row number of the edited item
* @throws IllegalStateException
* if the editor is not enabled or already editing a different item
* in buffered mode
* @throws IllegalArgumentException
* if the {@code rowNumber} is not in the backing data provider
* @see #setEnabled(boolean)
*/
@Override @Override
public void editRow(int rowNumber) public void editRow(int rowNumber)
throws IllegalStateException, IllegalArgumentException { throws IllegalStateException, IllegalArgumentException {

+ 1
- 1
server/src/main/java/com/vaadin/ui/components/grid/GridDragEndEvent.java Просмотреть файл

* @param dropEffect * @param dropEffect
* Drop effect from {@code DataTransfer.dropEffect} object. * Drop effect from {@code DataTransfer.dropEffect} object.
* @param draggedItems * @param draggedItems
* Set of items having been dragged.
* List of items having been dragged.
*/ */
public GridDragEndEvent(Grid<T> source, DropEffect dropEffect, public GridDragEndEvent(Grid<T> source, DropEffect dropEffect,
List<T> draggedItems) { List<T> draggedItems) {

+ 1
- 1
server/src/main/java/com/vaadin/ui/components/grid/GridDragStartEvent.java Просмотреть файл

* @param effectAllowed * @param effectAllowed
* Allowed effect from {@code DataTransfer.effectAllowed} object. * Allowed effect from {@code DataTransfer.effectAllowed} object.
* @param draggedItems * @param draggedItems
* Set of items being dragged.
* List of items being dragged.
*/ */
public GridDragStartEvent(Grid<T> source, EffectAllowed effectAllowed, public GridDragStartEvent(Grid<T> source, EffectAllowed effectAllowed,
List<T> draggedItems) { List<T> draggedItems) {

+ 9
- 9
server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java Просмотреть файл



private Registration sortListenerRegistration; private Registration sortListenerRegistration;
private DropMode cachedDropMode; private DropMode cachedDropMode;
private boolean dropAllowedOnSortedGridRows = true;
private boolean dropAllowedOnRowsWhenSorted = true;


/** /**
* Extends a Grid and makes it's rows drop targets for HTML5 drag and drop. * Extends a Grid and makes it's rows drop targets for HTML5 drag and drop.
* in this case. * in this case.
* <p> * <p>
* <em>NOTE: {@link DropMode#ON_GRID} is used automatically when the grid * <em>NOTE: {@link DropMode#ON_GRID} is used automatically when the grid
* has been sorted and {@link #setDropAllowedOnSortedGridRows(boolean)} is
* has been sorted and {@link #setDropAllowedOnRowsWhenSorted(boolean)} is
* {@code false} - since the drop location would not necessarily match the * {@code false} - since the drop location would not necessarily match the
* correct row because of the sorting. During the sorting, any calls to this * correct row because of the sorting. During the sorting, any calls to this
* method don't have any effect until the sorting has been removed, or * method don't have any effect until the sorting has been removed, or
* {@link #setDropAllowedOnSortedGridRows(boolean)} is set back to
* {@link #setDropAllowedOnRowsWhenSorted(boolean)} is set back to
* {@code true}.</em> * {@code true}.</em>
* *
* @param dropMode * @param dropMode
* Drop mode that describes the allowed drop locations within the * Drop mode that describes the allowed drop locations within the
* Grid's row. * Grid's row.
* @see GridDropEvent#getDropLocation() * @see GridDropEvent#getDropLocation()
* @see #setDropAllowedOnSortedGridRows(boolean)
* @see #setDropAllowedOnRowsWhenSorted(boolean)
*/ */
public void setDropMode(DropMode dropMode) { public void setDropMode(DropMode dropMode) {
if (dropMode == null) { if (dropMode == null) {
* drops on sorted grid rows * drops on sorted grid rows
* @since 8.2 * @since 8.2
*/ */
public void setDropAllowedOnSortedGridRows(
public void setDropAllowedOnRowsWhenSorted(
boolean dropAllowedOnSortedGridRows) { boolean dropAllowedOnSortedGridRows) {
if (this.dropAllowedOnSortedGridRows != dropAllowedOnSortedGridRows) {
this.dropAllowedOnSortedGridRows = dropAllowedOnSortedGridRows;
if (this.dropAllowedOnRowsWhenSorted != dropAllowedOnSortedGridRows) {
this.dropAllowedOnRowsWhenSorted = dropAllowedOnSortedGridRows;


if (!dropAllowedOnSortedGridRows) { if (!dropAllowedOnSortedGridRows) {


* the grid * the grid
* @since 8.2 * @since 8.2
*/ */
public boolean isDropAllowedOnSortedGridRows() {
return dropAllowedOnSortedGridRows;
public boolean isDropAllowedOnRowsWhenSorted() {
return dropAllowedOnRowsWhenSorted;
} }


/** /**

+ 1
- 1
server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java Просмотреть файл

gridDragSource = new GridDragSource<>(source); gridDragSource = new GridDragSource<>(source);


gridDropTarget = new GridDropTarget<>(target, dropMode); gridDropTarget = new GridDropTarget<>(target, dropMode);
gridDropTarget.setDropAllowedOnSortedGridRows(false);
gridDropTarget.setDropAllowedOnRowsWhenSorted(false);


gridDragSource.addGridDragStartListener(event -> { gridDragSource.addGridDragStartListener(event -> {
draggedItems = event.getDraggedItems(); draggedItems = event.getDraggedItems();

+ 13
- 13
server/src/test/java/com/vaadin/tests/components/grid/GridDropTargetTest.java Просмотреть файл

@Test @Test
public void dropAllowedOnSortedGridRows_defaultValue_isTrue() { public void dropAllowedOnSortedGridRows_defaultValue_isTrue() {
Assert.assertTrue("Default drop allowed should be backwards compatible", Assert.assertTrue("Default drop allowed should be backwards compatible",
target.isDropAllowedOnSortedGridRows());
target.isDropAllowedOnRowsWhenSorted());
} }


@Test @Test
public void dropAllowedOnSortedGridRows_notAllowed_changesDropModeWhenSorted() { public void dropAllowedOnSortedGridRows_notAllowed_changesDropModeWhenSorted() {
Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(false);
target.setDropAllowedOnRowsWhenSorted(false);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());




Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(false);
target.setDropAllowedOnRowsWhenSorted(false);


Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); Assert.assertEquals(DropMode.ON_GRID, target.getDropMode());


target.setDropAllowedOnSortedGridRows(true);
target.setDropAllowedOnRowsWhenSorted(true);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());
} }
public void dropAllowedOnSortedGridRows_notAllowedBackToAllowed_changesBackToUserDefinedMode() { public void dropAllowedOnSortedGridRows_notAllowedBackToAllowed_changesBackToUserDefinedMode() {
Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(false);
target.setDropAllowedOnRowsWhenSorted(false);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());




Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); Assert.assertEquals(DropMode.ON_GRID, target.getDropMode());


target.setDropAllowedOnSortedGridRows(true);
target.setDropAllowedOnRowsWhenSorted(true);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


public void dropAllowedOnSortedGridRows_swappingAllowedDropOnSortedOffAndOn() { public void dropAllowedOnSortedGridRows_swappingAllowedDropOnSortedOffAndOn() {
Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(false);
target.setDropAllowedOnRowsWhenSorted(false);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(false);
target.setDropAllowedOnRowsWhenSorted(false);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(true);
target.setDropAllowedOnRowsWhenSorted(true);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(true);
target.setDropAllowedOnRowsWhenSorted(true);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());
} }
public void dropAllowedOnSortedGridRows_changingDropModeWhileSorted_replacesPreviouslyCachedButDoesntOverride() { public void dropAllowedOnSortedGridRows_changingDropModeWhileSorted_replacesPreviouslyCachedButDoesntOverride() {
Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());


target.setDropAllowedOnSortedGridRows(false);
target.setDropAllowedOnRowsWhenSorted(false);


Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());




Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); Assert.assertEquals(DropMode.ON_GRID, target.getDropMode());
Assert.assertFalse("Changing drop mode should not have any effect here", Assert.assertFalse("Changing drop mode should not have any effect here",
target.isDropAllowedOnSortedGridRows());
target.isDropAllowedOnRowsWhenSorted());


grid.clearSortOrder(); grid.clearSortOrder();




Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); Assert.assertEquals(DropMode.ON_GRID, target.getDropMode());


target.setDropAllowedOnSortedGridRows(true);
target.setDropAllowedOnRowsWhenSorted(true);


Assert.assertEquals(DropMode.ON_TOP_OR_BETWEEN, target.getDropMode()); Assert.assertEquals(DropMode.ON_TOP_OR_BETWEEN, target.getDropMode());
} }

+ 3
- 3
server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java Просмотреть файл

import com.vaadin.shared.ui.grid.DropLocation; import com.vaadin.shared.ui.grid.DropLocation;
import com.vaadin.ui.Grid; import com.vaadin.ui.Grid;
import com.vaadin.ui.components.grid.DropIndexCalculator; import com.vaadin.ui.components.grid.DropIndexCalculator;
import com.vaadin.ui.components.grid.GridRowDragger;
import com.vaadin.ui.components.grid.GridDropEvent; import com.vaadin.ui.components.grid.GridDropEvent;
import com.vaadin.ui.components.grid.GridRowDragger;
import com.vaadin.ui.components.grid.SourceDataProviderUpdater; import com.vaadin.ui.components.grid.SourceDataProviderUpdater;


public class GridRowDraggerOneGridTest { public class GridRowDraggerOneGridTest {
public void alwaysDropToEndCalculator() { public void alwaysDropToEndCalculator() {
source.setItems("0", "1", "2"); source.setItems("0", "1", "2");


dragger.setDropIndexCalculator(DropIndexCalculator.ALWAYS_DROP_TO_END);
dragger.setDropIndexCalculator(DropIndexCalculator.alwaysDropToEnd());


drop("1", DropLocation.ABOVE, "0"); drop("1", DropLocation.ABOVE, "0");


public void dropOnSortedGrid_byDefault_dropsToTheEnd() { public void dropOnSortedGrid_byDefault_dropsToTheEnd() {
Assert.assertFalse( Assert.assertFalse(
"Default drops on sorted grid rows should not be allowed", "Default drops on sorted grid rows should not be allowed",
dragger.getGridDropTarget().isDropAllowedOnSortedGridRows());
dragger.getGridDropTarget().isDropAllowedOnRowsWhenSorted());


source.setItems("0", "1", "2", "3", "4"); source.setItems("0", "1", "2", "3", "4");



+ 3
- 3
server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerTwoGridsTest.java Просмотреть файл

import com.vaadin.shared.ui.grid.DropLocation; import com.vaadin.shared.ui.grid.DropLocation;
import com.vaadin.ui.Grid; import com.vaadin.ui.Grid;
import com.vaadin.ui.components.grid.DropIndexCalculator; import com.vaadin.ui.components.grid.DropIndexCalculator;
import com.vaadin.ui.components.grid.GridRowDragger;
import com.vaadin.ui.components.grid.GridDropEvent; import com.vaadin.ui.components.grid.GridDropEvent;
import com.vaadin.ui.components.grid.GridRowDragger;
import com.vaadin.ui.components.grid.SourceDataProviderUpdater; import com.vaadin.ui.components.grid.SourceDataProviderUpdater;


public class GridRowDraggerTwoGridsTest { public class GridRowDraggerTwoGridsTest {
source.setItems("0"); source.setItems("0");
target.setItems("1", "2"); target.setItems("1", "2");


dragger.setDropIndexCalculator(DropIndexCalculator.ALWAYS_DROP_TO_END);
dragger.setDropIndexCalculator(DropIndexCalculator.alwaysDropToEnd());


drop("1", DropLocation.ABOVE, "0"); drop("1", DropLocation.ABOVE, "0");


public void dropOnSortedGrid_byDefault_dropsToTheEnd() { public void dropOnSortedGrid_byDefault_dropsToTheEnd() {
Assert.assertFalse( Assert.assertFalse(
"Default drops on sorted grid rows should not be allowed", "Default drops on sorted grid rows should not be allowed",
dragger.getGridDropTarget().isDropAllowedOnSortedGridRows());
dragger.getGridDropTarget().isDropAllowedOnRowsWhenSorted());


source.setItems("0", "1", "2"); source.setItems("0", "1", "2");
target.setItems("4", "5"); target.setItems("4", "5");

+ 3
- 5
shared/src/main/java/com/vaadin/shared/communication/SharedState.java Просмотреть файл

import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;


import com.vaadin.shared.Connector; import com.vaadin.shared.Connector;
import com.vaadin.shared.annotations.NoLayout; import com.vaadin.shared.annotations.NoLayout;
public boolean enabled = true; public boolean enabled = true;


/** /**
* A Map of event identifiers with registered listeners, {@code key} is
* event identifier, {@code value} is the listeners count.
*
* @since 8.2
* A set of event identifiers with registered listeners.
*/ */
@NoLayout @NoLayout
public Map<String, Integer> registeredEventListeners;
public Set<String> registeredEventListeners;


} }

+ 9
- 20
shared/src/main/java/com/vaadin/shared/ui/ComponentStateUtil.java Просмотреть файл

package com.vaadin.shared.ui; package com.vaadin.shared.ui;


import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;


import com.vaadin.shared.AbstractComponentState; import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.Registration; import com.vaadin.shared.Registration;
@Deprecated @Deprecated
public static final void removeRegisteredEventListener(SharedState state, public static final void removeRegisteredEventListener(SharedState state,
String eventIdentifier) { String eventIdentifier) {
if (state.registeredEventListeners != null) {
Integer count = state.registeredEventListeners.get(eventIdentifier);
if (count != null) {
if (count > 1) {
state.registeredEventListeners.put(eventIdentifier,
count - 1);
} else {
state.registeredEventListeners.remove(eventIdentifier);
if (state.registeredEventListeners.isEmpty()) {
state.registeredEventListeners = null;
}
}
}
if (state.registeredEventListeners == null) {
return;
}
state.registeredEventListeners.remove(eventIdentifier);
if (state.registeredEventListeners.size() == 0) {
state.registeredEventListeners = null;
} }
} }


public static final Registration addRegisteredEventListener( public static final Registration addRegisteredEventListener(
SharedState state, String eventListenerId) { SharedState state, String eventListenerId) {
if (state.registeredEventListeners == null) { if (state.registeredEventListeners == null) {
state.registeredEventListeners = new HashMap<>();
}
Integer count = state.registeredEventListeners.get(eventListenerId);
if (count == null) {
count = 0;
state.registeredEventListeners = new HashSet<>();
} }
state.registeredEventListeners.put(eventListenerId, count + 1);
state.registeredEventListeners.add(eventListenerId);
return () -> removeRegisteredEventListener(state, eventListenerId); return () -> removeRegisteredEventListener(state, eventListenerId);
} }
} }

+ 1
- 1
shared/src/main/java/com/vaadin/shared/ui/grid/ColumnState.java Просмотреть файл

* *
* @since 8.2 * @since 8.2
*/ */
public ContentMode contentMode;
public ContentMode tooltipContentMode;


} }

+ 2
- 2
uitest/src/main/java/com/vaadin/tests/components/grid/AbstractGridDnD.java Просмотреть файл

} }
}); });
CheckBox dropOnSortedGridRows = new CheckBox("Drop on Sorted Grid Rows", CheckBox dropOnSortedGridRows = new CheckBox("Drop on Sorted Grid Rows",
dropTarget.isDropAllowedOnSortedGridRows());
dropTarget.isDropAllowedOnRowsWhenSorted());
dropOnSortedGridRows.addValueChangeListener(event -> { dropOnSortedGridRows.addValueChangeListener(event -> {
dropTarget.setDropAllowedOnSortedGridRows(event.getValue());
dropTarget.setDropAllowedOnRowsWhenSorted(event.getValue());
}); });


RadioButtonGroup<Integer> frozenColumnSelect = new RadioButtonGroup<>( RadioButtonGroup<Integer> frozenColumnSelect = new RadioButtonGroup<>(

+ 1
- 1
uitest/src/main/java/com/vaadin/tests/components/grid/GridRowDraggerTwoGrids.java Просмотреть файл

CheckBox addItemsToEnd = new CheckBox("Add Items To End", false); CheckBox addItemsToEnd = new CheckBox("Add Items To End", false);
addItemsToEnd.addValueChangeListener( addItemsToEnd.addValueChangeListener(
event -> gridDragger.setDropIndexCalculator(event.getValue() event -> gridDragger.setDropIndexCalculator(event.getValue()
? DropIndexCalculator.ALWAYS_DROP_TO_END : null));
? DropIndexCalculator.alwaysDropToEnd() : null));
CheckBox removeItemsFromSource = new CheckBox( CheckBox removeItemsFromSource = new CheckBox(
"Remove items from source grid", true); "Remove items from source grid", true);
removeItemsFromSource.addValueChangeListener(event -> gridDragger removeItemsFromSource.addValueChangeListener(event -> gridDragger

Загрузка…
Отмена
Сохранить