Search in sources :

Example 1 with CompileNotebookResult

use of org.rstudio.studio.client.notebook.CompileNotebookResult in project rstudio by rstudio.

the class TextEditingTarget method generateNotebook.

private void generateNotebook(final Command executeOnSuccess) {
    // default title
    String defaultTitle = docUpdateSentinel_.getProperty(NOTEBOOK_TITLE);
    if (StringUtil.isNullOrEmpty(defaultTitle))
        defaultTitle = FileSystemItem.getNameFromPath(docUpdateSentinel_.getPath());
    // default author
    String defaultAuthor = docUpdateSentinel_.getProperty(NOTEBOOK_AUTHOR);
    if (StringUtil.isNullOrEmpty(defaultAuthor)) {
        defaultAuthor = prefs_.compileNotebookOptions().getValue().getAuthor();
        if (StringUtil.isNullOrEmpty(defaultAuthor))
            defaultAuthor = session_.getSessionInfo().getUserIdentity();
    }
    // default type
    String defaultType = docUpdateSentinel_.getProperty(NOTEBOOK_TYPE);
    if (StringUtil.isNullOrEmpty(defaultType)) {
        defaultType = prefs_.compileNotebookOptions().getValue().getType();
        if (StringUtil.isNullOrEmpty(defaultType))
            defaultType = CompileNotebookOptions.TYPE_DEFAULT;
    }
    CompileNotebookOptionsDialog dialog = new CompileNotebookOptionsDialog(getId(), defaultTitle, defaultAuthor, defaultType, new OperationWithInput<CompileNotebookOptions>() {

        @Override
        public void execute(CompileNotebookOptions input) {
            server_.createNotebook(input, new SimpleRequestCallback<CompileNotebookResult>() {

                @Override
                public void onResponseReceived(CompileNotebookResult response) {
                    if (response.getSucceeded()) {
                        executeOnSuccess.execute();
                    } else {
                        globalDisplay_.showErrorMessage("Unable to Compile Report", response.getFailureMessage());
                    }
                }
            });
            // save options for this document
            HashMap<String, String> changedProperties = new HashMap<String, String>();
            changedProperties.put(NOTEBOOK_TITLE, input.getNotebookTitle());
            changedProperties.put(NOTEBOOK_AUTHOR, input.getNotebookAuthor());
            changedProperties.put(NOTEBOOK_TYPE, input.getNotebookType());
            docUpdateSentinel_.modifyProperties(changedProperties, null);
            // save global prefs
            CompileNotebookPrefs prefs = CompileNotebookPrefs.create(input.getNotebookAuthor(), input.getNotebookType());
            if (!CompileNotebookPrefs.areEqual(prefs, prefs_.compileNotebookOptions().getValue())) {
                prefs_.compileNotebookOptions().setGlobalValue(prefs);
                prefs_.writeUIPrefs();
            }
        }
    });
    dialog.showModal();
}
Also used : CompileNotebookResult(org.rstudio.studio.client.notebook.CompileNotebookResult) HashMap(java.util.HashMap) CompileNotebookOptionsDialog(org.rstudio.studio.client.notebook.CompileNotebookOptionsDialog) CompileNotebookOptions(org.rstudio.studio.client.notebook.CompileNotebookOptions) CompileNotebookPrefs(org.rstudio.studio.client.notebook.CompileNotebookPrefs) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 HashMap (java.util.HashMap)1 CompileNotebookOptions (org.rstudio.studio.client.notebook.CompileNotebookOptions)1 CompileNotebookOptionsDialog (org.rstudio.studio.client.notebook.CompileNotebookOptionsDialog)1 CompileNotebookPrefs (org.rstudio.studio.client.notebook.CompileNotebookPrefs)1 CompileNotebookResult (org.rstudio.studio.client.notebook.CompileNotebookResult)1