use of com.vaadin.flow.dom.DisabledUpdateMode in project flow by vaadin.
the class MapSyncRpcHandler method handleNode.
@Override
protected Optional<Runnable> handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_FEATURE);
assert invocationJson.hasKey(JsonConstants.RPC_PROPERTY);
assert invocationJson.hasKey(JsonConstants.RPC_PROPERTY_VALUE);
int featureId = (int) invocationJson.getNumber(JsonConstants.RPC_FEATURE);
Class<? extends NodeFeature> feature = NodeFeatureRegistry.getFeature(featureId);
assert NodeMap.class.isAssignableFrom(feature);
assert ElementPropertyMap.class.equals(feature);
boolean isEnabled = node.isEnabled();
List<DisabledUpdateMode> seenUpdateModes = new ArrayList<>();
String property = invocationJson.getString(JsonConstants.RPC_PROPERTY);
if (node.hasFeature(ElementListenerMap.class)) {
DisabledUpdateMode eventMode = node.getFeature(ElementListenerMap.class).getPropertySynchronizationMode(property);
if (eventMode != null) {
seenUpdateModes.add(eventMode);
}
}
DisabledUpdateMode updateMode = seenUpdateModes.stream().reduce(DisabledUpdateMode::mostPermissive).orElse(null);
if (isEnabled) {
return enqueuePropertyUpdate(node, invocationJson, feature, property);
} else if (DisabledUpdateMode.ALWAYS.equals(updateMode)) {
LoggerFactory.getLogger(MapSyncRpcHandler.class).trace("Property update request for disabled element is received from the client side. " + "Change will be applied since the property '{}' always allows its update.", property);
return enqueuePropertyUpdate(node, invocationJson, feature, property);
} else {
LoggerFactory.getLogger(MapSyncRpcHandler.class).warn("Property update request for disabled element is received from the client side. " + "The property is '{}'. Request is ignored.", property);
}
return Optional.empty();
}
use of com.vaadin.flow.dom.DisabledUpdateMode in project flow by vaadin.
the class ComponentEventBus method addDomTrigger.
/**
* Adds a DOM listener of the given type for the given component event and
* annotation.
*
* @param eventType
* the component event type
* @param annotation
* annotation with event configuration
* @param wrapper
* the listener that is being registered
*/
private <T extends ComponentEvent<?>> void addDomTrigger(Class<T> eventType, com.vaadin.flow.component.DomEvent annotation, ListenerWrapper<T> wrapper) {
assert eventType != null;
assert annotation != null;
String domEventType = annotation.value();
DisabledUpdateMode mode = annotation.allowUpdates();
String filter = annotation.filter();
DebounceSettings debounce = annotation.debounce();
int debounceTimeout = debounce.timeout();
if (domEventType == null || domEventType.isEmpty()) {
throw new IllegalArgumentException("The DOM event type cannot be null or empty");
}
Element element = component.getElement();
// Register DOM event handler
DomListenerRegistration registration = element.addEventListener(domEventType, event -> handleDomEvent(eventType, event, wrapper));
wrapper.domRegistration = registration;
registration.setDisabledUpdateMode(mode);
LinkedHashMap<String, Class<?>> eventDataExpressions = ComponentEventBusUtil.getEventDataExpressions(eventType);
eventDataExpressions.forEach((expression, type) -> {
if (Component.class.isAssignableFrom(type) || type == Element.class) {
registration.addEventDataElement(expression);
} else {
registration.addEventData(expression);
}
});
if (!"".equals(filter)) {
registration.setFilter(filter);
}
if (debounceTimeout != 0) {
DebouncePhase[] phases = debounce.phases();
if (phases.length == 0) {
throw new IllegalStateException("There must be at least one debounce phase");
}
DebouncePhase[] rest = new DebouncePhase[phases.length - 1];
System.arraycopy(phases, 1, rest, 0, rest.length);
registration.debounce(debounceTimeout, phases[0], rest);
}
}
Aggregations