Search in sources :

Example 1 with SessionInfo

use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.

the class TextEditingTargetCompilePdfHelper method checkCompilers.

public void checkCompilers(final WarningBarDisplay display, TextFileType fileType) {
    // for all tex files we need to parse magic comments and validate
    // any explict latex proram directive
    ArrayList<TexMagicComment> magicComments = null;
    if (fileType.canCompilePDF()) {
        magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
        String latexProgramDirective = detectLatexProgramDirective(magicComments);
        if (latexProgramDirective != null) {
            if (latexProgramRegistry_.findTypeIgnoreCase(latexProgramDirective) == null) {
                // show warning and bail 
                display.showWarningBar("Unknown LaTeX program type '" + latexProgramDirective + "' specified (valid types are " + latexProgramRegistry_.getPrintableTypeNames() + ")");
                return;
            }
        }
    }
    // for Rnw we first determine the RnwWeave type
    RnwWeave rnwWeave = null;
    RnwWeaveDirective rnwWeaveDirective = null;
    if (fileType.isRnw()) {
        rnwWeaveDirective = detectRnwWeaveDirective(magicComments);
        if (rnwWeaveDirective != null) {
            rnwWeave = rnwWeaveDirective.getRnwWeave();
            if (rnwWeave == null) {
                // show warning and bail 
                display.showWarningBar("Unknown Rnw weave method '" + rnwWeaveDirective.getName() + "' specified (valid types are " + rnwWeaveRegistry_.getPrintableTypeNames() + ")");
                return;
            }
        } else {
            rnwWeave = rnwWeaveRegistry_.findTypeIgnoreCase(prefs_.defaultSweaveEngine().getValue());
        }
    }
    final SessionInfo sessionInfo = session_.getSessionInfo();
    TexCapabilities texCap = sessionInfo.getTexCapabilities();
    final boolean checkForTeX = fileType.canCompilePDF() && !texCap.isTexInstalled();
    final boolean checkForRnwWeave = (rnwWeave != null) && !texCap.isRnwWeaveAvailable(rnwWeave);
    if (checkForTeX || checkForRnwWeave) {
        // alias variables to finals
        final boolean hasRnwWeaveDirective = rnwWeaveDirective != null;
        final RnwWeave fRnwWeave = rnwWeave;
        server_.getTexCapabilities(new ServerRequestCallback<TexCapabilities>() {

            @Override
            public void onResponseReceived(TexCapabilities response) {
                if (checkForTeX && !response.isTexInstalled()) {
                    String warning;
                    if (Desktop.isDesktop())
                        warning = "No TeX installation detected. Please install " + "TeX before compiling.";
                    else
                        warning = "This server does not have TeX installed. You " + "may not be able to compile.";
                    display.showWarningBar(warning);
                } else if (checkForRnwWeave && !response.isRnwWeaveAvailable(fRnwWeave)) {
                    String forContext = "";
                    if (hasRnwWeaveDirective)
                        forContext = "this file";
                    else if (sessionInfo.getActiveProjectFile() != null)
                        forContext = "Rnw files for this project";
                    else
                        forContext = "Rnw files";
                    display.showWarningBar(fRnwWeave.getName() + " is configured to weave " + forContext + " " + "however the " + fRnwWeave.getPackageName() + " package is not installed.");
                } else {
                    display.hideWarningBar();
                }
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
            }
        });
    } else {
        display.hideWarningBar();
    }
}
Also used : RnwWeave(org.rstudio.studio.client.common.rnw.RnwWeave) RnwWeaveDirective(org.rstudio.studio.client.common.rnw.RnwWeaveDirective) ServerError(org.rstudio.studio.client.server.ServerError) TexCapabilities(org.rstudio.studio.client.workbench.model.TexCapabilities) TexMagicComment(org.rstudio.core.client.tex.TexMagicComment) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo)

Example 2 with SessionInfo

use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.

the class VersionControlPage method acceptNavigation.

@Override
protected boolean acceptNavigation() {
    SessionInfo sessionInfo = RStudioGinjector.INSTANCE.getSession().getSessionInfo();
    if (!sessionInfo.isVcsAvailable(getVcsId())) {
        NewProjectResources.Styles styles = NewProjectResources.INSTANCE.styles();
        VerticalPanel verticalPanel = new VerticalPanel();
        verticalPanel.addStyleName(styles.vcsNotInstalledWidget());
        if (Desktop.isDesktop()) {
            HTML msg = new HTML("<p>" + getTitle() + " was not detected " + "on the system path.</p>" + "<p>To create projects from " + getTitle() + " " + "repositories you should install " + getTitle() + " " + "and then restart RStudio.</p>" + "<p>Note that if " + getTitle() + " is installed " + "and not on the path, then you can specify its location using " + "the " + (BrowseCap.isMacintosh() ? "Preferences" : "Options") + " dialog.</p>");
            msg.setWidth("100%");
            verticalPanel.add(msg);
            HelpLink vcsHelpLink = new VcsHelpLink();
            vcsHelpLink.setCaption("Using " + getTitle() + " with RStudio");
            vcsHelpLink.addStyleName(styles.vcsHelpLink());
            verticalPanel.add(vcsHelpLink);
        } else {
            HTML msg = new HTML("<p>An installation of " + getTitle() + " was not detected " + "on this system.</p>" + "<p>To create projects from " + getTitle() + " " + "repositories you should request that your server " + "administrator install the " + getTitle() + " package.</p>");
            msg.setWidth("100%");
            verticalPanel.add(msg);
        }
        MessageDialog dlg = new MessageDialog(MessageDialog.INFO, getTitle() + " Not Found", verticalPanel);
        dlg.addButton("OK", (Operation) null, true, false);
        dlg.showModal();
        return false;
    } else {
        return true;
    }
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) HelpLink(org.rstudio.studio.client.common.HelpLink) VcsHelpLink(org.rstudio.studio.client.common.vcs.VcsHelpLink) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) HTML(com.google.gwt.user.client.ui.HTML) MessageDialog(org.rstudio.core.client.widget.MessageDialog) VcsHelpLink(org.rstudio.studio.client.common.vcs.VcsHelpLink)

Example 3 with SessionInfo

use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.

the class PresentationDispatcher method fireEventFromTutorialDirectory.

private void fireEventFromTutorialDirectory(final GwtEvent<?> event) {
    SessionInfo sessionInfo = session_.getSessionInfo();
    PresentationState state = sessionInfo.getPresentationState();
    FileSystemItem projectDir = sessionInfo.getActiveProjectDir();
    if (state.isTutorial() && (projectDir != null)) {
        if (!workbenchContext_.getCurrentWorkingDir().equalTo(projectDir)) {
            server_.setWorkingDirectory(projectDir.getPath(), new VoidServerRequestCallback() {

                @Override
                protected void onSuccess() {
                    eventBus_.fireEvent(event);
                }
            });
        } else {
            eventBus_.fireEvent(event);
        }
    } else {
        eventBus_.fireEvent(event);
    }
}
Also used : PresentationState(org.rstudio.studio.client.workbench.views.presentation.model.PresentationState) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Example 4 with SessionInfo

use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.

the class Application method go.

public void go(final RootLayoutPanel rootPanel, final Command dismissLoadingProgress) {
    Widget w = view_.getWidget();
    rootPanel.add(w);
    rootPanel.setWidgetTopBottom(w, 0, Style.Unit.PX, 0, Style.Unit.PX);
    rootPanel.setWidgetLeftRight(w, 0, Style.Unit.PX, 0, Style.Unit.PX);
    // attempt init
    pClientInit_.get().execute(new ServerRequestCallback<SessionInfo>() {

        public void onResponseReceived(final SessionInfo sessionInfo) {
            // initialize workbench after verifying agreement
            verifyAgreement(sessionInfo, new Operation() {

                public void execute() {
                    // directly to the user
                    if (ApplicationAction.isSwitchProject()) {
                        new Timer() {

                            @Override
                            public void run() {
                                dismissLoadingProgress.execute();
                            }
                        }.schedule(10000);
                    } else {
                        dismissLoadingProgress.execute();
                    }
                    session_.setSessionInfo(sessionInfo);
                    // initialize workbench
                    initializeWorkbench();
                }
            });
        }

        public void onError(ServerError error) {
            Debug.logError(error);
            dismissLoadingProgress.execute();
            globalDisplay_.showErrorMessage("RStudio Initialization Error", error.getUserMessage());
        }
    });
}
Also used : Timer(com.google.gwt.user.client.Timer) Widget(com.google.gwt.user.client.ui.Widget) InvalidSessionInfo(org.rstudio.studio.client.application.model.InvalidSessionInfo) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) Operation(org.rstudio.core.client.widget.Operation)

Example 5 with SessionInfo

use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.

the class Application method initializeWorkbench.

private void initializeWorkbench() {
    pAceThemes_.get();
    // subscribe to ClientDisconnected event (wait to do this until here
    // because there were spurious ClientDisconnected events occuring
    // after a session interrupt sequence. we couldn't figure out why,
    // and since this is a temporary hack why not add another temporary
    // hack to go with it here :-)
    // TOOD: move this back tot he constructor after we revise the
    // interrupt hack(s)
    events_.addHandler(ClientDisconnectedEvent.TYPE, this);
    // create workbench
    Workbench wb = workbench_.get();
    eventBusProvider_.get().fireEvent(new SessionInitEvent());
    // disable commands
    SessionInfo sessionInfo = session_.getSessionInfo();
    if (!sessionInfo.getAllowShell()) {
        commands_.showShellDialog().remove();
        removeTerminalCommands();
    }
    if (!sessionInfo.getAllowPackageInstallation()) {
        commands_.installPackage().remove();
        commands_.updatePackages().remove();
    }
    if (!sessionInfo.getAllowVcs()) {
        commands_.versionControlProjectSetup().remove();
    }
    if (!sessionInfo.getAllowFileDownloads()) {
        commands_.exportFiles().remove();
    }
    if (!sessionInfo.getAllowFileUploads()) {
        commands_.uploadFile().remove();
    }
    // disable external publishing if requested
    if (!SessionUtils.showExternalPublishUi(session_, uiPrefs_.get())) {
        commands_.publishHTML().remove();
    }
    // hide the agreement menu item if we don't have one
    if (!session_.getSessionInfo().hasAgreement())
        commands_.rstudioAgreement().setVisible(false);
    // remove knit params if they aren't supported
    if (!sessionInfo.getKnitParamsAvailable())
        commands_.knitWithParameters().remove();
    // show the correct set of data import commands
    if (uiPrefs_.get().useDataImport().getValue()) {
        commands_.importDatasetFromFile().remove();
        commands_.importDatasetFromURL().remove();
        commands_.importDatasetFromCsvUsingReadr().setVisible(false);
        commands_.importDatasetFromSAV().setVisible(false);
        commands_.importDatasetFromSAS().setVisible(false);
        commands_.importDatasetFromStata().setVisible(false);
        commands_.importDatasetFromXML().setVisible(false);
        commands_.importDatasetFromODBC().setVisible(false);
        commands_.importDatasetFromJDBC().setVisible(false);
        try {
            String rVersion = sessionInfo.getRVersionsInfo().getRVersion();
            if (ApplicationUtils.compareVersions(rVersion, "3.0.2") >= 0) {
                commands_.importDatasetFromCsvUsingReadr().setVisible(true);
            }
            if (ApplicationUtils.compareVersions(rVersion, "3.1.0") >= 0) {
                commands_.importDatasetFromSAV().setVisible(true);
                commands_.importDatasetFromSAS().setVisible(true);
                commands_.importDatasetFromStata().setVisible(true);
                commands_.importDatasetFromXML().setVisible(true);
            }
            if (ApplicationUtils.compareVersions(rVersion, "3.0.0") >= 0) {
                commands_.importDatasetFromODBC().setVisible(true);
            }
            if (ApplicationUtils.compareVersions(rVersion, "2.4.0") >= 0) {
                commands_.importDatasetFromJDBC().setVisible(true);
            }
        } catch (Exception e) {
        }
        // Removing data import dialogs that are NYI
        commands_.importDatasetFromXML().remove();
        commands_.importDatasetFromJSON().remove();
        commands_.importDatasetFromJDBC().remove();
        commands_.importDatasetFromODBC().remove();
        commands_.importDatasetFromMongo().remove();
    } else {
        commands_.importDatasetFromCsv().remove();
        commands_.importDatasetFromCsvUsingBase().remove();
        commands_.importDatasetFromCsvUsingReadr().remove();
        commands_.importDatasetFromSAV().remove();
        commands_.importDatasetFromSAS().remove();
        commands_.importDatasetFromStata().remove();
        commands_.importDatasetFromXLS().remove();
        commands_.importDatasetFromXML().remove();
        commands_.importDatasetFromJSON().remove();
        commands_.importDatasetFromJDBC().remove();
        commands_.importDatasetFromODBC().remove();
        commands_.importDatasetFromMongo().remove();
    }
    // show workbench
    view_.showWorkbenchView(wb.getMainView().asWidget());
    // hide zoom actual size everywhere but cocoa desktop
    if (!BrowseCap.isCocoaDesktop()) {
        commands_.zoomActualSize().remove();
    }
    // hide zoom in and zoom out in web mode
    if (!Desktop.isDesktop()) {
        commands_.zoomIn().remove();
        commands_.zoomOut().remove();
    }
    // show new session when appropriate
    if (!Desktop.isDesktop()) {
        if (sessionInfo.getMultiSession())
            commands_.newSession().setMenuLabel("New Session...");
        else
            commands_.newSession().remove();
    }
    // toolbar (must be after call to showWorkbenchView because
    // showing the toolbar repositions the workbench view widget)
    showToolbar(uiPrefs_.get().toolbarVisible().getValue());
    // sync to changes in the toolbar visibility state
    uiPrefs_.get().toolbarVisible().addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            showToolbar(event.getValue());
        }
    });
    clientStateUpdaterInstance_ = clientStateUpdater_.get();
    // before we interrogate it for unsaved documents
    if (ApplicationAction.hasAction()) {
        new Timer() {

            @Override
            public void run() {
                if (ApplicationAction.isQuit()) {
                    commands_.quitSession().execute();
                } else if (ApplicationAction.isNewProject()) {
                    ApplicationAction.removeActionFromUrl();
                    events_.fireEvent(new NewProjectEvent(true, false));
                } else if (ApplicationAction.isOpenProject()) {
                    ApplicationAction.removeActionFromUrl();
                    events_.fireEvent(new OpenProjectEvent(true, false));
                } else if (ApplicationAction.isSwitchProject()) {
                    handleSwitchProjectAction();
                }
            }
        }.schedule(500);
    }
}
Also used : NewProjectEvent(org.rstudio.studio.client.projects.events.NewProjectEvent) SessionInitEvent(org.rstudio.studio.client.workbench.events.SessionInitEvent) Timer(com.google.gwt.user.client.Timer) OpenProjectEvent(org.rstudio.studio.client.projects.events.OpenProjectEvent) InvalidSessionInfo(org.rstudio.studio.client.application.model.InvalidSessionInfo) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) Workbench(org.rstudio.studio.client.workbench.Workbench)

Aggregations

SessionInfo (org.rstudio.studio.client.workbench.model.SessionInfo)21 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 SessionInitEvent (org.rstudio.studio.client.workbench.events.SessionInitEvent)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 Timer (com.google.gwt.user.client.Timer)3 JsObject (org.rstudio.core.client.js.JsObject)3 JsArrayString (com.google.gwt.core.client.JsArrayString)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 Inject (com.google.inject.Inject)2 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)2 Operation (org.rstudio.core.client.widget.Operation)2 InvalidSessionInfo (org.rstudio.studio.client.application.model.InvalidSessionInfo)2 GlobalToolbar (org.rstudio.studio.client.application.ui.GlobalToolbar)2 ServerError (org.rstudio.studio.client.server.ServerError)2 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)2 SessionInitHandler (org.rstudio.studio.client.workbench.events.SessionInitHandler)2 ClientInitState (org.rstudio.studio.client.workbench.model.ClientInitState)2 JSObjectStateValue (org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)2 StringStateValue (org.rstudio.studio.client.workbench.model.helper.StringStateValue)2 PresentationState (org.rstudio.studio.client.workbench.views.presentation.model.PresentationState)2