Search in sources :

Example 26 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class RmdOutput method onRenderRmd.

@Override
public void onRenderRmd(final RenderRmdEvent event) {
    quitInitiatedAfterLastRender_ = false;
    final Operation renderOperation = new Operation() {

        @Override
        public void execute() {
            renderInProgress_ = true;
            server_.renderRmd(event.getSourceFile(), event.getSourceLine(), event.getFormat(), event.getEncoding(), event.getParamsFile(), event.asTempfile(), event.getType(), event.getExistingOutputFile(), event.getWorkingDir(), event.getViewerType(), new SimpleRequestCallback<Boolean>() {

                @Override
                public void onError(ServerError error) {
                    renderInProgress_ = false;
                }
            });
        }
    };
    // information back into the preview window.
    if (shinyDoc_ != null && event.getSourceFile().equals(shinyDoc_.getFile()) && !shinyDoc_.getFormat().getFormatName().endsWith(RmdOutputFormat.OUTPUT_PRESENTATION_SUFFIX) && (result_ == null || "shiny".equals(result_.getRuntime()))) {
        final RmdRenderResult result = RmdRenderResult.createFromShinyDoc(shinyDoc_);
        displayHTMLRenderResult(result);
    } else {
        performRenderOperation(renderOperation);
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) ProgressOperation(org.rstudio.core.client.widget.ProgressOperation) Operation(org.rstudio.core.client.widget.Operation) RmdRenderResult(org.rstudio.studio.client.rmarkdown.model.RmdRenderResult)

Example 27 with ServerError

use of org.rstudio.studio.client.server.ServerError 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 28 with ServerError

use of org.rstudio.studio.client.server.ServerError 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 29 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class Presentation method confirmClose.

public void confirmClose(Command onConfirmed) {
    // don't allow close if this is a tutorial
    if (currentState_.isTutorial()) {
        globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Close", "Tutorials cannot be closed");
        return;
    }
    final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 0, "Closing Presentation...").getIndicator();
    server_.closePresentationPane(new ServerRequestCallback<Void>() {

        @Override
        public void onResponseReceived(Void resp) {
            reloadWorkbench();
        }

        @Override
        public void onError(ServerError error) {
            progress.onError(error.getUserMessage());
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) Void(org.rstudio.studio.client.server.Void)

Example 30 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class Source method doOpenSourceFile.

private void doOpenSourceFile(final FileSystemItem file, final TextFileType fileType, final FilePosition position, final String pattern, final int navMethod, final boolean forceHighlightMode) {
    // if the navigation should happen in another window, do that instead
    NavigationResult navResult = windowManager_.navigateToFile(file, position, navMethod);
    // we navigated externally, just skip this
    if (navResult.getType() == NavigationResult.RESULT_NAVIGATED)
        return;
    // we're about to open in this window--if it's the main window, focus it
    if (SourceWindowManager.isMainSourceWindow() && Desktop.isDesktop())
        Desktop.getFrame().bringMainFrameToFront();
    final boolean isDebugNavigation = navMethod == NavigationMethods.DEBUG_STEP || navMethod == NavigationMethods.DEBUG_END;
    final CommandWithArg<EditingTarget> editingTargetAction = new CommandWithArg<EditingTarget>() {

        @Override
        public void execute(EditingTarget target) {
            if (position != null) {
                SourcePosition endPosition = null;
                if (isDebugNavigation) {
                    DebugFilePosition filePos = (DebugFilePosition) position.cast();
                    endPosition = SourcePosition.create(filePos.getEndLine() - 1, filePos.getEndColumn() + 1);
                    if (Desktop.isDesktop() && navMethod != NavigationMethods.DEBUG_END)
                        Desktop.getFrame().bringMainFrameToFront();
                }
                navigate(target, SourcePosition.create(position.getLine() - 1, position.getColumn() - 1), endPosition);
            } else if (pattern != null) {
                Position pos = target.search(pattern);
                if (pos != null) {
                    navigate(target, SourcePosition.create(pos.getRow(), 0), null);
                }
            }
        }

        private void navigate(final EditingTarget target, final SourcePosition srcPosition, final SourcePosition srcEndPosition) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    if (navMethod == NavigationMethods.DEBUG_STEP) {
                        target.highlightDebugLocation(srcPosition, srcEndPosition, true);
                    } else if (navMethod == NavigationMethods.DEBUG_END) {
                        target.endDebugHighlighting();
                    } else {
                        // force highlight mode if requested
                        if (forceHighlightMode)
                            target.forceLineHighlighting();
                        // now navigate to the new position
                        boolean highlight = navMethod == NavigationMethods.HIGHLIGHT_LINE && !uiPrefs_.highlightSelectedLine().getValue();
                        target.navigateToPosition(srcPosition, false, highlight);
                    }
                }
            });
        }
    };
    if (navResult.getType() == NavigationResult.RESULT_RELOCATE) {
        server_.getSourceDocument(navResult.getDocId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(final SourceDocument doc) {
                editingTargetAction.execute(addTab(doc, OPEN_REPLAY));
            }

            @Override
            public void onError(ServerError error) {
                globalDisplay_.showErrorMessage("Document Tab Move Failed", "Couldn't move the tab to this window: \n" + error.getMessage());
            }
        });
        return;
    }
    final CommandWithArg<FileSystemItem> action = new CommandWithArg<FileSystemItem>() {

        @Override
        public void execute(FileSystemItem file) {
            openFile(file, fileType, editingTargetAction);
        }
    };
    // highlight in place.
    if (isDebugNavigation) {
        setPendingDebugSelection();
        for (int i = 0; i < editors_.size(); i++) {
            EditingTarget target = editors_.get(i);
            String path = target.getPath();
            if (path != null && path.equalsIgnoreCase(file.getPath())) {
                // the file's open; just update its highlighting 
                if (navMethod == NavigationMethods.DEBUG_END) {
                    target.endDebugHighlighting();
                } else {
                    view_.selectTab(i);
                    editingTargetAction.execute(target);
                }
                return;
            }
        }
        // open a file just to turn off debug highlighting in the file!
        if (navMethod == NavigationMethods.DEBUG_END)
            return;
    }
    // Warning: event.getFile() can be null (e.g. new Sweave document)
    if (file != null && file.getLength() < 0) {
        // If the file has no size info, stat the file from the server. This
        // is to prevent us from opening large files accidentally.
        server_.stat(file.getPath(), new ServerRequestCallback<FileSystemItem>() {

            @Override
            public void onResponseReceived(FileSystemItem response) {
                action.execute(response);
            }

            @Override
            public void onError(ServerError error) {
                // Couldn't stat the file? Proceed anyway. If the file doesn't
                // exist, we'll let the downstream code be the one to show the
                // error.
                action.execute(file);
            }
        });
    } else {
        action.execute(file);
    }
}
Also used : SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) NavigationResult(org.rstudio.studio.client.workbench.views.source.SourceWindowManager.NavigationResult)

Aggregations

ServerError (org.rstudio.studio.client.server.ServerError)109 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)26 JsArrayString (com.google.gwt.core.client.JsArrayString)22 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)20 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)18 Void (org.rstudio.studio.client.server.Void)16 ArrayList (java.util.ArrayList)13 JsArray (com.google.gwt.core.client.JsArray)12 Command (com.google.gwt.user.client.Command)11 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)9 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)9 Operation (org.rstudio.core.client.widget.Operation)8 Handler (org.rstudio.core.client.command.Handler)7 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)7 JSONString (com.google.gwt.json.client.JSONString)6 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)6 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)6 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)6 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)6