Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: notify component about identifier provider changes (#13902)
Components like Grid or MultiSelectComboBox are supposed to reuse the identifier provider of the Flow data classes to identify items, for example to manage a selection state. However retrieving the identifier provider from a component is problematic at the moment as developers can set an identifier provider on any data view, and there is no way to react to that apart from extending individual implementations of data view classes to implement a custom notification mechanism that the setIdentifierProvider method was called. This change introduces a IdentifierProviderChangeEvent that is fired when the developer sets an identifier provider on a data view. Components like Grid or MultiSelectComboBox can listen for this event, and retrieve the new identifier provider from it.
- Loading branch information
1 parent
5b22525
commit 44c0e4d
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
flow-data/src/main/java/com/vaadin/flow/data/provider/IdentifierProviderChangeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.vaadin.flow.data.provider; | ||
|
||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.ComponentEvent; | ||
|
||
/** | ||
* Event notifying the component that its identifier provider has been changed | ||
* through a data view. | ||
* | ||
* @param <T> | ||
* the type of item used by the identifier provider | ||
* @param <C> | ||
* the event source type | ||
*/ | ||
public class IdentifierProviderChangeEvent<T, C extends Component> | ||
extends ComponentEvent<C> { | ||
|
||
private final IdentifierProvider<T> identifierProvider; | ||
|
||
/** | ||
* Creates a new event using the given source and the new identifier | ||
* provider. | ||
* | ||
* @param source | ||
* the source component | ||
* @param identifierProvider | ||
* the new identifier provider | ||
*/ | ||
public IdentifierProviderChangeEvent(C source, | ||
IdentifierProvider<T> identifierProvider) { | ||
super(source, false); | ||
this.identifierProvider = identifierProvider; | ||
} | ||
|
||
/** | ||
* Returns the new identifier provider for the component. | ||
* | ||
* @return the new identifier provider | ||
*/ | ||
public IdentifierProvider<T> getIdentifierProvider() { | ||
return identifierProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters