Search in sources :

Example 31 with JavaScriptObject

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

the class ProfilerEditingTarget method saveNewFile.

private void saveNewFile(final String suggestedPath) {
    FileSystemItem fsi;
    if (suggestedPath != null)
        fsi = FileSystemItem.createFile(suggestedPath).getParentPath();
    else
        fsi = workbenchContext_.getDefaultFileDialogDir();
    fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {

        public void execute(final FileSystemItem saveItem, final ProgressIndicator indicator) {
            if (saveItem == null)
                return;
            workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
            final String toPath = saveItem.getPath();
            server_.copyProfile(htmlLocalPath_, toPath, new ServerRequestCallback<JavaScriptObject>() {

                @Override
                public void onResponseReceived(JavaScriptObject response) {
                    savePropertiesWithPath(saveItem.getPath());
                    persistDocumentProperty("isUserSaved", "saved");
                    isUserSaved_ = true;
                    indicator.onCompleted();
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    indicator.onCompleted();
                    globalDisplay_.showErrorMessage("Failed to Save Profile", error.getMessage());
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 32 with JavaScriptObject

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

the class EventBus method fireEvent.

private void fireEvent(GwtEvent<?> event, boolean fromOtherWindow) {
    // the main window
    if (event instanceof CrossWindowEvent && Satellite.isCurrentWindowSatellite() && !fromOtherWindow) {
        CrossWindowEvent<?> crossWindow = (CrossWindowEvent<?>) (event);
        if (crossWindow.forward()) {
            JavaScriptObject jso = serializer_.serialize(event);
            // raise the main window if requested
            if (crossWindow.focusMode() == CrossWindowEvent.MODE_FOCUS)
                pSatellite_.get().focusMainWindow();
            else if (crossWindow.focusMode() == CrossWindowEvent.MODE_AUXILIARY && Desktop.isDesktop())
                Desktop.getFrame().bringMainFrameBehindActive();
            fireEventToMainWindow(jso, pSatellite_.get().getSatelliteName());
        } else {
            super.fireEvent(event);
        }
    } else {
        super.fireEvent(event);
    }
}
Also used : JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 33 with JavaScriptObject

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

the class RemoteServer method sendRemoteServerRequest.

// this code runs in the main workbench and implements the server request
// and then calls back the satellite on the provided js responseCallback
private void sendRemoteServerRequest(final JavaScriptObject sourceWindow, final String scope, final String method, final JavaScriptObject params, final boolean redactLog, final JavaScriptObject responseCallback) {
    // get the WindowEx from the sourceWindow
    final WindowEx srcWnd = sourceWindow.<WindowEx>cast();
    // unwrap the parameter array
    JsArrayEx array = params.cast();
    final JSONArray jsonParams = array.toJSONArray();
    // setup an rpc response handler that proxies back to the js object
    class ResponseHandler extends RpcResponseHandler {

        @Override
        public void onResponseReceived(RpcResponse response) {
            if (!srcWnd.isClosed())
                performCallback(responseCallback, response);
        }

        public void onError(RpcError error) {
            RpcResponse errorResponse = RpcResponse.create(error);
            if (!srcWnd.isClosed())
                performCallback(responseCallback, errorResponse);
        }

        private native void performCallback(JavaScriptObject responseCallback, RpcResponse response);
    }
    ;
    final ResponseHandler responseHandler = new ResponseHandler();
    // setup a retry handler which will call back the second time with
    // the same args (but no retryHandler, ensurin at most 1 retry)
    RetryHandler retryHandler = new RetryHandler() {

        public void onRetry() {
            // retry one time (passing null as last param ensures there
            // is no retry handler installed)
            sendRequest(getSourceWindowName(sourceWindow), scope, method, jsonParams, redactLog, responseHandler, null);
        }

        public void onError(RpcError error) {
            // propagate error which caused the retry to the caller
            responseHandler.onError(error);
        }
    };
    // submit request (retry same request up to one time)
    sendRequest(getSourceWindowName(sourceWindow), scope, method, jsonParams, redactLog, responseHandler, retryHandler);
}
Also used : JsArrayEx(org.rstudio.core.client.js.JsArrayEx) RpcResponseHandler(org.rstudio.core.client.jsonrpc.RpcResponseHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) RpcResponseHandler(org.rstudio.core.client.jsonrpc.RpcResponseHandler) JSONArray(com.google.gwt.json.client.JSONArray) RpcError(org.rstudio.core.client.jsonrpc.RpcError) WindowEx(org.rstudio.core.client.dom.WindowEx) RpcResponse(org.rstudio.core.client.jsonrpc.RpcResponse)

Example 34 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject 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 35 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject 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

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)436 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)333 PerunError (cz.metacentrum.perun.webgui.model.PerunError)212 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)181 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)110 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)110 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)104 ArrayList (java.util.ArrayList)95 JSONObject (com.google.gwt.json.client.JSONObject)79 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)73 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)58 HashMap (java.util.HashMap)34 JSONNumber (com.google.gwt.json.client.JSONNumber)32 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)31 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)31 Map (java.util.Map)25 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)24 JSONString (com.google.gwt.json.client.JSONString)22 Attribute (cz.metacentrum.perun.webgui.model.Attribute)20 Group (cz.metacentrum.perun.webgui.model.Group)19