use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class RSConnectPublishButton method rebuildPopupMenu.
// rebuilds the popup menu--this can happen when the menu is invoked; it can
// also happen when the button is created if we're aggressively checking
// publish status
private void rebuildPopupMenu(final ToolbarPopupMenu.DynamicPopupMenuCallback callback) {
final ToolbarPopupMenu menu = publishMenu_;
// prevent reentrancy
if (populating_) {
if (callback != null)
callback.onPopupMenu(menu);
return;
}
// handle case where we don't have a content path (i.e. plots)
if (contentPath_ == null) {
setPreviousDeployments(null);
if (callback != null)
callback.onPopupMenu(menu);
return;
}
// (unless we're forcefully repopulating)
if (populatedPath_ != null && populatedPath_.equals(contentPath_)) {
if (callback != null)
callback.onPopupMenu(menu);
return;
}
String contentPath = contentPath_;
boolean parent = false;
// CONTENT_TYPE_APP_SINGLE and their own deployment records)
if (contentType_ == RSConnect.CONTENT_TYPE_APP && StringUtil.getExtension(contentPath_).equalsIgnoreCase("r"))
parent = true;
// if this is a document in a website, use the parent path
if (contentType_ == RSConnect.CONTENT_TYPE_WEBSITE)
parent = true;
// apply parent path if needed
if (parent) {
FileSystemItem fsiContent = FileSystemItem.createFile(contentPath_);
contentPath = fsiContent.getParentPathString();
}
populating_ = true;
server_.getRSConnectDeployments(contentPath, outputPath_ == null ? "" : outputPath_, new ServerRequestCallback<JsArray<RSConnectDeploymentRecord>>() {
@Override
public void onResponseReceived(JsArray<RSConnectDeploymentRecord> recs) {
populatedPath_ = contentPath_;
populating_ = false;
// that are static (as we can't update them)
if (contentType_ == RSConnect.CONTENT_TYPE_WEBSITE && (docPreview_ == null || StringUtil.isNullOrEmpty(docPreview_.getOutputFile()))) {
JsArray<RSConnectDeploymentRecord> codeRecs = JsArray.createArray().cast();
for (int i = 0; i < recs.length(); i++) {
if (!recs.get(i).getAsStatic())
codeRecs.push(recs.get(i));
}
recs = codeRecs;
}
setPreviousDeployments(recs);
if (callback != null)
callback.onPopupMenu(menu);
}
@Override
public void onError(ServerError error) {
populating_ = false;
if (callback != null)
callback.onPopupMenu(menu);
}
});
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class RSConnect method configureShinyApp.
// Manage, step 2: Get the status of the applications from the server
private void configureShinyApp(final String dir, JsArray<RSConnectDeploymentRecord> records) {
if (records.length() == 0) {
display_.showMessage(GlobalDisplay.MSG_INFO, "No Deployments Found", "No application deployments were found for '" + dir + "'");
return;
}
// If we know the most recent deployment of the directory, act on that
// deployment by default
final ArrayList<RSConnectDeploymentRecord> recordList = new ArrayList<RSConnectDeploymentRecord>();
RSConnectDeploymentRecord lastRecord = dirState_.getLastDeployment(dir);
if (lastRecord != null) {
recordList.add(lastRecord);
}
for (int i = 0; i < records.length(); i++) {
RSConnectDeploymentRecord record = records.get(i);
if (lastRecord == null) {
recordList.add(record);
} else {
if (record.getUrl().equals(lastRecord.getUrl()))
recordList.set(0, record);
}
}
// We need to further filter the list by deployments that are
// eligible for termination (i.e. are currently running)
server_.getRSConnectAppList(recordList.get(0).getAccountName(), recordList.get(0).getServer(), new ServerRequestCallback<JsArray<RSConnectApplicationInfo>>() {
@Override
public void onResponseReceived(JsArray<RSConnectApplicationInfo> apps) {
configureShinyApp(dir, apps, recordList);
}
@Override
public void onError(ServerError error) {
display_.showErrorMessage("Error Listing Applications", error.getMessage());
}
});
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class ChooseMirrorDialog method createMainWidget.
@Override
protected Widget createMainWidget() {
// create progress container
final SimplePanelWithProgress panel = new SimplePanelWithProgress(ProgressImages.createLargeGray());
panel.setStylePrimaryName(RESOURCES.styles().mainWidget());
// show progress (with delay)
panel.showProgress(200);
// query data source for packages
mirrorSource_.requestData(new SimpleRequestCallback<JsArray<T>>() {
@Override
public void onResponseReceived(JsArray<T> mirrors) {
// keep internal list of mirrors
boolean haveInsecureMirror = false;
mirrors_ = new ArrayList<T>(mirrors.length());
// create list box and select default item
listBox_ = new ListBox();
listBox_.setMultipleSelect(false);
// all
listBox_.setVisibleItemCount(18);
listBox_.setWidth("100%");
if (mirrors.length() > 0) {
for (int i = 0; i < mirrors.length(); i++) {
T mirror = mirrors.get(i);
if (mirrorSource_.getLabel(mirror).startsWith("0-Cloud"))
continue;
mirrors_.add(mirror);
String item = mirrorSource_.getLabel(mirror);
String value = mirrorSource_.getURL(mirror);
if (!value.startsWith("https"))
haveInsecureMirror = true;
listBox_.addItem(item, value);
}
listBox_.setSelectedIndex(0);
enableOkButton(true);
}
// set it into the panel
panel.setWidget(listBox_);
// set caption
String protocolQualifer = !haveInsecureMirror ? " HTTPS" : "";
setText("Choose" + protocolQualifer + " CRAN Mirror");
// update ok button on changed
listBox_.addDoubleClickHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(DoubleClickEvent event) {
clickOkButton();
}
});
// if the list box is larger than the space we initially allocated
// then increase the panel height
final int kDefaultPanelHeight = 285;
if (listBox_.getOffsetHeight() > kDefaultPanelHeight)
panel.setHeight(listBox_.getOffsetHeight() + "px");
// set focus
FocusHelper.setFocusDeferred(listBox_);
}
@Override
public void onError(ServerError error) {
closeDialog();
super.onError(error);
}
});
return panel;
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class PackageActionConfirmationDialog method createMainWidget.
@Override
protected Widget createMainWidget() {
FlowPanel flowPanel = new FlowPanel();
String explanatoryText = getExplanatoryText();
if (explanatoryText.length() > 0) {
Label text = new Label(explanatoryText);
text.setStylePrimaryName(RESOURCES.styles().explanatoryText());
flowPanel.add(text);
}
actionsTable_ = new CellTable<PendingAction>(15, GWT.<PackagesCellTableResources>create(PackagesCellTableResources.class));
actionsTable_.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
actionsTable_.setSelectionModel(new NoSelectionModel<PendingAction>());
actionsTable_.setWidth("100%", true);
ActionColumn actionColumn = new ActionColumn();
actionsTable_.addColumn(actionColumn);
actionsTable_.setColumnWidth(actionColumn, 30, Unit.PX);
addTableColumns(actionsTable_);
ScrollPanel scrollPanel = new ScrollPanel();
scrollPanel.setWidget(actionsTable_);
scrollPanel.setStylePrimaryName(RESOURCES.styles().mainWidget());
flowPanel.add(scrollPanel);
// query for updates
actionsDS_.requestData(new SimpleRequestCallback<JsArray<T>>() {
@Override
public void onResponseReceived(JsArray<T> actions) {
if (actions != null && actions.length() > 0) {
ArrayList<PendingAction> pendingActions = new ArrayList<PendingAction>();
for (int i = 0; i < actions.length(); i++) pendingActions.add(new PendingAction(actions.get(i), false));
actionsTable_.setPageSize(pendingActions.size());
actionsDataProvider_ = new ListDataProvider<PendingAction>();
actionsDataProvider_.setList(pendingActions);
actionsDataProvider_.addDataDisplay(actionsTable_);
enableCancelButton(true);
selectAllButton_.setEnabled(true);
selectNoneButton_.setEnabled(true);
} else {
closeDialog();
showNoActionsRequired();
}
}
@Override
public void onError(ServerError error) {
closeDialog();
super.onError(error);
}
});
return flowPanel;
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class Files method initSession.
private void initSession() {
final SessionInfo sessionInfo = session_.getSessionInfo();
ClientInitState state = sessionInfo.getClientState();
// make the column sort order persistent
new JSObjectStateValue(MODULE_FILES, KEY_SORT_ORDER, ClientState.PROJECT_PERSISTENT, state, false) {
@Override
protected void onInit(JsObject value) {
if (value != null)
columnSortOrder_ = value.cast();
else
columnSortOrder_ = null;
lastKnownState_ = columnSortOrder_;
view_.setColumnSortOrder(columnSortOrder_);
}
@Override
protected JsObject getValue() {
if (columnSortOrder_ != null)
return columnSortOrder_.cast();
else
return null;
}
@Override
protected boolean hasChanged() {
if (lastKnownState_ != columnSortOrder_) {
lastKnownState_ = columnSortOrder_;
return true;
} else {
return false;
}
}
private JsArray<ColumnSortInfo> lastKnownState_ = null;
};
// navigate to previous directory (works for resumed case)
new StringStateValue(MODULE_FILES, KEY_PATH, ClientState.PROJECT_PERSISTENT, state) {
@Override
protected void onInit(final String value) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
// we don't need to initialize from client state
if (hasNavigatedToDirectory_)
return;
// compute start dir
String path = transformPathStateValue(value);
FileSystemItem start = path != null ? FileSystemItem.createDir(path) : FileSystemItem.createDir(sessionInfo.getInitialWorkingDir());
navigateToDirectory(start);
}
});
}
@Override
protected String getValue() {
return currentPath_.getPath();
}
private String transformPathStateValue(String value) {
// if the value is null then return null
if (value == null)
return null;
// only respect the value for projects
String projectFile = session_.getSessionInfo().getActiveProjectFile();
if (projectFile == null)
return null;
// ensure that the value is within the project dir (it wouldn't
// be if the project directory has been moved or renamed)
String projectDirPath = FileSystemItem.createFile(projectFile).getParentPathString();
if (value.startsWith(projectDirPath))
return value;
else
return null;
}
};
}
Aggregations