Class TextSelectionDelegate<C extends com.vaadin.flow.component.Component & CanSelectText & CanReceiveSelectionEventsFromClient>

    • Field Detail

      • SELECTED_TEXT_ATTRIBUTE_NAME

        public static final String SELECTED_TEXT_ATTRIBUTE_NAME
        Defines the name of the HTML attribute that contains the selected text.
        See Also:
        Constant Field Values
    • Constructor Detail

      • TextSelectionDelegate

        public TextSelectionDelegate​(C source,
                                     com.vaadin.flow.component.ComponentEventBus eventBus,
                                     com.vaadin.flow.function.SerializableSupplier<String> stringValueSupplier)
        Creates the delegate for a given component.
        Parameters:
        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.
    • Method Detail

      • getSource

        protected final C getSource()
        Gets the source component.
        Returns:
        Source component.
      • getSourceElement

        protected final com.vaadin.flow.dom.Element getSourceElement()
        Gets the element for the source component.
        Returns:
        The element.
      • informClientAboutSendingEvents

        public void informClientAboutSendingEvents​(boolean value)
        Sends information to the client side about whether or not it should forward text selection change events.
        Parameters:
        value - When true, client-side will notify server about changes in text selection.
      • fireTextSelectionEvent

        public void fireTextSelectionEvent​(boolean fromClient,
                                           int start,
                                           int end,
                                           String text)
        Fires text selection event.
        Parameters:
        fromClient - Whether or not the event originates from the client.
        start - Selection start.
        end - Selection end.
        text - Selection text.
      • selectAll

        public void selectAll()
        Description copied from interface: CanSelectText
        Selects entire text in the component.
        Specified by:
        selectAll in interface CanSelectText
      • selectNone

        public void selectNone()
        Description copied from interface: CanSelectText
        Removes the current selection and selects no text.
        Specified by:
        selectNone in interface CanSelectText
      • select

        public void select​(int from,
                           int to)
        Description copied from interface: CanSelectText
        Selects text starting from index from (inclusive) and ending at index to (exclusive).
        Specified by:
        select in interface CanSelectText
        Parameters:
        from - Starting index (inclusive).
        to - Ending index (exclusive).
      • clearSelectionOnValueChange

        public void clearSelectionOnValueChange()
        Handles selection change on value change if there are no client notifications. Does nothing if the component is receiving client-side notifications.
      • onAttach

        public 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.
        Parameters:
        event - Event.
        originalMethod - Method to call. Must not be null.
      • onDetach

        public 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.
        Parameters:
        event - Event.
        originalMethod - Method to call. Must not be null.
      • setReceivingSelectionEventsFromClient

        public void setReceivingSelectionEventsFromClient​(boolean receivingSelectionEventsFromClient)
        Description copied from interface: CanReceiveSelectionEventsFromClient
        Configures sending events by the client-side component. Note: this feature is by default turned off.
        Specified by:
        setReceivingSelectionEventsFromClient in interface CanReceiveSelectionEventsFromClient
        Parameters:
        receivingSelectionEventsFromClient - When false, selecting text in client-side component will not send an event to server-side component. When true, it will.
      • reinitialiseListeners

        public void reinitialiseListeners()
        This method should be called in response to @ClientCallable void reinitialiseListeners() on the owning object.