Java Code Examples for com.vaadin.client.WidgetUtil#crazyJsCast()
The following examples show how to use
com.vaadin.client.WidgetUtil#crazyJsCast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientJsonCodec.java From flow with Apache License 2.0 | 5 votes |
/** * Converts a JSON array to a JS array. This is a no-op in compiled * JavaScript, but needs special handling for tests running in the JVM. * * @param jsonArray * the JSON array to convert * @return the converted JS array */ public static JsArray<Object> jsonArrayAsJsArray(JsonArray jsonArray) { JsArray<Object> jsArray; if (GWT.isScript()) { jsArray = WidgetUtil.crazyJsCast(jsonArray); } else { jsArray = JsCollections.array(); for (int i = 0; i < jsonArray.length(); i++) { jsArray.push(decodeWithoutTypeInfo(jsonArray.get(i))); } } return jsArray; }
Example 2
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 5 votes |
private void assertUpdateListValues(StateNode nodeWithList) { Binder.bind(node, element); Reactive.flush(); List<String> newList = Arrays.asList("1", "2", "3"); fillNodeWithListItems(nodeWithList, newList); Reactive.flush(); JsonArray argumentsArray = WidgetUtil.crazyJsCast( WidgetUtil.getJsProperty(element, "argumentsArray")); // Since `fillNodeWithListItems` makes separate `add` call for every // element in newList, we will be having // the same number of `splice` calls. assertEquals(newList.size(), argumentsArray.length()); for (int i = 0; i < newList.size(); i++) { JsonArray arguments = argumentsArray.getArray(i); assertEquals(4, arguments.length()); String path = arguments.getString(0); int start = (int) arguments.getNumber(1); int deleteCount = (int) arguments.getNumber(2); String items = arguments.getString(3); assertEquals(MODEL_PROPERTY_NAME + "." + LIST_PROPERTY_NAME, path); assertEquals(i, start); assertEquals(0, deleteCount); assertEquals(newList.get(i), items); } }
Example 3
Source File: GwtJsArrayTest.java From flow with Apache License 2.0 | 5 votes |
/** * Tests that it's possible to cast an instance to its own type. * * Most of the JS produced by GWT does not make any assertions about types, * but explicit casts and some use of generics leads to code that might do a * JavaScript instanceof check for @JsType classes, thus failing if the type * defined in the annotation doesn't match the runtime type. */ public void testCanCast() { // Ok if this doesn't throw ClassCastException JsArray<Object> array = WidgetUtil.crazyJsCast(JsCollections.array()); assertNotNull(array); // Ok if this doesn't throw ClassCastException JsArray<Object> array2 = WidgetUtil .crazyJsCast(JsCollections.array("a", "b")); assertNotNull(array2); }
Example 4
Source File: SimpleElementBindingStrategy.java From flow with Apache License 2.0 | 4 votes |
private void handlePropertyChange(String fullPropertyName, Supplier<Object> valueProvider, StateNode node) { UpdatableModelProperties updatableProperties = node .getNodeData(UpdatableModelProperties.class); if (updatableProperties == null || !updatableProperties.isUpdatableProperty(fullPropertyName)) { // don't do anything if the property/sub-property is not in the // collection of updatable properties return; } // This is not the property value itself, its a parent node of the // property String[] subProperties = fullPropertyName.split("\\."); StateNode model = node; MapProperty mapProperty = null; int i = 0; int size = subProperties.length; for (String subProperty : subProperties) { NodeMap elementProperties = model .getMap(NodeFeatures.ELEMENT_PROPERTIES); if (!elementProperties.hasPropertyValue(subProperty) && i < size - 1) { Console.debug("Ignoring property change for property '" + fullPropertyName + "' which isn't defined from server"); return; } mapProperty = elementProperties.getProperty(subProperty); if (mapProperty.getValue() instanceof StateNode) { model = (StateNode) mapProperty.getValue(); } i++; } if (mapProperty.getValue() instanceof StateNode) { // Don't send to the server updates for list nodes StateNode nodeValue = (StateNode) mapProperty.getValue(); JsonObject obj = WidgetUtil.crazyJsCast(valueProvider.get()); if (!obj.hasKey("nodeId") || nodeValue.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) { return; } } mapProperty.syncToServer(valueProvider.get()); }
Example 5
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 4 votes |
private JsonArray getClientList() { return WidgetUtil.crazyJsCast(WidgetUtil.getJsProperty( WidgetUtil.getJsProperty(element, MODEL_PROPERTY_NAME), LIST_PROPERTY_NAME)); }
Example 6
Source File: GwtJsWeakMapTest.java From flow with Apache License 2.0 | 4 votes |
public void testCanCast() { // Ok if this doesn't throw ClassCastException JsWeakMap<Object, Object> map = WidgetUtil .crazyJsCast(JsCollections.weakMap()); assertNotNull(map); }
Example 7
Source File: StateTree.java From flow with Apache License 2.0 | 3 votes |
/** * Sends a request to call server side method with {@code methodName} using * {@code argsArray} as argument values. * <p> * In cases when the state tree has been changed and we receive a delayed or * deferred template event the event is just ignored. * * @param node * the node referring to the server side instance containing the * method * @param methodName * the method name * @param argsArray * the arguments array for the method * @param promiseId * the promise id to use for getting the result back, or -1 if no * result is expected */ public void sendTemplateEventToServer(StateNode node, String methodName, JsArray<?> argsArray, int promiseId) { if (isValidNode(node)) { JsonArray array = WidgetUtil.crazyJsCast(argsArray); registry.getServerConnector().sendTemplateEventMessage(node, methodName, array, promiseId); } }
Example 8
Source File: GwtJsSetTest.java From flow with Apache License 2.0 | 2 votes |
/** * Tests that it's possible to cast an instance to its own type. * * Most of the JS produced by GWT does not make any assertions about types, * but explicit casts and some use of generics leads to code that might do a * JavaScript instanceof check for @JsType classes, thus failing if the type * defined in the annotation doesn't match the runtime type. */ public void testCanCast() { // Ok if this doesn't throw ClassCastException JsSet<Object> set = WidgetUtil.crazyJsCast(JsCollections.set()); assertNotNull(set); }
Example 9
Source File: GwtJsMapTest.java From flow with Apache License 2.0 | 2 votes |
/** * Tests that it's possible to cast an instance to its own type. * * Most of the JS produced by GWT does not make any assertions about types, * but explicit casts and some use of generics leads to code that might do a * JavaScript instanceof check for @JsType classes, thus failing if the type * defined in the annotation doesn't match the runtime type. */ public void testCanCast() { // Ok if this doesn't throw ClassCastException JsMap<Object, Object> map = WidgetUtil.crazyJsCast(JsCollections.map()); assertNotNull(map); }