Search in sources :

Example 11 with Registry

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

the class ExecuteJavaScriptProcessorTest method isBound_hasElementHasFeatureAndBound_bound.

@Test
public void isBound_hasElementHasFeatureAndBound_bound() {
    TestJsProcessor processor = new TestJsProcessor();
    Registry registry = processor.getRegistry();
    StateNode node = new StateNode(37, registry.getStateTree());
    // emulate binding
    JsElement element = new JsElement() {
    };
    node.setDomNode(element);
    node.getMap(NodeFeatures.VISIBILITY_DATA).getProperty(NodeProperties.VISIBILITY_BOUND_PROPERTY).setValue(true);
    Assert.assertTrue(processor.isBound(node));
}
Also used : JsElement(elemental.js.dom.JsElement) Registry(com.vaadin.client.Registry) Test(org.junit.Test)

Example 12 with Registry

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

the class GwtDomApiTest method gwtSetUp.

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

        {
            UILifecycle uiLifecycle = new UILifecycle();
            uiLifecycle.setState(UIState.RUNNING);
            set(UILifecycle.class, uiLifecycle);
            set(RequestResponseTracker.class, new RequestResponseTracker(this));
            set(MessageHandler.class, new MessageHandler(this));
            set(ServerRpcQueue.class, new ServerRpcQueue(this));
            set(DependencyLoader.class, new DependencyLoader(this));
            set(ResourceLoader.class, new ResourceLoader(this, false));
        }
    };
    registry.getRequestResponseTracker().startRequest();
}
Also used : ResourceLoader(com.vaadin.client.ResourceLoader) MessageHandler(com.vaadin.client.communication.MessageHandler) ServerRpcQueue(com.vaadin.client.communication.ServerRpcQueue) DependencyLoader(com.vaadin.client.DependencyLoader) Registry(com.vaadin.client.Registry) UILifecycle(com.vaadin.client.UILifecycle) RequestResponseTracker(com.vaadin.client.communication.RequestResponseTracker)

Example 13 with Registry

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

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

the class ExecuteJavaScriptProcessorTest method isBound_noElement_notBound.

@Test
public void isBound_noElement_notBound() {
    TestJsProcessor processor = new TestJsProcessor();
    Registry registry = processor.getRegistry();
    StateNode node = new StateNode(37, registry.getStateTree());
    Assert.assertFalse(processor.isBound(node));
}
Also used : Registry(com.vaadin.client.Registry) Test(org.junit.Test)

Example 15 with Registry

use of com.vaadin.client.Registry 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)

Aggregations

Registry (com.vaadin.client.Registry)18 Test (org.junit.Test)11 JsElement (elemental.js.dom.JsElement)9 ExistingElementMap (com.vaadin.client.ExistingElementMap)4 JsonArray (elemental.json.JsonArray)4 JsonObject (elemental.json.JsonObject)4 InitialPropertiesHandler (com.vaadin.client.InitialPropertiesHandler)2 UILifecycle (com.vaadin.client.UILifecycle)2 MessageHandler (com.vaadin.client.communication.MessageHandler)2 RequestResponseTracker (com.vaadin.client.communication.RequestResponseTracker)2 ServerConnector (com.vaadin.client.communication.ServerConnector)2 DependencyLoader (com.vaadin.client.DependencyLoader)1 ResourceLoader (com.vaadin.client.ResourceLoader)1 ScrollPositionHandler (com.vaadin.client.ScrollPositionHandler)1 ServerRpcQueue (com.vaadin.client.communication.ServerRpcQueue)1 ConstantPool (com.vaadin.client.flow.ConstantPool)1 StateNode (com.vaadin.client.flow.StateNode)1 StateTree (com.vaadin.client.flow.StateTree)1 JsArray (com.vaadin.client.flow.collection.JsArray)1 TemplateRegistry (com.vaadin.client.flow.template.TemplateRegistry)1