Search in sources :

Example 1 with JavaScriptException

use of com.google.gwt.core.client.JavaScriptException in project che by eclipse.

the class RequireJsLoader method require.

public void require(final Callback<JavaScriptObject[], Throwable> callback, final String[] requiredScripts, final String[] moduleKeys) {
    // require with default config
    final RequirejsConfig defaultConfig = RequirejsConfig.create();
    /** Using GWT.getModuleBaseForStaticFiles() blocks CodeMirror to run under Super Dev Mode */
    defaultConfig.setBaseUrl(GWT.getModuleBaseURL());
    defaultConfig.setWaitSeconds(0);
    require(new RequirejsCallback() {

        @Override
        public void onReady(final JsArray<RequirejsModule> modules) {
            final JavaScriptObject[] result = new JavaScriptObject[modules.length()];
            for (int i = 0; i < modules.length(); i++) {
                result[i] = modules.get(i);
            }
            callback.onSuccess(result);
        }
    }, new RequirejsErrorHandler() {

        @Override
        public void onError(final RequireError error) {
            callback.onFailure(new JavaScriptException(error));
        }
    }, defaultConfig, requiredScripts, moduleKeys);
}
Also used : RequirejsConfig(org.eclipse.che.plugin.requirejs.ide.conf.RequirejsConfig) JavaScriptException(com.google.gwt.core.client.JavaScriptException)

Example 2 with JavaScriptException

use of com.google.gwt.core.client.JavaScriptException in project rstudio by rstudio.

the class EditSnippetsDialog method attemptSaveAndClose.

private void attemptSaveAndClose() {
    // record pending edits
    recordEditorState();
    // check for edits we need to save
    JsArray<SnippetData> changedSnippets = JsArray.createArray().cast();
    for (int i = 0; i < snippetTypes_.getItemCount(); i++) {
        EditableSnippets snippets = snippetTypes_.getItemAtIdx(i);
        String edits = snippets.getPendingEdits();
        if (edits != null) {
            String mode = snippets.getEditorMode();
            JavaScriptException ex = SnippetHelper.loadSnippetsForMode(mode, edits);
            if (ex != null) {
                snippetTypes_.setSelectedIndex(i);
                globalDisplay_.showErrorMessage("Error Applying Snippets (" + snippets.getFileTypeLabel() + ")", ex.getDescription());
                // early return (don't close dialog)
                return;
            }
            changedSnippets.push(SnippetData.create(mode, edits));
        }
    }
    // perform the save then close the dialog
    if (changedSnippets.length() > 0) {
        server_.saveSnippets(changedSnippets, new VoidServerRequestCallback() {

            @Override
            protected void onSuccess() {
                closeDialog();
            }
        });
    } else {
        closeDialog();
    }
}
Also used : SnippetData(org.rstudio.studio.client.workbench.snippets.model.SnippetData) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) JavaScriptException(com.google.gwt.core.client.JavaScriptException)

Example 3 with JavaScriptException

use of com.google.gwt.core.client.JavaScriptException in project playn by threerings.

the class HtmlAssets method doXhr.

private void doXhr(final String fullPath, final Callback<String> callback) {
    XMLHttpRequest xhr = XMLHttpRequest.create();
    xhr.setOnReadyStateChange(new ReadyStateChangeHandler() {

        @Override
        public void onReadyStateChange(XMLHttpRequest xhr) {
            int readyState = xhr.getReadyState();
            if (readyState == XMLHttpRequest.DONE) {
                int status = xhr.getStatus();
                // status code 0 will be returned for non-http requests, e.g. file://
                if (status != 0 && (status < 200 || status >= 400)) {
                    PlayN.log().error("xhr::onReadyStateChange[" + fullPath + "](readyState = " + readyState + "; status = " + status + ")");
                    callback.onFailure(new RuntimeException("Error getting " + fullPath + " : " + xhr.getStatusText()));
                } else {
                    if (LOG_XHR_SUCCESS) {
                        PlayN.log().debug("xhr::onReadyStateChange[" + fullPath + "](readyState = " + readyState + "; status = " + status + ")");
                    }
                    // http://code.google.com/p/google-web-toolkit/issues/detail?id=6562
                    try {
                        callback.onSuccess(xhr.getResponseText());
                    } catch (JavaScriptException e) {
                        if (GWT.isProdMode()) {
                            throw e;
                        } else {
                            JavaScriptException materialized = new JavaScriptException(e.getName(), e.getDescription());
                            materialized.setStackTrace(e.getStackTrace());
                            throw materialized;
                        }
                    }
                }
            }
        }
    });
    if (LOG_XHR_SUCCESS) {
        PlayN.log().debug("xhr.open('GET', '" + fullPath + "')...");
    }
    xhr.open("GET", fullPath);
    if (LOG_XHR_SUCCESS) {
        PlayN.log().debug("xhr.send()...");
    }
    xhr.send();
}
Also used : XMLHttpRequest(com.google.gwt.xhr.client.XMLHttpRequest) ReadyStateChangeHandler(com.google.gwt.xhr.client.ReadyStateChangeHandler) JavaScriptException(com.google.gwt.core.client.JavaScriptException)

Example 4 with JavaScriptException

use of com.google.gwt.core.client.JavaScriptException in project playn by threerings.

the class HtmlJson method parse.

@Override
public Object parse(String json) throws JsonParserException {
    try {
        JavaScriptObject jsonParse = jsonParse(json);
        if (!isValueObject(jsonParse))
            throw new JsonParserException(null, "Input JSON was not an object", -1, -1, -1);
        HtmlObject object = (HtmlObject) unwrap0(jsonParse);
        return object;
    } catch (JavaScriptException e) {
        throw new JsonParserException(e, "Failed to parse JSON", -1, -1, -1);
    }
}
Also used : JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonParserException(playn.core.json.JsonParserException) JavaScriptException(com.google.gwt.core.client.JavaScriptException)

Example 5 with JavaScriptException

use of com.google.gwt.core.client.JavaScriptException in project playn by threerings.

the class HtmlJson method parseArray.

@Override
public Array parseArray(String json) throws JsonParserException {
    try {
        JavaScriptObject jsonParse = jsonParse(json);
        if (!isValueArray(jsonParse))
            throw new JsonParserException(null, "Input JSON was not an array", -1, -1, -1);
        HtmlArray array = (HtmlArray) unwrap0(jsonParse);
        return array;
    } catch (JavaScriptException e) {
        throw new JsonParserException(e, "Failed to parse JSON", -1, -1, -1);
    }
}
Also used : JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonParserException(playn.core.json.JsonParserException) JavaScriptException(com.google.gwt.core.client.JavaScriptException)

Aggregations

JavaScriptException (com.google.gwt.core.client.JavaScriptException)6 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 JsonParserException (playn.core.json.JsonParserException)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ReadyStateChangeHandler (com.google.gwt.xhr.client.ReadyStateChangeHandler)1 XMLHttpRequest (com.google.gwt.xhr.client.XMLHttpRequest)1 RequirejsConfig (org.eclipse.che.plugin.requirejs.ide.conf.RequirejsConfig)1 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)1 SnippetData (org.rstudio.studio.client.workbench.snippets.model.SnippetData)1