Search in sources :

Example 1 with JsArray

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);
        }
    });
}
Also used : ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) RSConnectDeploymentRecord(org.rstudio.studio.client.rsconnect.model.RSConnectDeploymentRecord)

Example 2 with JsArray

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());
        }
    });
}
Also used : RSConnectApplicationInfo(org.rstudio.studio.client.rsconnect.model.RSConnectApplicationInfo) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) RSConnectDeploymentRecord(org.rstudio.studio.client.rsconnect.model.RSConnectDeploymentRecord)

Example 3 with JsArray

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;
}
Also used : SimplePanelWithProgress(org.rstudio.core.client.widget.SimplePanelWithProgress) JsArray(com.google.gwt.core.client.JsArray) GWT(com.google.gwt.core.client.GWT) ServerError(org.rstudio.studio.client.server.ServerError) DoubleClickHandler(com.google.gwt.event.dom.client.DoubleClickHandler) ArrayList(java.util.ArrayList) DoubleClickEvent(com.google.gwt.event.dom.client.DoubleClickEvent) ListBox(com.google.gwt.user.client.ui.ListBox)

Example 4 with JsArray

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;
}
Also used : ListDataProvider(com.google.gwt.view.client.ListDataProvider) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) Label(com.google.gwt.user.client.ui.Label) ArrayList(java.util.ArrayList) GWT(com.google.gwt.core.client.GWT) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Example 5 with JsArray

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;
        }
    };
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) JsArray(com.google.gwt.core.client.JsArray) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) StringStateValue(org.rstudio.studio.client.workbench.model.helper.StringStateValue) ClientInitState(org.rstudio.studio.client.workbench.model.ClientInitState) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)

Aggregations

JsArray (com.google.gwt.core.client.JsArray)39 ArrayList (java.util.ArrayList)14 ServerError (org.rstudio.studio.client.server.ServerError)12 JsArrayString (com.google.gwt.core.client.JsArrayString)7 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)5 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)4 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 HTML (com.google.gwt.user.client.ui.HTML)3 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 CommentInfo (com.google.gerrit.client.changes.CommentInfo)2 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)2 NativeString (com.google.gerrit.client.rpc.NativeString)2 Context (com.google.gwt.cell.client.Cell.Context)2