com.github.mvysny.kaributesting.v10.groovy.HasValueUtils.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of karibu-testing-v10-groovy Show documentation
Show all versions of karibu-testing-v10-groovy Show documentation
Karibu Testing, support for browserless Vaadin testing in Kotlin
package com.github.mvysny.kaributesting.v10.groovy
import com.github.mvysny.kaributesting.v10.HasValueUtilsKt
import com.vaadin.flow.component.AbstractField
import com.vaadin.flow.component.HasValue
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable
/**
* A set of basic extension methods for {@link HasValue}-based components such as
* TextField.
* @author Martin Vysny
*/
@CompileStatic
class HasValueUtils {
/**
* Gets the value of given component. Alias for {@link com.vaadin.flow.component.HasValue#getValue()}.
*/
@Nullable
static > V get_value(@NotNull HasValue self) {
return HasValueUtilsKt.get_value(self)
}
/**
* Sets the value of given component, but only if it is actually possible to do so by the user.
* If the component is read-only or disabled, an exception is thrown.
*
* The function fires the value change event; the {@link HasValue.ValueChangeEvent#isFromClient()} will
* return false indicating that the event came from the server. If this is not desired,
* depending on your code, it may be
* possible to call {@link #_fireValueChange(AbstractField, boolean)} with fromClient=true
instead.
* @throws IllegalStateException if the field was not visible, not enabled or was read-only.
*/
static void set_value(@NotNull HasValue, V> self, @Nullable V value) {
HasValueUtilsKt.set_value(self, value)
}
/**
* Sets the value of given component, but only if it is actually possible to do so by the user.
* If the component is read-only or disabled, an exception is thrown.
*
* The function fires the value change event; the {@link HasValue.ValueChangeEvent#isFromClient()} will
* mirror the fromClient
parameter which defaults to `true` indicating that the event came from the client.
* @throws IllegalStateException if the field was not visible, not enabled or was read-only.
*/
static void _setValue(@NotNull HasValue, V> self, @Nullable V value, boolean fromClient = true) {
HasValueUtilsKt._setValue(self, value, fromClient)
}
/**
* Fires a value change event which "comes from the client".
*
* The event is only fired if it is actually possible to do so by the user.
* If the component is read-only or disabled, an exception is thrown.
* @param fromClient defaults to true
* @throws IllegalStateException if the field was not visible, not enabled or was read-only.
*/
static void _fireValueChange(@NotNull AbstractField, ?> self, boolean fromClient = true) {
HasValueUtilsKt._fireValueChange(self as AbstractField, fromClient)
}
}