use of com.vaadin.client.flow.nodefeature.NodeFeature in project flow by vaadin.
the class StateNode method getMap.
/**
* Gets the node map with the given id. Creates a new map if one doesn't
* already exist.
*
* @param id
* the id of the map
* @return the map with the given id
*/
public NodeMap getMap(int id) {
Double key = Double.valueOf(id);
NodeFeature feature = features.get(key);
if (feature == null) {
feature = new NodeMap(id, this);
features.set(key, feature);
}
assert feature instanceof NodeMap;
return (NodeMap) feature;
}
use of com.vaadin.client.flow.nodefeature.NodeFeature in project flow by vaadin.
the class StateNode method getList.
/**
* Gets the node list with the given id. Creates a new node list if one
* doesn't already exist.
*
* @param id
* the id of the list
* @return the list with the given id
*/
public NodeList getList(int id) {
Double key = Double.valueOf(id);
NodeFeature feature = features.get(key);
if (feature == null) {
feature = new NodeList(id, this);
features.set(key, feature);
}
assert feature instanceof NodeList;
return (NodeList) feature;
}
use of com.vaadin.client.flow.nodefeature.NodeFeature in project flow by vaadin.
the class StateNodeTest method testGetListFeature.
@Test
public void testGetListFeature() {
NodeList list = node.getList(1);
Assert.assertEquals(1, list.getId());
List<NodeFeature> features = collectFeatures();
Assert.assertEquals(Arrays.asList(list), features);
NodeList anotherList = node.getList(1);
Assert.assertSame(anotherList, list);
Assert.assertEquals(features, collectFeatures());
}
use of com.vaadin.client.flow.nodefeature.NodeFeature in project flow by vaadin.
the class StateNodeTest method testGetMapFeature.
@Test
public void testGetMapFeature() {
NodeMap map = node.getMap(1);
Assert.assertEquals(1, map.getId());
List<NodeFeature> features = collectFeatures();
Assert.assertEquals(Arrays.asList(map), features);
NodeMap anotherMap = node.getMap(1);
Assert.assertSame(anotherMap, map);
}
use of com.vaadin.client.flow.nodefeature.NodeFeature in project flow by vaadin.
the class PolymerUtils method convertToJson.
/**
* Makes an attempt to convert an object into json.
*
* @param object
* the object to convert to json
* @return json from object, {@code null} for null
*/
public static JsonValue convertToJson(Object object) {
if (object instanceof StateNode) {
StateNode node = (StateNode) object;
NodeFeature feature = null;
if (node.hasFeature(NodeFeatures.ELEMENT_PROPERTIES)) {
feature = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
} else if (node.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
feature = node.getList(NodeFeatures.TEMPLATE_MODELLIST);
} else if (node.hasFeature(NodeFeatures.BASIC_TYPE_VALUE)) {
return convertToJson(node.getMap(NodeFeatures.BASIC_TYPE_VALUE).getProperty(NodeProperties.VALUE));
}
assert feature != null : "Don't know how to convert node without map or list features";
JsonValue convert = feature.convert(PolymerUtils::convertToJson);
if (convert instanceof JsonObject && !((JsonObject) convert).hasKey("nodeId")) {
((JsonObject) convert).put("nodeId", node.getId());
}
return convert;
} else if (object instanceof MapProperty) {
MapProperty property = (MapProperty) object;
if (property.getMap().getId() == NodeFeatures.BASIC_TYPE_VALUE) {
return convertToJson(property.getValue());
} else {
JsonObject convertedObject = Json.createObject();
convertedObject.put(property.getName(), convertToJson(property.getValue()));
return convertedObject;
}
} else {
return WidgetUtil.crazyJsoCast(object);
}
}
Aggregations