Search in sources :

Example 6 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class ChunkWindowManager method forwardEventToSatelliteChunk.

private void forwardEventToSatelliteChunk(String docId, String chunkId, CrossWindowEvent<?> event) {
    if (satelliteChunkExists(docId, chunkId)) {
        String windowName = getName(docId, chunkId);
        if (pSatelliteManager_.get().satelliteWindowExists(windowName)) {
            WindowEx satelliteWindow = pSatelliteManager_.get().getSatelliteWindowObject(windowName);
            events_.fireEventToSatellite(event, satelliteWindow);
        }
    }
}
Also used : WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 7 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class WebWindowOpener method openWindowInternal.

private void openWindowInternal(GlobalDisplay globalDisplay, final String url, NewWindowOptions options, final String features, final int width, final int height) {
    String name = options.getName();
    final boolean focus = options.isFocus();
    final OperationWithInput<WindowEx> openOperation = options.getCallback();
    if (name == null)
        name = "_blank";
    if (!name.equals("_blank") && !name.equals("_top") && !name.equals("_parent") && !name.equals("_self")) {
        name += "_" + clientId;
    }
    // Need to make the URL absolute because IE resolves relative URLs
    // against the JavaScript file location, not the window.location like
    // the other browsers do
    final String absUrl = Pattern.create("^/|([a-zA-Z]+:)").match(url, 0) == null ? GWT.getHostPageBaseURL() + url : url;
    final String finalName = name;
    WindowEx window = doOpenWindow(absUrl, finalName, features, focus);
    if (window == null) {
        if (showPopupBlockedMessage()) {
            globalDisplay.showPopupBlockedMessage(new Operation() {

                public void execute() {
                    WindowEx window = doOpenWindow(absUrl, finalName, features, focus);
                    if (window != null) {
                        if (openOperation != null)
                            openOperation.execute(window);
                    }
                }
            });
        }
    } else {
        if (openOperation != null)
            openOperation.execute(window);
    }
}
Also used : Operation(org.rstudio.core.client.widget.Operation) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 8 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class SatelliteManager method dispatchClientEvent.

// dispatch an event to all satellites
public void dispatchClientEvent(JavaScriptObject clientEvent) {
    // list of windows to remove (because they were closed)
    ArrayList<ActiveSatellite> removeWindows = null;
    // iterate over the satellites (make a copy to avoid races if
    // for some reason firing an event creates or destroys a satellite)
    @SuppressWarnings("unchecked") ArrayList<ActiveSatellite> satellites = (ArrayList<ActiveSatellite>) satellites_.clone();
    for (ActiveSatellite satellite : satellites) {
        try {
            // them
            if (pendingEventsBySatelliteName_.containsKey(satellite.getName()))
                continue;
            WindowEx satelliteWnd = satellite.getWindow();
            if (satelliteWnd.isClosed()) {
                if (removeWindows == null)
                    removeWindows = new ArrayList<ActiveSatellite>();
                removeWindows.add(satellite);
            } else {
                callDispatchEvent(satelliteWnd, clientEvent);
            }
        } catch (Throwable e) {
        }
    }
    for (Entry<String, ArrayList<JavaScriptObject>> entry : pendingEventsBySatelliteName_.entrySet()) {
        entry.getValue().add(clientEvent);
    }
    // remove windows if necessary
    if (removeWindows != null) {
        for (ActiveSatellite satellite : removeWindows) {
            satellites_.remove(satellite);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 9 with WindowEx

use of org.rstudio.core.client.dom.WindowEx in project rstudio by rstudio.

the class SatelliteManager method forceReopenSatellite.

// Forcefully reopen a satellite window. This refreshes the window and
// pushes it to the front in Chrome. It should be used as a last resort;
// if responding to a UI event, use openSatellite instead, since Chrome
// permits window.open to reactivate windows in that context. 
public void forceReopenSatellite(final String name, final JavaScriptObject params, boolean activate) {
    Size preferredSize = null;
    Point preferredPos = null;
    for (ActiveSatellite satellite : satellites_) {
        if (satellite.getName().equals(name) && !satellite.getWindow().isClosed()) {
            // save the window's geometry so we can restore it after the window 
            // is destroyed
            final WindowEx win = satellite.getWindow();
            Document doc = win.getDocument();
            preferredSize = new Size(doc.getClientWidth(), doc.getClientHeight());
            preferredPos = new Point(win.getLeft(), win.getTop());
            callNotifyPendingReactivate(win);
            satellite.close();
            break;
        }
    }
    // didn't find an open window to reopen
    if (preferredSize == null)
        return;
    // open a new window with the same geometry as the one we just destroyed,
    // but with the newly supplied set of parameters
    final Size windowSize = preferredSize;
    final Point windowPos = preferredPos;
    openSatellite(name, params, windowSize, false, windowPos, activate);
}
Also used : Size(org.rstudio.core.client.Size) Point(org.rstudio.core.client.Point) WindowEx(org.rstudio.core.client.dom.WindowEx) Document(com.google.gwt.dom.client.Document)

Example 10 with WindowEx

use of org.rstudio.core.client.dom.WindowEx 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)

Aggregations

WindowEx (org.rstudio.core.client.dom.WindowEx)34 JsArrayString (com.google.gwt.core.client.JsArrayString)5 Size (org.rstudio.core.client.Size)5 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 Document (com.google.gwt.dom.client.Document)3 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)3 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)3 ArrayList (java.util.ArrayList)3 Point (org.rstudio.core.client.Point)3 FindTextBox (org.rstudio.core.client.widget.FindTextBox)3 NewWindowOptions (org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions)3 Command (com.google.gwt.user.client.Command)2 ElementEx (org.rstudio.core.client.dom.ElementEx)2 JsObject (org.rstudio.core.client.js.JsObject)2 CanFocus (org.rstudio.core.client.widget.CanFocus)2 Operation (org.rstudio.core.client.widget.Operation)2 ToolbarButton (org.rstudio.core.client.widget.ToolbarButton)2 ToolbarLabel (org.rstudio.core.client.widget.ToolbarLabel)2 SatelliteWindowGeometry (org.rstudio.studio.client.common.satellite.model.SatelliteWindowGeometry)2