Search in sources :

Example 46 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method gwtSetUp.

@Override
protected void gwtSetUp() throws Exception {
    super.gwtSetUp();
    registry = new Registry() {

        {
            set(TemplateRegistry.class, new TemplateRegistry());
            set(ConstantPool.class, new ConstantPool());
            set(ExistingElementMap.class, new ExistingElementMap());
            set(InitialPropertiesHandler.class, new InitialPropertiesHandler(this));
            set(StateTree.class, new StateTree(this) {

                @Override
                public void sendTemplateEventToServer(StateNode node, String methodName, JsArray<?> argValues) {
                    serverMethods.put(methodName, argValues);
                    serverRpcNodes.put(methodName, node);
                }
            });
        }
    };
    tree = registry.getStateTree();
    /**
     * This state node is ALWAYS a template !!!
     */
    stateNode = new StateNode(0, tree) {

        @Override
        public boolean hasFeature(int id) {
            if (id == NodeFeatures.TEMPLATE) {
                return true;
            }
            return super.hasFeature(id);
        }
    };
    // Use the most common model structure by default
    JsonObject modelType = Json.createObject();
    modelType.put(MODEL_KEY, "String");
    setModelType(stateNode, modelType);
}
Also used : InitialPropertiesHandler(com.vaadin.client.InitialPropertiesHandler) StateTree(com.vaadin.client.flow.StateTree) JsArray(com.vaadin.client.flow.collection.JsArray) ConstantPool(com.vaadin.client.flow.ConstantPool) StateNode(com.vaadin.client.flow.StateNode) ExistingElementMap(com.vaadin.client.ExistingElementMap) JsonObject(elemental.json.JsonObject) Registry(com.vaadin.client.Registry)

Example 47 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method testRemoveTemplateFromDom.

public void testRemoveTemplateFromDom() {
    int templateNodeId = 1;
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("span");
    StateNode templateState = new StateNode(1, stateNode.getTree());
    registerTemplateNode(templateNode, templateState, templateNodeId);
    StateNode simpleNode = new StateNode(2, tree);
    simpleNode.getMap(NodeFeatures.ELEMENT_DATA).getProperty(NodeProperties.TAG).setValue("div");
    simpleNode.getList(NodeFeatures.ELEMENT_CHILDREN).add(0, templateState);
    Element element = new SimpleElementBindingStrategy().create(simpleNode);
    Binder.bind(simpleNode, element);
    Reactive.flush();
    assertEquals(1, element.getChildElementCount());
    assertEquals("SPAN", element.getFirstElementChild().getTagName());
    simpleNode.getList(NodeFeatures.ELEMENT_CHILDREN).splice(0, 1);
    Reactive.flush();
    assertEquals(0, element.getChildElementCount());
}
Also used : SimpleElementBindingStrategy(com.vaadin.client.flow.binding.SimpleElementBindingStrategy) Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode)

Example 48 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method testTemplateAttributes_bindOverrideNodeAttribute.

public void testTemplateAttributes_bindOverrideNodeAttribute() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    templateNode.addAttribute("attr1", "value1");
    templateNode.addAttribute("attr2", "value2");
    int id = 37;
    StateNode overrideNode = createSimpleOverrideNode(id);
    Element element = createElement(templateNode, id);
    NodeMap props = overrideNode.getMap(NodeFeatures.ELEMENT_ATTRIBUTES);
    props.getProperty("attr2").setValue("foo");
    Reactive.flush();
    assertEquals("value1", element.getAttribute("attr1"));
    assertEquals("foo", element.getAttribute("attr2"));
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 49 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class GwtTemplateBinderTest method testBindOverrideNodeWhenCreated.

public void testBindOverrideNodeWhenCreated() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    int id = 83;
    StateNode overrideNode = createSimpleOverrideNode(id);
    overrideNode.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("id").setValue("override");
    Element element = createElement(templateNode, id);
    Reactive.flush();
    assertEquals("override", element.getId());
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode)

Example 50 with StateNode

use of com.vaadin.client.flow.StateNode in project flow by vaadin.

the class LoadingIndicatorConfiguratorTest method setup.

@Before
public void setup() {
    StateNode rootNode = registry.getStateTree().getRootNode();
    configuration = rootNode.getMap(NodeFeatures.LOADING_INDICATOR_CONFIGURATION);
    loadingIndicator = registry.getLoadingIndicator();
    LoadingIndicatorConfigurator.observe(rootNode, loadingIndicator);
}
Also used : StateNode(com.vaadin.client.flow.StateNode) Before(org.junit.Before)

Aggregations

StateNode (com.vaadin.client.flow.StateNode)73 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)21 Element (elemental.dom.Element)21 Test (org.junit.Test)16 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)14 Node (elemental.dom.Node)13 JsonObject (elemental.json.JsonObject)11 StateTree (com.vaadin.client.flow.StateTree)9 DomNode (com.vaadin.client.flow.dom.DomNode)9 NodeList (com.vaadin.client.flow.nodefeature.NodeList)7 JsonValue (elemental.json.JsonValue)5 ExistingElementMap (com.vaadin.client.ExistingElementMap)4 JsArray (com.vaadin.client.flow.collection.JsArray)4 NativeFunction (com.vaadin.client.flow.util.NativeFunction)4 JsonArray (elemental.json.JsonArray)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 Command (com.vaadin.client.Command)2 InitialPropertiesHandler (com.vaadin.client.InitialPropertiesHandler)2