Search in sources :

Example 1 with NewProjectEvent

use of org.rstudio.studio.client.projects.events.NewProjectEvent 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

Timer (com.google.gwt.user.client.Timer)1 InvalidSessionInfo (org.rstudio.studio.client.application.model.InvalidSessionInfo)1 NewProjectEvent (org.rstudio.studio.client.projects.events.NewProjectEvent)1 OpenProjectEvent (org.rstudio.studio.client.projects.events.OpenProjectEvent)1 Workbench (org.rstudio.studio.client.workbench.Workbench)1 SessionInitEvent (org.rstudio.studio.client.workbench.events.SessionInitEvent)1 SessionInfo (org.rstudio.studio.client.workbench.model.SessionInfo)1