Search in sources :

Example 26 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class RmdOutputPanel method createFrame.

@Override
protected AnchorableFrame createFrame(String url) {
    AnchorableFrame frame = new AnchorableFrame();
    // allow full screen
    Element el = frame.getElement();
    el.setAttribute("webkitallowfullscreen", "");
    el.setAttribute("mozallowfullscreen", "");
    el.setAttribute("allowfullscreen", "");
    frame.navigate(url);
    final Operation initSlides = new Operation() {

        @Override
        public void execute() {
            if (getNavigationMenu().isVisible()) {
                fireSlideIndexChanged();
                slideChangeMonitor_.scheduleRepeating(100);
            }
        }
    };
    if (isShiny_) {
        shinyFrame_.initialize(url, new Operation() {

            @Override
            public void execute() {
                shinyFrame_.setScrollPosition(scrollPosition_);
                initSlides.execute();
            }
        });
    } else {
        // poll for document availability then perform initialization
        // tasks once it's available (addLoadHandler wasn't always 
        // getting called at least under Cocoa WebKit)
        Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

            @Override
            public boolean execute() {
                // see if the document is ready
                AnchorableFrame frame = getFrame();
                if (frame == null)
                    return true;
                IFrameElementEx iframe = frame.getIFrame();
                if (iframe == null)
                    return true;
                Document doc = iframe.getContentDocument();
                if (doc == null)
                    return true;
                initSlides.execute();
                // Even though the document exists, it may not have rendered all
                // its content yet
                ScrollUtil.setScrollPositionOnLoad(frame, scrollPosition_);
                return false;
            }
        }, 50);
    }
    return frame;
}
Also used : Element(com.google.gwt.dom.client.Element) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) IFrameElementEx(org.rstudio.core.client.dom.IFrameElementEx) Operation(org.rstudio.core.client.widget.Operation) AnchorableFrame(org.rstudio.core.client.widget.AnchorableFrame) Document(com.google.gwt.dom.client.Document)

Example 27 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class PDFViewer method openPdfUrl.

// Private methods ---------------------------------------------------------
private void openPdfUrl(final String url, final boolean synctex, boolean restorePosition) {
    int width = 1070;
    int height = 1200;
    Point pos = null;
    // if there's a window open, restore the position when we're done
    if (restorePosition && url.equals(lastSuccessfulPdfUrl_)) {
        // the window closed
        if (haveActivePdfJsWindow())
            locationHash_ = pdfJsWindow_.getLocationHash();
        executeOnPdfLoad_ = createRestorePositionOperation();
    }
    // create the operation to load the PDF--we'll call this when the window
    // is finished opening, or immediately if there's already a window open
    Operation loadPdf = new Operation() {

        @Override
        public void execute() {
            pdfJsWindow_.openPdf(server_.getApplicationURL(url), 0, synctex);
            lastSuccessfulPdfUrl_ = url;
        }
    };
    // in the browser we need to close and reopen the window
    if (haveActivePdfJsWindow() && !Desktop.isDesktop()) {
        width = pdfJsWindow_.getOuterWidth();
        height = pdfJsWindow_.getOuterHeight();
        pos = new Point(pdfJsWindow_.getLeft(), pdfJsWindow_.getTop());
        pdfJsWindow_.close();
        pdfJsWindow_ = null;
    }
    lastSuccessfulPdfUrl_ = null;
    if (!haveActivePdfJsWindow()) {
        // open the window and continue
        String viewerUrl = server_.getApplicationURL("pdf_js/web/viewer.html?file=");
        NewWindowOptions options = new NewWindowOptions();
        options.setName(WINDOW_NAME);
        options.setShowDesktopToolbar(false);
        if (pos != null)
            options.setPosition(pos);
        options.setCallback(new OperationWithInput<WindowEx>() {

            @Override
            public void execute(WindowEx win) {
                initializePdfJsWindow(win);
            }
        });
        executeOnPdfJsLoad_ = loadPdf;
        if (Desktop.isDesktop() && Desktop.getFrame().isCocoa()) {
            // on cocoa, we can open a native window
            display_.openMinimalWindow(viewerUrl, false, width, height, options);
        } else {
            // on Qt, we need to open a web window so window.opener is wired
            display_.openWebMinimalWindow(viewerUrl, false, width, height, options);
        }
    } else {
        // we already have an open window, activate it
        if (Desktop.isDesktop())
            Desktop.getFrame().activateMinimalWindow(WINDOW_NAME);
        loadPdf.execute();
    }
}
Also used : NewWindowOptions(org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions) Point(org.rstudio.core.client.Point) Operation(org.rstudio.core.client.widget.Operation) WindowEx(org.rstudio.core.client.dom.WindowEx) Point(org.rstudio.core.client.Point)

Example 28 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class PDFViewer method viewPdfUrl.

public void viewPdfUrl(final String url, final Integer initialPage) {
    if (initialPage != null) {
        executeOnPdfLoad_ = new Operation() {

            @Override
            public void execute() {
                pdfJsWindow_.goToPage(initialPage.intValue());
            }
        };
    }
    lastSuccessfulPdfPath_ = null;
    openPdfUrl(url, false, initialPage == null);
}
Also used : Operation(org.rstudio.core.client.widget.Operation)

Example 29 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class ProjectSourceControlPreferencesPane method confirmGitRepo.

private void confirmGitRepo(final Command onConfirmed) {
    final ProgressIndicator indicator = getProgressIndicator();
    indicator.onProgress("Checking for git repository...");
    final String projDir = session_.getSessionInfo().getActiveProjectDir().getPath();
    server_.gitHasRepo(projDir, new ServerRequestCallback<Boolean>() {

        @Override
        public void onResponseReceived(Boolean result) {
            indicator.onCompleted();
            if (result) {
                onConfirmed.execute();
            } else {
                globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Confirm New Git Repository", "Do you want to initialize a new git repository " + "for this project?", false, new Operation() {

                    @Override
                    public void execute() {
                        server_.gitInitRepo(projDir, new VoidServerRequestCallback(indicator) {

                            @Override
                            public void onSuccess() {
                                onConfirmed.execute();
                            }

                            @Override
                            public void onFailure() {
                                setVcsSelection(VCSConstants.NO_ID);
                            }
                        });
                    }
                }, new Operation() {

                    @Override
                    public void execute() {
                        setVcsSelection(VCSConstants.NO_ID);
                        indicator.onCompleted();
                    }
                }, true);
            }
        }

        @Override
        public void onError(ServerError error) {
            setVcsSelection(VCSConstants.NO_ID);
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) JsArrayString(com.google.gwt.core.client.JsArrayString) Operation(org.rstudio.core.client.widget.Operation)

Example 30 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class RSAccountConnector method showShinyAppsDialog.

// Private methods --------------------------------------------------------
private void showShinyAppsDialog(final OperationWithInput<Boolean> onCompleted) {
    RSConnectCloudDialog dialog = new RSConnectCloudDialog(new ProgressOperationWithInput<NewRSConnectAccountResult>() {

        @Override
        public void execute(NewRSConnectAccountResult input, ProgressIndicator indicator) {
            processDialogResult(input, indicator, onCompleted);
        }
    }, new Operation() {

        @Override
        public void execute() {
            onCompleted.execute(false);
        }
    });
    dialog.showModal();
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) Operation(org.rstudio.core.client.widget.Operation) NewRSConnectAccountResult(org.rstudio.studio.client.rsconnect.model.NewRSConnectAccountResult)

Aggregations

Operation (org.rstudio.core.client.widget.Operation)47 ServerError (org.rstudio.studio.client.server.ServerError)8 Command (com.google.gwt.user.client.Command)7 ArrayList (java.util.ArrayList)6 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)5 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)5 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)4 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ProgressOperation (org.rstudio.core.client.widget.ProgressOperation)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Timer (com.google.gwt.user.client.Timer)2 HTML (com.google.gwt.user.client.ui.HTML)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 WindowEx (org.rstudio.core.client.dom.WindowEx)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2