public class TextSelectionDelegate<C extends com.vaadin.flow.component.Component & CanSelectText & CanReceiveSelectionEventsFromClient> extends Object implements Serializable, CanSelectText, CanReceiveSelectionEventsFromClient, TextSelectionNotifier<C>
onAttach onDetach must be overwritten in the delegating class and delegated here.
The source component must implement CanSelectText and CanReceiveSelectionEventsFromClient and delegate them
to this object.
The client-side component must mix in text-selection-mixin.js or otherwise react to needed JS method calls.
Finally, the delegating class must implement methods: @ClientCallable void selectionChanged(int, int, String) and
@ClientCallable void reinitialiseEventListening(). The first method should call this object's
fireTextSelectionEvent(boolean, int, int, String) and the second method should just be delegated to this object.| Modifier and Type | Field and Description |
|---|---|
static String |
SELECTED_TEXT_ATTRIBUTE_NAME
Defines the name of the HTML attribute that contains the selected text.
|
| Constructor and Description |
|---|
TextSelectionDelegate(C source,
com.vaadin.flow.component.ComponentEventBus eventBus,
com.vaadin.flow.function.SerializableSupplier<String> stringValueSupplier)
Creates the delegate for a given component.
|
| Modifier and Type | Method and Description |
|---|---|
com.vaadin.flow.shared.Registration |
addTextSelectionListener(TextSelectionListener<C> listener)
Adds the listener.
|
void |
clearSelectionOnValueChange()
Handles selection change on value change if there are no client notifications.
|
void |
fireTextSelectionEvent(boolean fromClient,
int start,
int end,
String text)
Fires text selection event.
|
protected C |
getSource()
Gets the source component.
|
protected com.vaadin.flow.dom.Element |
getSourceElement()
Gets the element for the source component.
|
void |
informClientAboutSendingEvents(boolean value)
Sends information to the client side about whether or not it should forward text selection change events.
|
boolean |
isReceivingSelectionEventsFromClient()
Check if client will inform server on selection change.
|
void |
onAttach(com.vaadin.flow.component.AttachEvent event,
Consumer<com.vaadin.flow.component.AttachEvent> originalMethod)
Informs client about sending events and calls the original method.
|
void |
onDetach(com.vaadin.flow.component.DetachEvent event,
Consumer<com.vaadin.flow.component.DetachEvent> originalMethod)
Informs client to not send events (if needed) and calls the original method.
|
void |
reinitialiseListeners()
This method should be called in response to
@ClientCallable void reinitialiseListeners() on the owning object. |
void |
select(int from,
int to)
Selects text starting from index
from (inclusive) and ending at index to (exclusive). |
void |
selectAll()
Selects entire text in the component.
|
void |
selectNone()
Removes the current selection and selects no text.
|
void |
setReceivingSelectionEventsFromClient(boolean receivingSelectionEventsFromClient)
Configures sending events by the client-side component.
|
public static final String SELECTED_TEXT_ATTRIBUTE_NAME
public TextSelectionDelegate(C source, com.vaadin.flow.component.ComponentEventBus eventBus, com.vaadin.flow.function.SerializableSupplier<String> stringValueSupplier)
source - Source of all events, data, etc.eventBus - Event bus to use for firing events. Typically, source.getEventBus().stringValueSupplier - Method to obtain current value of the component as a String.protected final C getSource()
protected final com.vaadin.flow.dom.Element getSourceElement()
public void informClientAboutSendingEvents(boolean value)
value - When true, client-side will notify server about changes in text selection.public void fireTextSelectionEvent(boolean fromClient,
int start,
int end,
String text)
fromClient - Whether or not the event originates from the client.start - Selection start.end - Selection end.text - Selection text.public void selectAll()
CanSelectTextselectAll in interface CanSelectTextpublic void selectNone()
CanSelectTextselectNone in interface CanSelectTextpublic void select(int from,
int to)
CanSelectTextfrom (inclusive) and ending at index to (exclusive).select in interface CanSelectTextfrom - Starting index (inclusive).to - Ending index (exclusive).public void clearSelectionOnValueChange()
public void onAttach(com.vaadin.flow.component.AttachEvent event,
Consumer<com.vaadin.flow.component.AttachEvent> originalMethod)
event - Event.originalMethod - Method to call. Must not be null.public void onDetach(com.vaadin.flow.component.DetachEvent event,
Consumer<com.vaadin.flow.component.DetachEvent> originalMethod)
event - Event.originalMethod - Method to call. Must not be null.public com.vaadin.flow.shared.Registration addTextSelectionListener(TextSelectionListener<C> listener)
TextSelectionNotifieraddTextSelectionListener in interface TextSelectionNotifier<C extends com.vaadin.flow.component.Component & CanSelectText & CanReceiveSelectionEventsFromClient>listener - A listener to add.Registration that can be used to stop listening to the event.public boolean isReceivingSelectionEventsFromClient()
CanReceiveSelectionEventsFromClientisReceivingSelectionEventsFromClient in interface CanReceiveSelectionEventsFromClienttrue, each selection change in the client-side component will result in this component broadcasting a TextSelectionEvent.public void setReceivingSelectionEventsFromClient(boolean receivingSelectionEventsFromClient)
CanReceiveSelectionEventsFromClientsetReceivingSelectionEventsFromClient in interface CanReceiveSelectionEventsFromClientreceivingSelectionEventsFromClient - When false, selecting text in client-side component will not send an event to server-side component. When true, it will.public void reinitialiseListeners()
@ClientCallable void reinitialiseListeners() on the owning object.Copyright © 2024 Miki. All rights reserved.