Search in sources :

Example 46 with NodeMap

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

the class StateTreeTest method sendNodePropertySyncToServer_notInitialProperty_propertyIsSent.

@Test
public void sendNodePropertySyncToServer_notInitialProperty_propertyIsSent() {
    tree.registerNode(node);
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty property = new MapProperty("foo", map);
    property.setValue("bar");
    connector.clear();
    tree.sendNodePropertySyncToServer(property);
    connector.assertMessage(node, "foo", "bar");
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

Example 47 with NodeMap

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

the class StateTreeTest method sendNodePropertySyncToServer_nodeDetached_propertyNotIsSent.

@Test
public void sendNodePropertySyncToServer_nodeDetached_propertyNotIsSent() {
    tree.registerNode(node);
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty property = new MapProperty("foo", map);
    property.setValue("bar");
    connector.clear();
    tree.unregisterNode(node);
    tree.sendNodePropertySyncToServer(property);
    connector.assertMessage(null, null, null);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

Example 48 with NodeMap

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

the class InitialPropertiesHandlerTest method flushPropertyUpdates_updateIsNotInProgress_collectInitialProperties.

@Test
public void flushPropertyUpdates_updateIsNotInProgress_collectInitialProperties() {
    Mockito.when(tree.isUpdateInProgress()).thenReturn(false);
    StateNode node = new StateNode(1, tree);
    NodeMap properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty serverSidePropertyUpdatedByClient = properties.getProperty("foo");
    serverSidePropertyUpdatedByClient.setValue("bar");
    MapProperty serverSideProperty = properties.getProperty("other");
    serverSideProperty.setValue("value");
    handler.nodeRegistered(node);
    Mockito.when(tree.getNode(node.getId())).thenReturn(node);
    handler.flushPropertyUpdates();
    serverSidePropertyUpdatedByClient.setValue("updated");
    MapProperty clientSideProperty = properties.getProperty("client");
    clientSideProperty.setValue("baz");
    handler.handlePropertyUpdate(serverSidePropertyUpdatedByClient);
    handler.handlePropertyUpdate(clientSideProperty);
    Reactive.flush();
    Assert.assertEquals("bar", properties.getProperty("foo").getValue());
    Assert.assertEquals("value", properties.getProperty("other").getValue());
    Assert.assertEquals("baz", properties.getProperty("client").getValue());
    Mockito.verify(tree, Mockito.times(0)).sendNodePropertySyncToServer(serverSidePropertyUpdatedByClient);
    Mockito.verify(tree, Mockito.times(0)).sendNodePropertySyncToServer(serverSideProperty);
    Mockito.verify(tree).sendNodePropertySyncToServer(clientSideProperty);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

Example 49 with NodeMap

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

the class StateTree method sendNodePropertySyncToServer.

/**
 * Sends a map property sync to the server.
 *
 * @param property
 *            the property that should have its value synced to the server,
 *            not <code>null</code>
 */
public void sendNodePropertySyncToServer(MapProperty property) {
    assert property != null;
    NodeMap nodeMap = property.getMap();
    StateNode node = nodeMap.getNode();
    if (getRegistry().getInitialPropertiesHandler().handlePropertyUpdate(property) || !isValidNode(node)) {
        return;
    }
    registry.getServerConnector().sendNodeSyncMessage(node, nodeMap.getId(), property.getName(), property.getValue());
}
Also used : NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 50 with NodeMap

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

the class StateTree method isVisible.

/**
 * Returns the visibility state of the {@code node}.
 *
 * @param node
 *            the node whose visibility is tested
 * @return {@code true} is the node is visible, {@code false} otherwise
 */
public boolean isVisible(StateNode node) {
    if (!node.hasFeature(NodeFeatures.ELEMENT_DATA)) {
        return true;
    }
    NodeMap visibilityMap = node.getMap(NodeFeatures.ELEMENT_DATA);
    Boolean visibility = (Boolean) visibilityMap.getProperty(NodeProperties.VISIBLE).getValue();
    /*
         * Absence of value or "true" means that the node should be visible. So
         * only "false" means "hide".
         */
    return !Boolean.FALSE.equals(visibility);
}
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