Search in sources :

Example 61 with NodeMap

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

the class SimpleElementBindingStrategy method bindShadowRoot.

private EventRemover bindShadowRoot(BindingContext context) {
    assert context.htmlNode instanceof Element : "Cannot bind shadow root to a Node";
    NodeMap map = context.node.getMap(NodeFeatures.SHADOW_ROOT_DATA);
    attachShadow(context);
    return map.addPropertyAddListener(event -> Reactive.addFlushListener(() -> attachShadow(context)));
}
Also used : DomElement(com.vaadin.client.flow.dom.DomElement) Element(elemental.dom.Element) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 62 with NodeMap

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

the class SimpleElementBindingStrategy method handlePropertyChange.

private void handlePropertyChange(String fullPropertyName, Supplier<Object> valueProvider, StateNode node) {
    UpdatableModelProperties updatableProperties = node.getNodeData(UpdatableModelProperties.class);
    if (updatableProperties == null || !updatableProperties.isUpdatableProperty(fullPropertyName)) {
        // collection of updatable properties
        return;
    }
    // This is not the property value itself, its a parent node of the
    // property
    String[] subProperties = fullPropertyName.split("\\.");
    StateNode model = node;
    MapProperty mapProperty = null;
    int i = 0;
    int size = subProperties.length;
    for (String subProperty : subProperties) {
        NodeMap elementProperties = model.getMap(NodeFeatures.ELEMENT_PROPERTIES);
        if (!elementProperties.hasPropertyValue(subProperty) && i < size - 1) {
            Console.debug("Ignoring property change for property '" + fullPropertyName + "' which isn't defined from server");
            return;
        }
        mapProperty = elementProperties.getProperty(subProperty);
        if (mapProperty.getValue() instanceof StateNode) {
            model = (StateNode) mapProperty.getValue();
        }
        i++;
    }
    if (mapProperty.getValue() instanceof StateNode) {
        // Don't send to the server updates for list nodes
        StateNode nodeValue = (StateNode) mapProperty.getValue();
        JsonObject obj = WidgetUtil.crazyJsCast(valueProvider.get());
        if (!obj.hasKey("nodeId") || nodeValue.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
            return;
        }
    }
    mapProperty.syncToServer(valueProvider.get());
}
Also used : UpdatableModelProperties(com.vaadin.client.flow.model.UpdatableModelProperties) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) JsonObject(elemental.json.JsonObject) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 63 with NodeMap

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

the class SimpleElementBindingStrategy method updateVisibility.

private void updateVisibility(JsArray<EventRemover> listeners, BindingContext context, JsArray<JsMap<String, Computation>> computationsCollection, BinderContext nodeFactory) {
    assert context.htmlNode instanceof Element : "The HTML node for the StateNode with id=" + context.node.getId() + " is not an Element";
    NodeMap visibilityData = context.node.getMap(NodeFeatures.ELEMENT_DATA);
    Element element = (Element) context.htmlNode;
    if (needsRebind(context.node) && isVisible(context.node)) {
        remove(listeners, context, computationsCollection);
        Reactive.addFlushListener(() -> {
            restoreInitialHiddenAttribute(element, visibilityData);
            doBind(context.node, nodeFactory);
        });
    } else if (isVisible(context.node)) {
        visibilityData.getProperty(NodeProperties.VISIBILITY_BOUND_PROPERTY).setValue(true);
        restoreInitialHiddenAttribute(element, visibilityData);
    } else {
        setElementInvisible(element, visibilityData);
    }
}
Also used : DomElement(com.vaadin.client.flow.dom.DomElement) Element(elemental.dom.Element) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 64 with NodeMap

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

the class SimpleElementBindingStrategy method handleListItemPropertyChange.

private static void handleListItemPropertyChange(double nodeId, Element host, String property, Object value, StateTree tree) {
    // Warning : it's important that <code>tree</code> is passed as an
    // argument instead of StateNode or Element ! We have replaced a method
    // in the prototype which means that it may not use the context from the
    // hookUpPolymerElement method. Only a tree may be use as a context
    // since StateTree is a singleton.
    StateNode node = tree.getNode((int) nodeId);
    if (!node.hasFeature(NodeFeatures.ELEMENT_PROPERTIES)) {
        return;
    }
    assert checkParent(node, host) : "Host element is not a parent of the node whose property has changed. " + "This is an implementation error. " + "Most likely it means that there are several StateTrees on the same page " + "(might be possible with portlets) and the target StateTree should not be passed " + "into the method as an argument but somehow detected from the host element. " + "Another option is that host element is calculated incorrectly.";
    // TODO: this code doesn't care about "security feature" which prevents
    // sending
    // data from the client side to the server side if property is not
    // "updatable". See <code>handlePropertyChange</code> and
    // UpdatableModelProperties.
    // It should be aware of that. The current issue is that we don't know
    // the full property path (dot separated) to the property which is a
    // property for the <code>host</code> StateNode and not
    // for the <code>node</code> below. It's tricky to calculate FQN
    // property name at this point though the <code>host</code> element
    // which is
    // the template element could be used for that: a StateNode of
    // <code>host</code> is an ancestor of the <code>node</code> and it
    // should be possible to calculate FQN using this info. Also at the
    // moment
    // AllowClientUpdates ignores bean properties in
    // lists ( if "list" is a property name of list type property and
    // "name" is a property of a bean then
    // "list.name" is not in the UpdatableModelProperties ).
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty mapProperty = map.getProperty(property);
    mapProperty.syncToServer(value);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 65 with NodeMap

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

the class GwtBasicElementBinderTest method testAddStylesAfterUnbind.

public void testAddStylesAfterUnbind() {
    polyfillStyleSetProperty(element);
    Binder.bind(node, element);
    NodeMap styleMap = node.getMap(NodeFeatures.ELEMENT_STYLE_PROPERTIES);
    styleMap.getProperty("color").setValue("red");
    Reactive.flush();
    node.unregister();
    styleMap.getProperty("color").setValue("blue");
    styleMap.getProperty("font-size").setValue("12px");
    Reactive.flush();
    assertEquals("red", element.getStyle().getColor());
}
Also used : 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