Java Code Examples for com.google.gwt.core.client.JavaScriptObject

The following are top voted examples for showing how to use com.google.gwt.core.client.JavaScriptObject. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: empiria.player   File: ExternalInteractionStateProviderTest.java   View source code 6 votes vote down vote up
@Test
public void shouldReturnEncodedState() throws Exception {
    // GIVEN
    JavaScriptObject givenStateObject = mock(JavaScriptObject.class);
    JSONArray encodedState = mock(JSONArray.class);

    when(externalApiProvider.getExternalApi().getStateFromExternal()).thenReturn(givenStateObject);
    when(stateEncoder.encodeState(givenStateObject)).thenReturn(encodedState);

    // WHEN
    JSONArray result = testObj.getState();

    // THEN
    assertThat(result).isEqualTo(encodedState);
    verify(externalStateSaver).setExternalState(givenStateObject);
}
 
Example 2
Project: empiria.player   File: ModuleJsSocketFactory.java   View source code 6 votes vote down vote up
public static JavaScriptObject createSocketObject(Object module) {
    JavaScriptObject jso = JavaScriptObject.createObject();

    jso = addObjectFunctions(jso, module.getClass().getName());

    if (module instanceof Lockable) {
        jso = addLockableFunctions(jso, module);
    }

    if (module instanceof Resetable) {
        jso = addResetableFunctions(jso, module);
    }

    if (module instanceof Activity) {
        jso = addActivityFunctions(jso, module);
    }

    if (module instanceof IUniqueModule) {
        jso = addUniqueFunctions(jso, module);
    }

    return jso;
}
 
Example 3
Project: unitimes   File: Lookup.java   View source code 6 votes vote down vote up
public static void peopleLookup(String query, final JavaScriptObject callback, String options) {
	final Lookup lookup = new Lookup();
	if (query != null && !query.trim().isEmpty())
		lookup.setQuery(query);
	lookup.addValueChangeHandler(new ValueChangeHandler<PersonInterface>() {
		@Override
		public void onValueChange(ValueChangeEvent<PersonInterface> event) {
			if (event.getValue() != null)
				lookup.fireCallback(callback,
					event.getValue().getId(),
					event.getValue().getFirstName(),
					event.getValue().getMiddleName(),
					event.getValue().getLastName(),
					event.getValue().getEmail(),
					event.getValue().getPhone(),
					event.getValue().getAcademicTitle(),
					event.getValue().getName());
		}
	});
	lookup.setOptions(options);
	lookup.center();
}
 
Example 4
Project: empiria.player   File: FlowActivityEvent.java   View source code 6 votes vote down vote up
public static FlowActivityEvent fromJsObject(JavaScriptObject jsObject) {
    String currTypeString = getTypeJs(jsObject);
    final String groupIdentifierString = getGroupIdentifierJs(jsObject); // NOPMD
    if (currTypeString != null) {
        currTypeString = currTypeString.trim().toUpperCase();
        for (FlowActivityEventType currType : FlowActivityEventType.values()) {
            if (currType.toString().equals(currTypeString)) {
                return new FlowActivityEvent(currType, new GroupIdentifier() { // NOPMD

                    @Override
                    public String getIdentifier() {
                        return groupIdentifierString;
                    }
                });
            }
        }
    }
    return null;
}
 
Example 5
Project: empiria.player   File: ExternalStateEncoderGWTTestCase.java   View source code 6 votes vote down vote up
public void testShouldGetStateObject() {
    // given
    JavaScriptObject state = JavaScriptObject.createObject();
    JSONArray stateArray = new JSONArray();
    stateArray.set(0, new JSONObject(state));

    JSONObject stateObject = new JSONObject();
    stateObject.put("STATE", stateArray);

    JSONArray jsonArray = new JSONArray();
    jsonArray.set(0, stateObject);

    // when
    JavaScriptObject result = testObj.decodeState(jsonArray);

    // then
    assertEquals(result, state);
}
 
Example 6
Project: empiria.player   File: SessionDataCarrier.java   View source code 6 votes vote down vote up
private native JavaScriptObject createJsObject()/*-{
    var obj = [];
    var instance = this;
    obj.getTimeTotal = function () {
        return [email protected]nDataCarrier::timeTotal;
    }
    obj.getVariableTotalValue = function () {
        return [email protected]nDataCarrier::timeTotal;
    }
    obj.getDoneTotal = function () {
        return [email protected]nDataCarrier::doneTotal;
    }
    obj.getTodoTotal = function () {
        return [email protected]nDataCarrier::todoTotal;
    }
    obj.getVisitedCount = function () {
        return [email protected]nDataCarrier::visitedCount;
    }
    return obj;
}-*/;
 
Example 7
Project: empiria.player   File: FlowOptions.java   View source code 6 votes vote down vote up
private native JavaScriptObject createJsObject()/*-{
    var obj = [];
    var instance = this;
    obj.isShowToc = function () {
        return [email protected]FlowOptions::showToC;
    }
    obj.isShowSummary = function () {
        return [email protected]FlowOptions::showSummary;
    }
    obj.getPageItemsDisplayMode = function () {
        return [email protected]FlowOptions::getItemsDisplayModeString()();
    }
    obj.getActivityMode = function () {
        return [email protected]FlowOptions::getActivityModeString()();
    }
    return obj;
}-*/;
 
Example 8
Project: empiria.player   File: TextEditorDesktopOptions.java   View source code 5 votes vote down vote up
private native final JavaScriptObject getDesktopOptions() /*-{
    var options = {
        link: false,
        indent: false,
        outdent: false,
        unlink: false,
        remove: false,
        source: false,
        rule: false
    };
    return options;
}-*/;
 
Example 9
Project: Charba   File: Plugins.java   View source code 5 votes vote down vote up
/**
 * Returns the plugin options, if exist.
 * @param pluginId plugin id.
 * @return java script object used to configure the plugin or <code>null</code> if not exist.
 * @throws InvalidPluginIdException occurs if the plugin id is invalid.
 */
public JavaScriptObject getOptions(String pluginId) throws InvalidPluginIdException{
	// checks the plugin id
	PluginIdChecker.check(pluginId);
	// returns the configuration creating a key by plugin id.
	return getValue(new StandardKey(pluginId));
}
 
Example 10
Project: empiria.player   File: PlayerCoreApiExtension.java   View source code 5 votes vote down vote up
private native int callImportInitialItemIndex(JavaScriptObject playerJsObject)/*-{
    var itemIndex = -1;
    if (typeof playerJsObject.importInitialItemIndex == 'function') {
        var importedIndex = playerJsObject.importInitialItemIndex();
        if (!isNaN(importedIndex)) {
            itemIndex = parseInt(importedIndex);
        }
    }

    return itemIndex;

}-*/;
 
Example 11
Project: empiria.player   File: ModuleJsSocketFactory.java   View source code 5 votes vote down vote up
private static native JavaScriptObject addObjectFunctions(JavaScriptObject jso, String className)/*-{
    var instanceClassName = className;
    jso.getClassName = function () {
        return instanceClassName;
    }
    return jso;
}-*/;
 
Example 12
Project: empiria.player   File: ModuleJsSocketFactory.java   View source code 5 votes vote down vote up
private static native JavaScriptObject addLockableFunctions(JavaScriptObject jso, Object moduleInstance)/*-{
    var instance = moduleInstance;
    jso.lock = function () {
        [email protected]::lock(Z)(true);
    }
    jso.unlock = function () {
        [email protected]::lock(Z)(false);
    }
    return jso;
}-*/;
 
Example 13
Project: empiria.player   File: ModuleJsSocketFactory.java   View source code 5 votes vote down vote up
private static native JavaScriptObject addResetableFunctions(JavaScriptObject jso, Object moduleInstance)/*-{
    var instance = moduleInstance;
    jso.reset = function () {
        [email protected]e::reset()();
    }
    return jso;
}-*/;
 
Example 14
Project: empiria.player   File: TextActionProcessor.java   View source code 5 votes vote down vote up
@Override
public void processSingleAction(FeedbackAction action, FeedbackMark mark) {
    ShowTextAction textAction = (ShowTextAction) action;
    feedbackCounter.add(textAction);

    Element element = textAction.getContent().getValue();
    Widget widget = inlineBodyGenerator.generateInlineBody(element);
    feedbackPresenter.setFeedbackContent(widget, mark);

    JavaScriptObject mathJaxCallback = createCallback(textAction);
    mathJaxNative.renderMath(mathJaxCallback);
}
 
Example 15
Project: empiria.player   File: BookmarkProcessorExtension.java   View source code 5 votes vote down vote up
native JavaScriptObject getExternalBookmarks()/*-{
    var playerJso = [email protected]l.bookmark.BookmarkProcessorExtension::playerJsObject;
    if (typeof playerJso != 'undefined' && playerJso != null && typeof playerJso.getExternalBookmarks == 'function') {
        return playerJso.getExternalBookmarks();
    }
    return null;
}-*/;
 
Example 16
Project: empiria.player   File: ScormSupportExtension.java   View source code 5 votes vote down vote up
private native void initPlayerJsObject(JavaScriptObject playerJsObject)/*-{
    var instance = this;
    playerJsObject.getScore = function () {
        return [email protected]ernal.ScormSupportExtension::getScore()();
    }
    playerJsObject.getScoreMax = function () {
        return [email protected]ernal.ScormSupportExtension::getScoreMax()();
    }
    playerJsObject.getErrors = function () {
        return [email protected]ernal.ScormSupportExtension::getErrors()();
    }
    playerJsObject.getLessonStatus = function () {
        return [email protected]ernal.ScormSupportExtension::getLessonStatus()();
    }
    playerJsObject.getAssessmentTime = function () {
        return [email protected]ernal.ScormSupportExtension::getAssessmentTime()();
    }
    playerJsObject.setMasteryScore = function (ms) {
        return [email protected]ernal.ScormSupportExtension::setMasteryScore(I)(ms);
    }
    playerJsObject.getMistakes = function () {
        return [email protected]ernal.ScormSupportExtension::getMistakes()();
    }
    playerJsObject.getShowAnswers = function () {
        return [email protected]ernal.ScormSupportExtension::getShowAnswers()();
    }
    playerJsObject.getReset = function () {
        return [email protected]ernal.ScormSupportExtension::getReset()();
    }
    playerJsObject.getChecks = function () {
        return [email protected]ernal.ScormSupportExtension::getChecks()();
    }
}-*/;
 
Example 17
Project: empiria.player   File: JsStyleSocketUserExtension.java   View source code 5 votes vote down vote up
private native JavaScriptObject createStyleSocketJs()/*-{
    var instance = this;
    var socket = [];
    socket.getStyle = function (element) {
        return [email protected]rappers.JsStyleSocketUserExtension::getStyle(Lcom/google/gwt/dom/client/Element;)(element);
    }
    return socket;
}-*/;
 
Example 18
Project: empiria.player   File: FlowRequest.java   View source code 5 votes vote down vote up
@Override
public JavaScriptObject toJsObject() {
    String giString = "";
    if (getGroupIdentifier() != null)
        giString = getGroupIdentifier().getIdentifier();
    return createRequestJsObject(getName(), giString);
}
 
Example 19
Project: empiria.player   File: JsPageInterferenceSocketUserExtension.java   View source code 5 votes vote down vote up
private native JavaScriptObject createPageInterferenceSocketJs(JavaScriptObject socketJs)/*-{
    var instance = this;
    var socket = [];
    var ais = socketJs;
    socket.getPageInterferenceSocket = function () {
        return ais;
    }
    return socket;
}-*/;
 
Example 20
Project: empiria.player   File: PlayerCoreApiExtension.java   View source code 5 votes vote down vote up
private void setOptions() {
    JavaScriptObject flowOptionsJs = callImportFlowOptionsJs(playerJsObject);

    if (flowOptionsJs != null) {
        FlowOptions flowOptions = FlowOptions.fromJsObject(flowOptionsJs);
        deliveryEngineSocket.setFlowOptions(flowOptions);
    }

    JavaScriptObject displayOptionsJs = callImportDisplayOptionsJs(playerJsObject);

    if (displayOptionsJs != null) {
        DisplayOptions displayOptions = DisplayOptions.fromJsObject(displayOptionsJs);
        deliveryEngineSocket.setDisplayOptions(displayOptions);
    }
}
 
Example 21
Project: Charba   File: Plugins.java   View source code 5 votes vote down vote up
/**
 * Sets the plugin options. If passed otpions is null, the configuration of plugin will be removed.
 * @param pluginId plugin id.
 * @param options java script object used to configure the plugin. Pass <code>null</code> to remove the configuration if exist.
 * @throws InvalidPluginIdException occurs if the plugin id is invalid.
 */
public void setOptions(String pluginId, JavaScriptObject options) throws InvalidPluginIdException {
	// checks the plugin id
	PluginIdChecker.check(pluginId);
	// creates a key using plugin ID
	Key key = new StandardKey(pluginId);
	// if null, removes the configuration
	if (options == null){
		// removes configuration if exists
		removeIfExists(key);
	} else {
		// stores configuration
		setValue(key, options);
	}
}
 
Example 22
Project: empiria.player   File: DeliveryEngineGWTTestCase.java   View source code 5 votes vote down vote up
public void testDeliveryEventsPageSwitch() {
    types = typesPageSwitch;
    PlayerGinjector injector = PlayerGinjectorFactory.getNewPlayerGinjectorForGWTTestCase();
    de = injector.getDeliveryEngine();
    de.init(JavaScriptObject.createObject());
    Extension ext = new MockDeliveryEventsListenerExtension();
    de.setFlowOptions(new FlowOptions(true, false, PageItemsDisplayMode.ONE, ActivityMode.NORMAL));
    de.loadExtension(ext);
    de.load(getAssessmentXMLData(), getItemXMLDatas());
}
 
Example 23
Project: empiria.player   File: PageChangedEventGWTTestCase.java   View source code 5 votes vote down vote up
public void testShouldSerializeEventWithTypeAndPageIndex() {
    // given
    PageChangedEvent testObj = new PageChangedEvent(EXPECTED_PAGE_INDEX);

    // when
    JavaScriptObject actual = testObj.getJSONObject();
    JSONObject actualJSON = new JSONObject(actual);

    // then
    double actualPage = actualJSON.get("payload").isObject().get("new_page").isNumber().doubleValue();
    assertEquals(actualPage, EXPECTED_PAGE_INDEX, DELTA);

    String actualEventType = actualJSON.get("type").isString().stringValue();
    assertEquals(actualEventType, "page_changed");
}
 
Example 24
Project: empiria.player   File: ConnectionModuleViewImplTest.java   View source code 5 votes vote down vote up
private CssHelper createCssHelperMock() {
    CssHelper cssHelper = spy(new CssHelper());
    Style style = mock(Style.class);
    doReturn("none").when(style).getProperty(Matchers.anyString());
    doReturn(style).when(cssHelper).getComputedStyle(Matchers.any(JavaScriptObject.class));
    return cssHelper;
}
 
Example 25
Project: empiria.player   File: JsFlowCommandSocketUserExtension.java   View source code 5 votes vote down vote up
private native JavaScriptObject createFlowCommandsSocketJs()/*-{
    var instance = this;
    var socket = [];
    socket.executeFlowCommand = function (command) {
        [email protected]rappers.JsFlowCommandSocketUserExtension::executeFlowCommand(Lcom/google/gwt/core/client/JavaScriptObject;)(command);
    }
    return socket;
}-*/;
 
Example 26
Project: empiria.player   File: JsInteractionEventSocketUserExtension.java   View source code 5 votes vote down vote up
private native JavaScriptObject createInteractionRequestSocketJs()/*-{
    var instance = this;
    var socket = [];
    socket.dispatchInteractionEvent = function (request) {
        [email protected]rappers.JsInteractionEventSocketUserExtension::dispatchInteractionEvent(Lcom/google/gwt/core/client/JavaScriptObject;)(request);
    }
    return socket;
}-*/;
 
Example 27
Project: empiria.player   File: SoundJsNative.java   View source code 4 votes vote down vote up
private native void onComplete(JavaScriptObject soundInstance)/*-{
    if (typeof soundInstance.onComplete == 'function') {
        soundInstance.onComplete(soundInstance);
    }
}-*/;
 
Example 28
Project: empiria.player   File: JsFlowDataSocketUserExtension.java   View source code 4 votes vote down vote up
private JavaScriptObject getFlowOptionsJs() {
    return supplier.getFlowOptions().toJsObject();
}
 
Example 29
Project: empiria.player   File: JsStatefulExtension.java   View source code 4 votes vote down vote up
private native String getStateJs(JavaScriptObject extension)/*-{
    if (typeof extension.getStateString == 'function') {
        return extension.getStateString();
    }
    return null;
}-*/;
 
Example 30
Project: Charba   File: AbstractPlugin.java   View source code 4 votes vote down vote up
@Override
public boolean onBeforeEvent(AbstractChart<?, ?> chart, ChartNativeEvent event, JavaScriptObject options){
	return true;
}
 
Example 31
Project: empiria.player   File: SimulationController.java   View source code 4 votes vote down vote up
public void resumeAnimation(JavaScriptObject context) {
    callMethod(context, METHOD_NAME_RESUME_ANIMATION);
}
 
Example 32
Project: empiria.player   File: SimulationController.java   View source code 4 votes vote down vote up
public void onWindowResized(JavaScriptObject context) {
    callMethod(context, METHOD_NAME_WINDOW_RESIZED);
}
 
Example 33
Project: empiria.player   File: SimulationController.java   View source code 4 votes vote down vote up
private void callMethod(JavaScriptObject context, String methodName) {
    methodInvocator.callMethod(context, methodName);
}
 
Example 34
Project: empiria.player   File: JSArrayUtils.java   View source code 4 votes vote down vote up
public static native JavaScriptObject fillArray(JavaScriptObject array, String index, boolean item)/*-{
    array[index] = item;
    return array;
}-*/;
 
Example 35
Project: empiria.player   File: JsBonusExtension.java   View source code 4 votes vote down vote up
private final native String getBonusIdNative(JavaScriptObject extensionJsObject)/*-{
    return extensionJsObject.getBonusId();
}-*/;
 
Example 36
Project: empiria.player   File: TextEditorDesktopOptions.java   View source code 4 votes vote down vote up
@Override
public JavaScriptObject getOptions() {
    return getDesktopOptions();
}
 
Example 37
Project: empiria.player   File: JsSessionDataSocketUserExtension.java   View source code 4 votes vote down vote up
private native void setSessionDataSocketJs(JavaScriptObject extension, JavaScriptObject socket)/*-{
    if (typeof extension.setSessionDataSocket == 'function') {
        extension.setSessionDataSocket(socket);
    }
}-*/;
 
Example 38
Project: Charba   File: AbstractPlugin.java   View source code 4 votes vote down vote up
@Override
public void onBeforeInit(AbstractChart<?, ?> chart, JavaScriptObject options){
}
 
Example 39
Project: empiria.player   File: IdentificationModule.java   View source code 4 votes vote down vote up
@Override
public JavaScriptObject getJsSocket() {
    return ModuleJsSocketFactory.createSocketObject(this);
}
 
Example 40
Project: empiria.player   File: MathJaxNative.java   View source code 4 votes vote down vote up
public void renderMath(JavaScriptObject callback) {
    renderMathNative(callback);
}