Search in sources :

Example 1 with SimpleRequestCallback

use of org.rstudio.studio.client.common.SimpleRequestCallback in project rstudio by rstudio.

the class Projects method handleNewProject.

private void handleNewProject(boolean forceSaveAll, final boolean allowOpenInNewWindow) {
    // first resolve the quit context (potentially saving edited documents   
    // and determining whether to save the R environment on exit)
    applicationQuit_.prepareForQuit("Save Current Workspace", forceSaveAll, new ApplicationQuit.QuitContext() {

        @Override
        public void onReadyToQuit(final boolean saveChanges) {
            projServer_.getNewProjectContext(new SimpleRequestCallback<NewProjectContext>() {

                @Override
                public void onResponseReceived(NewProjectContext context) {
                    NewProjectWizard wiz = new NewProjectWizard(session_.getSessionInfo(), pUIPrefs_.get(), pWorkbenchContext_.get(), new NewProjectInput(FileSystemItem.createDir(pUIPrefs_.get().defaultProjectLocation().getValue()), context), allowOpenInNewWindow, new ProgressOperationWithInput<NewProjectResult>() {

                        @Override
                        public void execute(NewProjectResult newProject, ProgressIndicator indicator) {
                            indicator.onCompleted();
                            createNewProject(newProject, saveChanges);
                        }
                    });
                    wiz.showModal();
                }
            });
        }
    });
}
Also used : NewProjectResult(org.rstudio.studio.client.projects.model.NewProjectResult) NewProjectContext(org.rstudio.studio.client.projects.model.NewProjectContext) ApplicationQuit(org.rstudio.studio.client.application.ApplicationQuit) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) NewProjectInput(org.rstudio.studio.client.projects.model.NewProjectInput) NewProjectWizard(org.rstudio.studio.client.projects.ui.newproject.NewProjectWizard) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 2 with SimpleRequestCallback

use of org.rstudio.studio.client.common.SimpleRequestCallback in project rstudio by rstudio.

the class RmdOutput method onWebsiteFileSaved.

@Override
public void onWebsiteFileSaved(WebsiteFileSavedEvent event) {
    // skip if there is a build in progress
    if (workbenchContext_.isBuildInProgress())
        return;
    // skip if there is a render in progress
    if (renderInProgress_)
        return;
    // skip if there was a quit initiated since the last render
    if (quitInitiatedAfterLastRender_)
        return;
    // is there an output frame?
    if (outputFrame_ == null || outputFrame_.getWindowObject() == null)
        return;
    // is it showing a page from the current site?
    String websiteDir = session_.getSessionInfo().getBuildTargetDir();
    final RmdPreviewParams params = outputFrame_.getPreviewParams();
    if (!params.getTargetFile().startsWith(websiteDir))
        return;
    // is the changed file one that should always produce a rebuild?
    FileSystemItem file = event.getFileSystemItem();
    TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
    String typeId = fileType.getTypeId();
    if (fileType.isR() || typeId.equals(FileTypeRegistry.HTML.getTypeId()) || typeId.equals(FileTypeRegistry.YAML.getTypeId()) || typeId.equals(FileTypeRegistry.JSON.getTypeId())) {
        reRenderPreview();
    } else // is the changed file a markdown document
    if (fileType.isMarkdown()) {
        // included Rmd files always produce a rebuild of the current file
        if (file.getStem().startsWith("_"))
            reRenderPreview();
        // files in subdirectories are also includes so re-render them also
        if (!file.getParentPathString().equals(websiteDir))
            reRenderPreview();
    // ...otherwise leave it alone (requires a knit)
    } else // see if this should result in a copy + refresh
    {
        server_.maybeCopyWebsiteAsset(file.getPath(), new SimpleRequestCallback<Boolean>() {

            @Override
            public void onResponseReceived(Boolean copied) {
                if (copied)
                    outputFrame_.showRmdPreview(params, true);
            }
        });
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 3 with SimpleRequestCallback

use of org.rstudio.studio.client.common.SimpleRequestCallback in project rstudio by rstudio.

the class PresentationPane method createMainToolbar.

@Override
protected Toolbar createMainToolbar() {
    boolean isTutorial = session_.getSessionInfo().getPresentationState().isTutorial();
    Toolbar toolbar = new Toolbar();
    slideNavigationMenu_ = new SlideNavigationToolbarMenu(toolbar);
    slideNavigationMenu_.setEditButtonVisible(!isTutorial);
    toolbar.addLeftSeparator();
    toolbar.addLeftWidget(commands_.presentationFullscreen().createToolbarButton());
    // More
    if (!isTutorial) {
        ToolbarPopupMenu moreMenu = new ToolbarPopupMenu();
        moreMenu.addItem(commands_.clearPresentationCache().createMenuItem(false));
        moreMenu.addSeparator();
        moreMenu.addItem(commands_.presentationViewInBrowser().createMenuItem(false));
        moreMenu.addItem(commands_.presentationSaveAsStandalone().createMenuItem(false));
        ToolbarButton moreButton = new ToolbarButton("More", new ImageResource2x(StandardIcons.INSTANCE.more_actions2x()), moreMenu);
        toolbar.addRightWidget(moreButton);
        // Create the publish button and wire it to our HTML generator
        publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_PRES, false, null);
        publishButton_.setPublishHtmlSource(new PublishHtmlSource() {

            @Override
            public void generatePublishHtml(final CommandWithArg<String> onCompleted) {
                server_.createPresentationRPubsSource(new SimpleRequestCallback<PresentationRPubsSource>() {

                    @Override
                    public void onResponseReceived(PresentationRPubsSource source) {
                        onCompleted.execute(source.getSourceFilePath());
                    }

                    @Override
                    public void onError(ServerError error) {
                        display_.showErrorMessage("Error Saving Presentation", Presentation.getErrorMessage(error));
                    }
                });
            }

            @Override
            public String getTitle() {
                return "Presentation:\n" + getPresentationTitle();
            }
        });
        toolbar.addRightSeparator();
        toolbar.addRightWidget(publishButton_);
    } else {
        toolbar.addRightWidget(commands_.tutorialFeedback().createToolbarButton());
    }
    toolbar.addRightSeparator();
    toolbar.addRightWidget(refreshButton_ = commands_.refreshPresentation().createToolbarButton());
    progressButton_ = new ToolbarButton(CoreResources.INSTANCE.progress_gray(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent e) {
        }
    });
    toolbar.addRightWidget(progressButton_);
    progressButton_.setVisible(false);
    return toolbar;
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback) ToolbarButton(org.rstudio.core.client.widget.ToolbarButton) ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RSConnectPublishButton(org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton) PublishHtmlSource(org.rstudio.studio.client.rsconnect.model.PublishHtmlSource) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) SlideNavigationToolbarMenu(org.rstudio.studio.client.common.presentation.SlideNavigationToolbarMenu) PresentationRPubsSource(org.rstudio.studio.client.workbench.views.presentation.model.PresentationRPubsSource) Toolbar(org.rstudio.core.client.widget.Toolbar)

Example 4 with SimpleRequestCallback

use of org.rstudio.studio.client.common.SimpleRequestCallback in project rstudio by rstudio.

the class RStudioAPI method showDialog.

private void showDialog(String caption, String message, final String url) {
    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.addStyleName(RES.styles().textInfoWidget());
    SafeHtml safeMsg = DialogHtmlSanitizer.sanitizeHtml(message);
    HTML msg = new HTML(safeMsg.asString());
    msg.setWidth("100%");
    verticalPanel.add(msg);
    if (!StringUtil.isNullOrEmpty(url)) {
        HyperlinkLabel link = new HyperlinkLabel(url, new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                RStudioGinjector.INSTANCE.getGlobalDisplay().openWindow(url);
            }
        });
        link.addStyleName(RES.styles().installLink());
        verticalPanel.add(link);
    }
    MessageDialog dlg = new MessageDialog(MessageDialog.INFO, caption, verticalPanel);
    dlg.addButton("OK", new Operation() {

        @Override
        public void execute() {
            server_.showDialogCompleted(null, false, new SimpleRequestCallback<Void>());
        }
    }, true, false);
    dlg.showModal();
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) HTML(com.google.gwt.user.client.ui.HTML) MessageDialog(org.rstudio.core.client.widget.MessageDialog) Operation(org.rstudio.core.client.widget.Operation) HyperlinkLabel(org.rstudio.core.client.widget.HyperlinkLabel) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 5 with SimpleRequestCallback

use of org.rstudio.studio.client.common.SimpleRequestCallback in project rstudio by rstudio.

the class Application method verifyAgreement.

private void verifyAgreement(SessionInfo sessionInfo, final Operation verifiedOperation) {
    // get the agreement (if any)
    final Agreement agreement = sessionInfo.pendingAgreement();
    // execute the verifiedOperation immediately)
    if (agreement != null) {
        // append updated to the title if necessary
        String title = agreement.getTitle();
        if (agreement.getUpdated())
            title += " (Updated)";
        view_.showApplicationAgreement(// title and contents   
        title, agreement.getContents(), // bail to sign in page if the user doesn't confirm
        new Operation() {

            public void execute() {
                if (Desktop.isDesktop()) {
                    Desktop.getFrame().setPendingQuit(DesktopFrame.PENDING_QUIT_AND_EXIT);
                    server_.quitSession(false, null, null, GWT.getHostPageBaseURL(), new SimpleRequestCallback<Boolean>());
                } else
                    navigateToSignIn();
            }
        }, // user confirmed
        new Operation() {

            public void execute() {
                // call verified operation
                verifiedOperation.execute();
                // record agreement on server
                server_.acceptAgreement(agreement, new VoidServerRequestCallback());
            }
        });
    } else {
        // no agreement pending
        verifiedOperation.execute();
    }
}
Also used : Agreement(org.rstudio.studio.client.workbench.model.Agreement) Operation(org.rstudio.core.client.widget.Operation) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Aggregations

SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)9 Operation (org.rstudio.core.client.widget.Operation)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Command (com.google.gwt.user.client.Command)2 ServerError (org.rstudio.studio.client.server.ServerError)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 HTML (com.google.gwt.user.client.ui.HTML)1 MenuItem (com.google.gwt.user.client.ui.MenuItem)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)1 HyperlinkLabel (org.rstudio.core.client.widget.HyperlinkLabel)1 MessageDialog (org.rstudio.core.client.widget.MessageDialog)1 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)1 ProgressOperation (org.rstudio.core.client.widget.ProgressOperation)1 Toolbar (org.rstudio.core.client.widget.Toolbar)1 ToolbarButton (org.rstudio.core.client.widget.ToolbarButton)1