Java Code Examples for com.google.gwt.core.client.JavaScriptObject#cast()

The following examples show how to use com.google.gwt.core.client.JavaScriptObject#cast() . 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: ApiRegistry.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Will unregister the provided {@link ApiFeature} in to map of features.
 */
public static void unregister(ApiFeature apiFeature) {
    JavaScriptObject scriptObject = features.get(apiFeature);
    if (scriptObject != null) {
        if (scriptObject.cast() instanceof Element) {
            Element scriptElement = scriptObject.cast();
            scriptElement.removeFromParent();
        }
    }
    features.remove(apiFeature);
}
 
Example 2
Source File: GwtMessageHandlerTest.java    From flow with Apache License 2.0 5 votes vote down vote up
public void testMessageProcessing_dynamicDependencyIsHandledBeforeApplyingChangesToTree() {
    resetInternalEvents();

    JavaScriptObject object = JavaScriptObject.createObject();
    JsonObject obj = object.cast();

    // make an empty changes list. It will initiate changes processing
    // anyway
    // Any changes processing should happen AFTER dependencies are loaded
    obj.put("changes", Json.createArray());

    JsonArray array = Json.createArray();

    // create a dependency
    JsonObject dep = Json.createObject();
    dep.put(Dependency.KEY_TYPE, Dependency.Type.DYNAMIC_IMPORT.toString());
    dep.put(Dependency.KEY_URL, "return new Promise(function(resolve){ "
            + "window.testEvents.push('test-dependency'); resolve(); });");
    array.set(0, dep);

    obj.put(LoadMode.LAZY.toString(), array);

    handler.handleJSON(object.cast());

    delayTestFinish(500);

    new Timer() {
        @Override
        public void run() {
            assertEquals("test-dependency", getInternalEvent(0));
            assertEquals(StateTree.class.getName(), getInternalEvent(1));
            finishTest();
        }
    }.schedule(100);
}
 
Example 3
Source File: GwtMessageHandlerTest.java    From flow with Apache License 2.0 5 votes vote down vote up
public void testForceHandleMessage_resyncIsRequested() {
    resetInternalEvents();
    setResyncState(false);

    // given a max message suspension time of 200 ms
    registry.getApplicationConfiguration().setMaxMessageSuspendTimeout(200);

    // when two out-of-order messages happen
    JavaScriptObject object1 = JavaScriptObject.createObject();
    JsonObject obj1 = object1.cast();
    obj1.put("syncId", 1);
    handler.handleJSON(object1.cast());

    JavaScriptObject object2 = JavaScriptObject.createObject();
    JsonObject obj2 = object2.cast();
    obj2.put("syncId", 3);
    handler.handleJSON(object2.cast());

    // then a resync message is sent within 300 ms
    delayTestFinish(500);
    new Timer() {
        @Override
        public void run() {
            assertTrue(getResyncState());
            finishTest();
        }
    }.schedule(300);
}
 
Example 4
Source File: TagsInputBase.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
protected static List<String> toMultiValue(JavaScriptObject js_multi_value) {
    List<String> retValue = new ArrayList<String>();
    
    if (js_multi_value != null) {
        JsArrayString js_string_array = js_multi_value.cast();
        
        for(int i=0; i<js_string_array.length(); i++) {
            retValue.add(js_string_array.get(i));
        }
    }
    
    return retValue;
}
 
Example 5
Source File: GwtMessageHandlerTest.java    From flow with Apache License 2.0 4 votes vote down vote up
public void testMessageProcessing_moduleDependencyIsHandledBeforeApplyingChangesToTree() {
    resetInternalEvents();

    JavaScriptObject object = JavaScriptObject.createObject();
    JsonObject obj = object.cast();

    // make an empty changes list. It will initiate changes processing
    // anyway
    // Any changes processing should happen AFTER dependencies are loaded
    obj.put("changes", Json.createArray());

    JsonArray array = Json.createArray();

    // create a dependency
    JsonObject dep = Json.createObject();
    dep.put(Dependency.KEY_URL, "foo");
    dep.put(Dependency.KEY_TYPE, Dependency.Type.JS_MODULE.toString());
    array.set(0, dep);

    obj.put(LoadMode.EAGER.toString(), array);
    handler.handleJSON(object.cast());

    delayTestFinish(500);

    new Timer() {
        @Override
        public void run() {
            assertTrue(getResourceLoader().scriptUrls.contains("foo"));

            EventsOrder eventsOrder = registry.get(EventsOrder.class);
            assertTrue(eventsOrder.sources.size() >= 2);
            // the first one is resource loaded which means dependency
            // processing
            assertEquals(ResourceLoader.class.getName(),
                    eventsOrder.sources.get(0));
            // the second one is applying changes to StatTree
            assertEquals(StateTree.class.getName(),
                    eventsOrder.sources.get(1));
            finishTest();
        }
    }.schedule(100);
}
 
Example 6
Source File: JsoView.java    From swellrt with Apache License 2.0 2 votes vote down vote up
/**
 * Unsafely cast any jso to a JsoView, exposing its internals.
 *
 * @param jso
 * @return a JsoView of the input javascript object
 */
public static JsoView as(JavaScriptObject jso) {
  return jso.cast();
}
 
Example 7
Source File: JsoView.java    From incubator-retired-wave with Apache License 2.0 2 votes vote down vote up
/**
 * Unsafely cast any jso to a JsoView, exposing its internals.
 *
 * @param jso
 * @return a JsoView of the input javascript object
 */
public static JsoView as(JavaScriptObject jso) {
  return jso.cast();
}