Search in sources :

Example 31 with MapProperty

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

the class TreeChangeProcessor method processPutChange.

private static void processPutChange(JsonObject change, StateNode node) {
    MapProperty property = findProperty(change, node);
    if (change.hasKey(JsonConstants.CHANGE_PUT_VALUE)) {
        JsonValue jsonValue = change.get(JsonConstants.CHANGE_PUT_VALUE);
        Object value = ClientJsonCodec.decodeWithoutTypeInfo(jsonValue);
        property.setValue(value);
    } else if (change.hasKey(JsonConstants.CHANGE_PUT_NODE_VALUE)) {
        int childId = (int) change.getNumber(JsonConstants.CHANGE_PUT_NODE_VALUE);
        StateNode child = node.getTree().getNode(childId);
        assert child != null;
        child.setParent(node);
        property.setValue(child);
    } else {
        assert false : "Change should have either value or nodeValue property: " + WidgetUtil.stringify(change);
    }
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject)

Example 32 with MapProperty

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

the class TreeChangeProcessor method processRemoveChange.

private static void processRemoveChange(JsonObject change, StateNode node) {
    MapProperty property = findProperty(change, node);
    property.removeValue();
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty)

Example 33 with MapProperty

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

the class GwtBasicElementBinderTest method testBindVirtualChild_withCorrespondingElementInShadowRoot_byId.

public void testBindVirtualChild_withCorrespondingElementInShadowRoot_byId() {
    Element shadowRootElement = addShadowRootElement(element);
    String childId = "childElement";
    StateNode childNode = createChildNode(childId, element.getTagName());
    NodeMap properties = childNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty fooProperty = properties.getProperty("foo");
    fooProperty.setValue("bar");
    Binder.bind(node, element);
    addVirtualChild(node, childNode, NodeProperties.INJECT_BY_ID, Json.create(childId));
    Element addressedElement = createAndAppendElementToShadowRoot(shadowRootElement, childId, element.getTagName());
    List<Integer> expectedAfterBindingFeatures = Arrays.asList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS, NodeFeatures.ELEMENT_CHILDREN);
    expectedAfterBindingFeatures.forEach(notExpectedFeature -> assertFalse("Child node should not have any features from list " + expectedAfterBindingFeatures + " before binding, but got feature " + notExpectedFeature, childNode.hasFeature(notExpectedFeature)));
    Reactive.flush();
    expectedAfterBindingFeatures.forEach(expectedFeature -> assertTrue("Child node should have all features from list " + expectedAfterBindingFeatures + " before binding, but missing feature " + expectedFeature, childNode.hasFeature(expectedFeature)));
    // nothing has changed: no new child
    assertEquals("No new child should be added to the element after attach", 0, element.getChildElementCount());
    assertEquals("No new child should be added to the shadow root after attach", 1, shadowRootElement.getChildElementCount());
    Element childElement = shadowRootElement.getFirstElementChild();
    assertSame("Existing element should be the same as element in the StateNode object", addressedElement, childElement);
}
Also used : Element(elemental.dom.Element) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 34 with MapProperty

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

the class GwtBasicElementBinderTest method setVisible.

private void setVisible(boolean visible) {
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_DATA);
    MapProperty visibility = map.getProperty(NodeProperties.VISIBLE);
    visibility.setValue(visible);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 35 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty 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)

Aggregations

MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)40 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)18 StateNode (com.vaadin.client.flow.StateNode)12 Test (org.junit.Test)8 Element (elemental.dom.Element)7 JsonObject (elemental.json.JsonObject)6 UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)5 JsonValue (elemental.json.JsonValue)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)2 SchedulerImpl (com.google.gwt.core.client.impl.SchedulerImpl)1 Computation (com.vaadin.client.flow.reactive.Computation)1 FlushListener (com.vaadin.client.flow.reactive.FlushListener)1 Node (elemental.dom.Node)1 NodeList (elemental.dom.NodeList)1 Text (elemental.dom.Text)1 EventRemover (elemental.events.EventRemover)1 MouseEvent (elemental.events.MouseEvent)1 JsonArray (elemental.json.JsonArray)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1