Search in sources :

Example 6 with ExistingElementMap

use of com.vaadin.client.ExistingElementMap 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 7 with ExistingElementMap

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

the class ExecuteJavaScriptProcessorTest method execute_nodeParametersAreCorrectlyPassed.

@Test
public void execute_nodeParametersAreCorrectlyPassed() {
    Registry registry = new Registry() {

        {
            StateTree tree = new StateTree(this);
            set(StateTree.class, tree);
            set(ExistingElementMap.class, new ExistingElementMap());
        }
    };
    CollectingExecuteJavaScriptProcessor processor = new CollectingExecuteJavaScriptProcessor(registry);
    StateNode node = new StateNode(10, registry.getStateTree());
    registry.getStateTree().registerNode(node);
    JsElement element = new JsElement() {
    };
    node.setDomNode(element);
    JsonArray json = JsonUtils.createArray(Json.create(JsonCodec.NODE_TYPE), Json.create(node.getId()));
    JsonArray invocation = Stream.of(json, Json.create("$0")).collect(JsonUtils.asArray());
    // JRE impl of the array uses
    processor.execute(JsonUtils.createArray(invocation));
    Assert.assertEquals(1, processor.nodeParametersList.size());
    Assert.assertEquals(1, processor.nodeParametersList.get(0).size());
    JsMap<Object, StateNode> map = processor.nodeParametersList.get(0);
    StateNode stateNode = map.get(element);
    Assert.assertEquals(node, stateNode);
}
Also used : JsonArray(elemental.json.JsonArray) ExistingElementMap(com.vaadin.client.ExistingElementMap) JsElement(elemental.js.dom.JsElement) JsonObject(elemental.json.JsonObject) Registry(com.vaadin.client.Registry) Test(org.junit.Test)

Example 8 with ExistingElementMap

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

the class GwtPropertyElementBinderTest method gwtSetUp.

@Override
protected void gwtSetUp() throws Exception {
    super.gwtSetUp();
    Reactive.reset();
    constantPool = new ConstantPool();
    tree = new CollectingStateTree(constantPool, new ExistingElementMap());
    node = createNode();
    properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    synchronizedPropertyList = new NodeList(0, node);
    element = Browser.getDocument().createElement("div");
}
Also used : NodeList(com.vaadin.client.flow.nodefeature.NodeList) ExistingElementMap(com.vaadin.client.ExistingElementMap)

Aggregations

ExistingElementMap (com.vaadin.client.ExistingElementMap)8 Registry (com.vaadin.client.Registry)4 StateNode (com.vaadin.client.flow.StateNode)3 NodeList (com.vaadin.client.flow.nodefeature.NodeList)3 JsonObject (elemental.json.JsonObject)3 DomNode (com.vaadin.client.flow.dom.DomNode)2 Element (elemental.dom.Element)2 Node (elemental.dom.Node)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ApplicationConfiguration (com.vaadin.client.ApplicationConfiguration)1 InitialPropertiesHandler (com.vaadin.client.InitialPropertiesHandler)1 ConstantPool (com.vaadin.client.flow.ConstantPool)1 StateTree (com.vaadin.client.flow.StateTree)1 JsArray (com.vaadin.client.flow.collection.JsArray)1 TemplateRegistry (com.vaadin.client.flow.template.TemplateRegistry)1 TestElementTemplateNode (com.vaadin.client.flow.template.TestElementTemplateNode)1 JsElement (elemental.js.dom.JsElement)1 JsonArray (elemental.json.JsonArray)1 Test (org.junit.Test)1