Search in sources :

Example 21 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class PushConfiguration method getParameters.

/**
 * Gets all configured push parameters.
 *
 * The parameters configured on the server, including transports.
 *
 * @return a map of all parameters configured on the server
 */
public JsMap<String, String> getParameters() {
    MapProperty p = getConfigurationMap().getProperty(PushConfigurationMap.PARAMETERS_KEY);
    StateNode parametersNode = (StateNode) p.getValue();
    NodeMap parametersMap = parametersNode.getMap(NodeFeatures.UI_PUSHCONFIGURATION_PARAMETERS);
    JsMap<String, String> parameters = JsCollections.map();
    parametersMap.forEachProperty((property, key) -> {
        parameters.set(key, (String) property.getValue());
    });
    return parameters;
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 22 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class LoadingIndicatorConfigurator method observe.

/**
 * Observes the given node for loading indicator configuration changes and
 * configures the loading indicator singleton accordingly.
 *
 * @param node
 *            the node containing the loading indicator configuration
 */
public static void observe(StateNode node) {
    NodeMap configMap = node.getMap(NodeFeatures.LOADING_INDICATOR_CONFIGURATION);
    bindInteger(configMap, LoadingIndicatorConfigurationMap.FIRST_DELAY_KEY, LoadingIndicatorConfigurator::setFirstDelay, LoadingIndicatorConfigurationMap.FIRST_DELAY_DEFAULT);
    bindInteger(configMap, LoadingIndicatorConfigurationMap.SECOND_DELAY_KEY, LoadingIndicatorConfigurator::setSecondDelay, LoadingIndicatorConfigurationMap.SECOND_DELAY_DEFAULT);
    bindInteger(configMap, LoadingIndicatorConfigurationMap.THIRD_DELAY_KEY, LoadingIndicatorConfigurator::setThirdDelay, LoadingIndicatorConfigurationMap.THIRD_DELAY_DEFAULT);
    MapProperty defaultThemeProperty = configMap.getProperty(LoadingIndicatorConfigurationMap.DEFAULT_THEME_APPLIED_KEY);
    defaultThemeProperty.addChangeListener(event -> setApplyDefaultTheme(event.getSource().getValueOrDefault(LoadingIndicatorConfigurationMap.DEFAULT_THEME_APPLIED_DEFAULT)));
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 23 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class SimpleElementBindingStrategy method verifyAttachedElement.

private boolean verifyAttachedElement(Element element, StateNode attachNode, String id, String address, BindingContext context) {
    StateNode node = context.node;
    String tag = getTag(attachNode);
    boolean failure = false;
    if (element == null) {
        failure = true;
        Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address + " is not found. The requested tag name is '" + tag + "'");
    } else if (!ElementUtil.hasTag(element, tag)) {
        failure = true;
        Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address + " has the wrong tag name '" + element.getTagName() + "', the requested tag name is '" + tag + "'");
    }
    if (failure) {
        node.getTree().sendExistingElementWithIdAttachToServer(node, attachNode.getId(), -1, id);
        return false;
    }
    if (!node.hasFeature(NodeFeatures.SHADOW_ROOT_DATA)) {
        return true;
    }
    NodeMap map = node.getMap(NodeFeatures.SHADOW_ROOT_DATA);
    StateNode shadowRootNode = (StateNode) map.getProperty(NodeProperties.SHADOW_ROOT).getValue();
    if (shadowRootNode == null) {
        return true;
    }
    NodeList list = shadowRootNode.getList(NodeFeatures.ELEMENT_CHILDREN);
    Integer existingId = null;
    for (int i = 0; i < list.length(); i++) {
        StateNode stateNode = (StateNode) list.get(i);
        Node domNode = stateNode.getDomNode();
        if (domNode.equals(element)) {
            existingId = stateNode.getId();
            break;
        }
    }
    if (existingId != null) {
        Console.warn(ELEMENT_ATTACH_ERROR_PREFIX + address + " has been already attached previously via the node id='" + existingId + "'");
        node.getTree().sendExistingElementWithIdAttachToServer(node, attachNode.getId(), existingId, id);
        return false;
    }
    return true;
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList) DomNode(com.vaadin.client.flow.dom.DomNode) StateNode(com.vaadin.client.flow.StateNode) Node(elemental.dom.Node) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 24 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class SimpleElementBindingStrategy method attachShadow.

private void attachShadow(BindingContext context) {
    NodeMap map = context.node.getMap(NodeFeatures.SHADOW_ROOT_DATA);
    StateNode shadowRootNode = (StateNode) map.getProperty(NodeProperties.SHADOW_ROOT).getValue();
    if (shadowRootNode != null) {
        NativeFunction function = NativeFunction.create("element", "if ( element.shadowRoot ) { return element.shadowRoot; } " + "else { return element.attachShadow({'mode' : 'open'});}");
        Node shadowRoot = (Node) function.call(null, context.htmlNode);
        if (shadowRootNode.getDomNode() == null) {
            shadowRootNode.setDomNode(shadowRoot);
        }
        BindingContext newContext = new BindingContext(shadowRootNode, shadowRoot, context.binderContext);
        bindChildren(newContext);
    }
}
Also used : NativeFunction(com.vaadin.client.flow.util.NativeFunction) DomNode(com.vaadin.client.flow.dom.DomNode) StateNode(com.vaadin.client.flow.StateNode) Node(elemental.dom.Node) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 25 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class SimpleElementBindingStrategy method bindDomEventListeners.

private EventRemover bindDomEventListeners(BindingContext context) {
    NodeMap elementListeners = getDomEventListenerMap(context.node);
    elementListeners.forEachProperty((property, name) -> {
        Computation computation = bindEventHandlerProperty(property, context);
        // Run eagerly to add initial listeners before element is attached
        computation.recompute();
    });
    return elementListeners.addPropertyAddListener(event -> bindEventHandlerProperty(event.getProperty(), context));
}
Also used : Computation(com.vaadin.client.flow.reactive.Computation) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Aggregations

NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)68 StateNode (com.vaadin.client.flow.StateNode)30 Element (elemental.dom.Element)21 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)20 Node (elemental.dom.Node)14 ChildSlotNode (com.vaadin.flow.template.angular.ChildSlotNode)10 ForTemplateNode (com.vaadin.flow.template.angular.ForTemplateNode)10 JsonObject (elemental.json.JsonObject)8 Test (org.junit.Test)6 DomElement (com.vaadin.client.flow.dom.DomElement)5 UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)4 NodeList (com.vaadin.client.flow.nodefeature.NodeList)4 DomNode (com.vaadin.client.flow.dom.DomNode)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 Computation (com.vaadin.client.flow.reactive.Computation)3 NativeFunction (com.vaadin.client.flow.util.NativeFunction)3 JsonValue (elemental.json.JsonValue)3 Command (com.vaadin.client.Command)2 ConstantPool (com.vaadin.client.flow.ConstantPool)2 JsArray (com.vaadin.client.flow.collection.JsArray)2