Search in sources :

Example 1 with SessionInitEvent

use of org.rstudio.studio.client.workbench.events.SessionInitEvent 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)

Example 2 with SessionInitEvent

use of org.rstudio.studio.client.workbench.events.SessionInitEvent in project rstudio by rstudio.

the class DesktopApplicationHeader method initialize.

@Inject
public void initialize(final Commands commands, EventBus events, final Session session, ApplicationServerOperations server, Provider<DesktopHooks> pDesktopHooks, Provider<CodeSearch> pCodeSearch, Provider<UIPrefs> pUIPrefs, ErrorManager errorManager, GlobalDisplay globalDisplay, ApplicationQuit appQuit) {
    session_ = session;
    eventBus_ = events;
    pUIPrefs_ = pUIPrefs;
    globalDisplay_ = globalDisplay;
    ignoredUpdates_ = IgnoredUpdates.create();
    server_ = server;
    appQuit_ = appQuit;
    binder_.bind(commands, this);
    commands.mainMenu(new DesktopMenuCallback());
    pDesktopHooks.get();
    commands.uploadFile().remove();
    commands.exportFiles().remove();
    commands.updateCredentials().remove();
    commands.checkForUpdates().setVisible(true);
    commands.showLogFiles().setVisible(true);
    commands.diagnosticsReport().setVisible(true);
    commands.showFolder().setVisible(true);
    events.addHandler(SessionInitEvent.TYPE, new SessionInitHandler() {

        public void onSessionInit(SessionInitEvent sie) {
            final SessionInfo sessionInfo = session.getSessionInfo();
            toolbar_.completeInitialization(sessionInfo);
            new JSObjectStateValue("updates", "ignoredUpdates", ClientState.PERSISTENT, session_.getSessionInfo().getClientState(), false) {

                @Override
                protected void onInit(JsObject value) {
                    if (value != null)
                        ignoredUpdates_ = value.cast();
                }

                @Override
                protected JsObject getValue() {
                    ignoredUpdatesDirty_ = false;
                    return ignoredUpdates_.cast();
                }

                @Override
                protected boolean hasChanged() {
                    return ignoredUpdatesDirty_;
                }
            };
            Scheduler.get().scheduleFinally(new ScheduledCommand() {

                public void execute() {
                    Desktop.getFrame().onWorkbenchInitialized(sessionInfo.getScratchDir());
                    if (sessionInfo.getDisableCheckForUpdates())
                        commands.checkForUpdates().remove();
                    if (!sessionInfo.getDisableCheckForUpdates() && pUIPrefs_.get().checkForUpdates().getValue()) {
                        checkForUpdates(false);
                    }
                }
            });
        }
    });
    events.addHandler(ShowFolderEvent.TYPE, new ShowFolderHandler() {

        public void onShowFolder(ShowFolderEvent event) {
            Desktop.getFrame().showFolder(event.getPath().getPath());
        }
    });
    toolbar_ = new GlobalToolbar(commands, events, pCodeSearch);
    ThemeStyles styles = ThemeResources.INSTANCE.themeStyles();
    toolbar_.addStyleName(styles.desktopGlobalToolbar());
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) SessionInitEvent(org.rstudio.studio.client.workbench.events.SessionInitEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) DesktopMenuCallback(org.rstudio.core.client.command.impl.DesktopMenuCallback) ShowFolderEvent(org.rstudio.studio.client.workbench.views.files.events.ShowFolderEvent) GlobalToolbar(org.rstudio.studio.client.application.ui.GlobalToolbar) ThemeStyles(org.rstudio.core.client.theme.res.ThemeStyles) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) SessionInitHandler(org.rstudio.studio.client.workbench.events.SessionInitHandler) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue) ShowFolderHandler(org.rstudio.studio.client.workbench.views.files.events.ShowFolderHandler) Inject(com.google.inject.Inject)

Example 3 with SessionInitEvent

use of org.rstudio.studio.client.workbench.events.SessionInitEvent in project rstudio by rstudio.

the class WebApplicationHeader method initialize.

@Inject
public void initialize(final Commands commands, EventBus eventBus, GlobalDisplay globalDisplay, ThemeResources themeResources, final Session session, Provider<CodeSearch> pCodeSearch) {
    commands_ = commands;
    eventBus_ = eventBus;
    globalDisplay_ = globalDisplay;
    overlay_ = new WebApplicationHeaderOverlay();
    // Use the outer panel to just aggregate the menu bar/account area,
    // with the logo. The logo can't be inside the HorizontalPanel because
    // it needs to overflow out of the top of the panel, and it was much
    // easier to do this with absolute positioning.
    outerPanel_ = new FlowPanel();
    outerPanel_.getElement().getStyle().setPosition(Position.RELATIVE);
    // large logo
    logoLarge_ = new Image(new ImageResource2x(ThemeResources.INSTANCE.rstudio2x()));
    ((ImageElement) logoLarge_.getElement().cast()).setAlt("RStudio");
    logoLarge_.getElement().getStyle().setBorderWidth(0, Unit.PX);
    // small logo
    logoSmall_ = new Image(new ImageResource2x(ThemeResources.INSTANCE.rstudio_small2x()));
    ((ImageElement) logoSmall_.getElement().cast()).setAlt("RStudio");
    logoSmall_.getElement().getStyle().setBorderWidth(0, Unit.PX);
    // link target for logo
    logoAnchor_ = new Anchor();
    Style style = logoAnchor_.getElement().getStyle();
    style.setPosition(Position.ABSOLUTE);
    style.setTop(5, Unit.PX);
    style.setLeft(18, Unit.PX);
    style.setTextDecoration(TextDecoration.NONE);
    style.setOutlineWidth(0, Unit.PX);
    // header container
    headerBarPanel_ = new HorizontalPanel();
    headerBarPanel_.setStylePrimaryName(themeResources.themeStyles().header());
    headerBarPanel_.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    headerBarPanel_.setWidth("100%");
    if (BrowseCap.INSTANCE.suppressBrowserForwardBack())
        suppressBrowserForwardBack();
    // override Cmd+W keybaord shortcut for Chrome
    if (BrowseCap.isChrome()) {
        int modifiers = (BrowseCap.hasMetaKey() ? KeyboardShortcut.META : KeyboardShortcut.CTRL) | KeyboardShortcut.ALT;
        AppCommand closeSourceDoc = commands.closeSourceDoc();
        closeSourceDoc.setShortcut(new KeyboardShortcut(modifiers, 'W'));
        ShortcutManager.INSTANCE.register(modifiers, 'W', closeSourceDoc, "", "", "");
    }
    // main menu
    advertiseEditingShortcuts(globalDisplay, commands);
    WebMenuCallback menuCallback = new WebMenuCallback();
    commands.mainMenu(menuCallback);
    mainMenu_ = menuCallback.getMenu();
    mainMenu_.setAutoHideRedundantSeparators(false);
    fixup(mainMenu_);
    mainMenu_.addStyleName(themeResources.themeStyles().mainMenu());
    AppMenuBar.addSubMenuVisibleChangedHandler(new SubMenuVisibleChangedHandler() {

        public void onSubMenuVisibleChanged(SubMenuVisibleChangedEvent event) {
            // so that mouse clicks can make the menus disappear
            if (event.isVisible())
                eventBus_.fireEvent(new GlassVisibilityEvent(true));
            else
                eventBus_.fireEvent(new GlassVisibilityEvent(false));
        }
    });
    headerBarPanel_.add(mainMenu_);
    // commands panel (no widgets added until after session init)
    headerBarCommandsPanel_ = new HorizontalPanel();
    headerBarCommandsPanel_.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    headerBarCommandsPanel_.setWidth("100%");
    headerBarPanel_.add(headerBarCommandsPanel_);
    headerBarPanel_.setCellWidth(headerBarCommandsPanel_, "100%");
    headerBarPanel_.setCellHorizontalAlignment(headerBarCommandsPanel_, HorizontalPanel.ALIGN_RIGHT);
    eventBus.addHandler(SessionInitEvent.TYPE, new SessionInitHandler() {

        public void onSessionInit(SessionInitEvent sie) {
            SessionInfo sessionInfo = session.getSessionInfo();
            // complete toolbar initialization
            toolbar_.completeInitialization(sessionInfo);
            // add project tools to main menu
            projectMenuSeparator_ = createCommandSeparator();
            headerBarPanel_.add(projectMenuSeparator_);
            projectMenuButton_ = new ProjectPopupMenu(sessionInfo, commands).getToolbarButton();
            projectMenuButton_.addStyleName(ThemeStyles.INSTANCE.webHeaderBarCommandsProjectMenu());
            headerBarPanel_.add(projectMenuButton_);
            showProjectMenu(!toolbar_.isVisible());
            // record logo target url (if any)
            logoTargetUrl_ = sessionInfo.getUserHomePageUrl();
            if (logoTargetUrl_ != null) {
                logoAnchor_.setHref(logoTargetUrl_);
                logoAnchor_.setTitle("RStudio Server Home");
                logoLarge_.setResource(new ImageResource2x(ThemeResources.INSTANCE.rstudio_home2x()));
                logoSmall_.setResource(new ImageResource2x(ThemeResources.INSTANCE.rstudio_home_small2x()));
            } else {
                // no link, so ensure this doesn't get styled as clickable
                logoAnchor_.getElement().getStyle().setCursor(Cursor.DEFAULT);
            }
            // init commands panel in server mode
            if (!Desktop.isDesktop())
                initCommandsPanel(sessionInfo);
            // notify overlay of global toolbar state
            overlay_.setGlobalToolbarVisible(WebApplicationHeader.this, toolbar_.isVisible());
        }
    });
    // create toolbar
    toolbar_ = new GlobalToolbar(commands, eventBus, pCodeSearch);
    toolbar_.addStyleName(themeResources.themeStyles().webGlobalToolbar());
    // create host for project commands
    projectBarCommandsPanel_ = new HorizontalPanel();
    toolbar_.addRightWidget(projectBarCommandsPanel_);
    // initialize widget
    initWidget(outerPanel_);
}
Also used : SessionInitEvent(org.rstudio.studio.client.workbench.events.SessionInitEvent) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) ProjectPopupMenu(org.rstudio.studio.client.application.ui.ProjectPopupMenu) SessionInitHandler(org.rstudio.studio.client.workbench.events.SessionInitHandler) GlassVisibilityEvent(org.rstudio.core.client.widget.events.GlassVisibilityEvent) ImageElement(com.google.gwt.dom.client.ImageElement) WebMenuCallback(org.rstudio.core.client.command.impl.WebMenuCallback) GlobalToolbar(org.rstudio.studio.client.application.ui.GlobalToolbar) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) Style(com.google.gwt.dom.client.Style) Inject(com.google.inject.Inject)

Example 4 with SessionInitEvent

use of org.rstudio.studio.client.workbench.events.SessionInitEvent in project rstudio by rstudio.

the class Satellite method setSessionInfo.

// called by main window to initialize sessionInfo
private void setSessionInfo(JavaScriptObject si) {
    // get the session info and set it
    SessionInfo sessionInfo = si.<SessionInfo>cast();
    session_.setSessionInfo(sessionInfo);
    // ensure ui prefs initialize
    pUIPrefs_.get();
    // some objects wait for SessionInit in order to initialize themselves
    // with SessionInfo
    events_.fireEvent(new SessionInitEvent());
}
Also used : SessionInitEvent(org.rstudio.studio.client.workbench.events.SessionInitEvent) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo)

Aggregations

SessionInitEvent (org.rstudio.studio.client.workbench.events.SessionInitEvent)4 SessionInfo (org.rstudio.studio.client.workbench.model.SessionInfo)4 Inject (com.google.inject.Inject)2 GlobalToolbar (org.rstudio.studio.client.application.ui.GlobalToolbar)2 SessionInitHandler (org.rstudio.studio.client.workbench.events.SessionInitHandler)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 ImageElement (com.google.gwt.dom.client.ImageElement)1 Style (com.google.gwt.dom.client.Style)1 Timer (com.google.gwt.user.client.Timer)1 DesktopMenuCallback (org.rstudio.core.client.command.impl.DesktopMenuCallback)1 WebMenuCallback (org.rstudio.core.client.command.impl.WebMenuCallback)1 JsObject (org.rstudio.core.client.js.JsObject)1 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)1 ThemeStyles (org.rstudio.core.client.theme.res.ThemeStyles)1 GlassVisibilityEvent (org.rstudio.core.client.widget.events.GlassVisibilityEvent)1 InvalidSessionInfo (org.rstudio.studio.client.application.model.InvalidSessionInfo)1 ProjectPopupMenu (org.rstudio.studio.client.application.ui.ProjectPopupMenu)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