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);
}
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());
}
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"));
}
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());
}
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);
}
Aggregations