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);
}
}
use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.
the class ApplicationClientInit method execute.
public void execute(final ServerRequestCallback<SessionInfo> requestCallback, final boolean retryOnTransmissionError) {
// reset internal state
timedOut_ = false;
timeoutTimer_ = null;
// send the request
final ServerRequestCallback<SessionInfo> rpcRequestCallback = new ServerRequestCallback<SessionInfo>() {
@Override
public void onResponseReceived(SessionInfo sessionInfo) {
if (!timedOut_) {
cancelTimeoutTimer();
requestCallback.onResponseReceived(sessionInfo);
}
}
@Override
public void onError(ServerError error) {
if (!timedOut_) {
cancelTimeoutTimer();
if ((error.getCode() == ServerError.TRANSMISSION) && retryOnTransmissionError) {
// transmission error can occur due to a race
// condition when switching projects or versions, for
// this case wait 1000ms then retry
new Timer() {
@Override
public void run() {
// retry (specify flag to ensure we only retry once)
execute(requestCallback, false);
}
}.schedule(1000);
} else {
requestCallback.onError(error);
}
}
}
};
server_.clientInit(rpcRequestCallback);
// wait for 60 seconds then ask the user if they want to issue an
// interrupt to the server
int timeoutMs = 60000;
timeoutTimer_ = new Timer() {
public void run() {
// set timed out flag
timedOut_ = true;
// cancel our request
rpcRequestCallback.cancel();
// ask the user if they want to attempt to interrupt the server
globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, // caption
"Initializing RStudio", // message
"The RStudio server is taking a long time to respond. It is " + "possible that your R session has become unresponsive. " + "Do you want to terminate the currently running R session?", // don't include cancel
false, // Yes operation
new Operation() {
public void execute() {
// call interrupt then call this method back on success
server_.abort(null, new ServerRequestCallback<Void>() {
@Override
public void onResponseReceived(Void response) {
// reload the application
reloadWithDelay(1000);
}
@Override
public void onError(ServerError error) {
// if we get an error during interrupt then just
// forward the error on to the original handler
requestCallback.onError(error);
}
});
}
}, // No operation
new Operation() {
public void execute() {
// keep trying (reload to clear out any crufty app
// or networking state)
reloadWithDelay(1);
}
}, // Cancel operation (none)
null, "Terminate R", "Keep Waiting", // default to No
false);
}
};
// activate the timer
timeoutTimer_.schedule(timeoutMs);
}
use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.
the class TextEditingTarget method previewRpresentation.
void previewRpresentation() {
SessionInfo sessionInfo = session_.getSessionInfo();
if (!fileTypeCommands_.getHTMLCapabiliites().isRMarkdownSupported()) {
globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Preview", "R Presentations require the knitr package " + "(version 1.2 or higher)");
return;
}
PresentationState state = sessionInfo.getPresentationState();
// if we are showing a tutorial then don't allow preview
if (state.isTutorial()) {
globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Preview", "R Presentations cannot be previewed when a Tutorial " + "is active");
return;
}
// if this presentation is already showing then just activate
if (state.isActive() && state.getFilePath().equals(docUpdateSentinel_.getPath())) {
commands_.activatePresentation().execute();
save();
} else // otherwise reload
{
saveThenExecute(null, new Command() {
@Override
public void execute() {
server_.showPresentationPane(docUpdateSentinel_.getPath(), new VoidServerRequestCallback());
}
});
}
}
use of org.rstudio.studio.client.workbench.model.SessionInfo in project rstudio by rstudio.
the class TextEditingTarget method getSaveFileDefaultDir.
private FileSystemItem getSaveFileDefaultDir() {
FileSystemItem fsi = null;
SessionInfo si = session_.getSessionInfo();
if (si.getBuildToolsType() == SessionInfo.BUILD_TOOLS_PACKAGE) {
FileSystemItem pkg = FileSystemItem.createDir(si.getBuildTargetDir());
if (fileType_.isR()) {
fsi = FileSystemItem.createDir(pkg.completePath("R"));
} else if (fileType_.isC() && si.getHasPackageSrcDir()) {
fsi = FileSystemItem.createDir(pkg.completePath("src"));
} else if (fileType_.isRd()) {
fsi = FileSystemItem.createDir(pkg.completePath("man"));
} else if ((fileType_.isRnw() || fileType_.isRmd()) && si.getHasPackageVignetteDir()) {
fsi = FileSystemItem.createDir(pkg.completePath("vignettes"));
}
}
if (fsi == null)
fsi = workbenchContext_.getDefaultFileDialogDir();
return fsi;
}
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;
}
}
Aggregations