Search in sources :

Example 26 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class FastSelectTable method setSelected.

public void setSelected(TableRowElement row, boolean selected) {
    try {
        if (row.getParentElement().getParentElement() != table_)
            return;
    } catch (NullPointerException npe) {
        return;
    }
    boolean isCurrentlySelected = isSelected(row);
    if (isCurrentlySelected == selected)
        return;
    if (selected && !codec_.isValueRow(row))
        return;
    setStyleName(row, selectedClassName_, selected);
    if (selected)
        selectedRows_.add(row);
    else
        selectedRows_.remove(row);
    if (selected && !allowMultiSelect_) {
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            public void execute() {
                fireEvent(new SelectionChangedEvent());
            }
        });
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SelectionChangedEvent(org.rstudio.core.client.widget.events.SelectionChangedEvent)

Example 27 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class GeneralPreferencesPane method initialize.

@Override
protected void initialize(RPrefs rPrefs) {
    // general prefs
    final GeneralPrefs generalPrefs = rPrefs.getGeneralPrefs();
    showServerHomePage_.setEnabled(true);
    reuseSessionsForProjectLinks_.setEnabled(true);
    saveWorkspace_.setEnabled(true);
    loadRData_.setEnabled(true);
    dirChooser_.setEnabled(true);
    showServerHomePage_.setValue(generalPrefs.getShowUserHomePage());
    reuseSessionsForProjectLinks_.setValue(generalPrefs.getReuseSessionsForProjectLinks());
    int saveWorkspaceIndex;
    switch(generalPrefs.getSaveAction()) {
        case SaveAction.NOSAVE:
            saveWorkspaceIndex = 1;
            break;
        case SaveAction.SAVE:
            saveWorkspaceIndex = 0;
            break;
        case SaveAction.SAVEASK:
        default:
            saveWorkspaceIndex = 2;
            break;
    }
    saveWorkspace_.getListBox().setSelectedIndex(saveWorkspaceIndex);
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            server_.getTerminalShells(new ServerRequestCallback<JsArray<TerminalShellInfo>>() {

                @Override
                public void onResponseReceived(JsArray<TerminalShellInfo> shells) {
                    int currentShell = generalPrefs.getDefaultTerminalShellValue();
                    int currentShellIndex = 0;
                    GeneralPreferencesPane.this.terminalShell_.getListBox().clear();
                    for (int i = 0; i < shells.length(); i++) {
                        TerminalShellInfo info = shells.get(i);
                        GeneralPreferencesPane.this.terminalShell_.addChoice(info.getShellName(), Integer.toString(info.getShellType()));
                        if (info.getShellType() == currentShell)
                            currentShellIndex = i;
                    }
                    if (GeneralPreferencesPane.this.terminalShell_.getListBox().getItemCount() > 0) {
                        GeneralPreferencesPane.this.terminalShell_.setEnabled((true));
                        GeneralPreferencesPane.this.terminalShell_.getListBox().setSelectedIndex(currentShellIndex);
                    }
                }

                @Override
                public void onError(ServerError error) {
                }
            });
        }
    });
    loadRData_.setValue(generalPrefs.getLoadRData());
    dirChooser_.setText(generalPrefs.getInitialWorkingDirectory());
    // history prefs
    HistoryPrefs historyPrefs = rPrefs.getHistoryPrefs();
    alwaysSaveHistory_.setEnabled(true);
    removeHistoryDuplicates_.setEnabled(true);
    alwaysSaveHistory_.setValue(historyPrefs.getAlwaysSave());
    removeHistoryDuplicates_.setValue(historyPrefs.getRemoveDuplicates());
    rProfileOnResume_.setValue(generalPrefs.getRprofileOnResume());
    rProfileOnResume_.setEnabled(true);
    showLastDotValue_.setValue(generalPrefs.getShowLastDotValue());
    showLastDotValue_.setEnabled(true);
    if (rServerRVersion_ != null)
        rServerRVersion_.setRVersion(generalPrefs.getDefaultRVersion());
    if (rememberRVersionForProjects_ != null) {
        rememberRVersionForProjects_.setValue(generalPrefs.getRestoreProjectRVersion());
    }
    // projects prefs
    ProjectsPrefs projectsPrefs = rPrefs.getProjectsPrefs();
    restoreLastProject_.setEnabled(true);
    restoreLastProject_.setValue(projectsPrefs.getRestoreLastProject());
}
Also used : GeneralPrefs(org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs) TerminalShellInfo(org.rstudio.studio.client.workbench.views.terminal.TerminalShellInfo) JsArray(com.google.gwt.core.client.JsArray) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) ProjectsPrefs(org.rstudio.studio.client.workbench.prefs.model.ProjectsPrefs) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) HistoryPrefs(org.rstudio.studio.client.workbench.prefs.model.HistoryPrefs)

Example 28 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class RemoteServerAuth method updateCredentials.

public void updateCredentials(final ServerRequestCallback<Integer> requestCallback) {
    // safely cleanup any previously active update credentials forms
    safeCleanupPreviousUpdateCredentials();
    // create a hidden form panel to submit the update credentials to
    // (we do this so GWT manages the trickiness associated with 
    // managing and reading the contents of a hidden iframe) 
    final FormPanel updateCredentialsForm = new FormPanel();
    updateCredentialsForm.setMethod(FormPanel.METHOD_GET);
    updateCredentialsForm.setEncoding(FormPanel.ENCODING_URLENCODED);
    // form url
    String url = remoteServer_.getApplicationURL("auth-update-credentials");
    updateCredentialsForm.setAction(url);
    // request log entry (fake up a json rpc method call to conform
    // to the data format expected by RequestLog
    String requestId = Integer.toString(Random.nextInt());
    String requestData = createRequestData();
    final RequestLogEntry logEntry = RequestLog.log(requestId, requestData);
    // form submit complete handler
    updateCredentialsForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            // parse the results
            String results = event.getResults();
            RpcResponse response = RpcResponse.parse(event.getResults());
            if (response != null) {
                logEntry.logResponse(ResponseType.Normal, results);
                // check for error
                RpcError rpcError = response.getError();
                if (rpcError != null) {
                    if (rpcError.getCode() == RpcError.METHOD_NOT_FOUND) {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_UNSUPPORTED));
                    } else {
                        requestCallback.onError(new RemoteServerError(rpcError));
                    }
                } else // must be a valid response
                {
                    Bool authenticated = response.getResult();
                    if (authenticated.getValue()) {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_SUCCESS));
                    } else {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_FAILURE));
                    }
                }
            } else // error parsing results
            {
                logEntry.logResponse(ResponseType.Error, results);
                // form message
                String msg = "Error parsing results: " + (results != null ? results : "(null)");
                // we don't expect this so debug log to flag our attention
                Debug.log("UPDATE CREDENTIALS: " + msg);
                // return the error
                RpcError rpcError = RpcError.create(RpcError.PARSE_ERROR, msg);
                requestCallback.onError(new RemoteServerError(rpcError));
            }
            // remove the hidden form (from both last-ditch list and DOM)
            previousUpdateCredentialsForms_.remove(updateCredentialsForm);
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                public void execute() {
                    RootPanel.get().remove(updateCredentialsForm);
                }
            });
        }
    });
    // add the (hidden) form panel to the document and last ditch list
    RootPanel.get().add(updateCredentialsForm, -1000, -1000);
    previousUpdateCredentialsForms_.add(updateCredentialsForm);
    // submit the form
    updateCredentialsForm.submit();
}
Also used : FormPanel(com.google.gwt.user.client.ui.FormPanel) RequestLogEntry(org.rstudio.core.client.jsonrpc.RequestLogEntry) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Bool(org.rstudio.studio.client.server.Bool) RpcError(org.rstudio.core.client.jsonrpc.RpcError) JSONString(com.google.gwt.json.client.JSONString) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) RpcResponse(org.rstudio.core.client.jsonrpc.RpcResponse)

Example 29 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class TextEditingTargetWidget method setFormatOptions.

@Override
public void setFormatOptions(TextFileType fileType, boolean showRmdFormatMenu, boolean canEditFormatOptions, List<String> options, List<String> values, List<String> extensions, String selectedOption) {
    if (!canEditFormatOptions) {
        setFormatText("");
    }
    setRmdFormatButtonVisible(showRmdFormatMenu);
    rmdFormatButton_.setEnabled(showRmdFormatMenu);
    rmdFormatButton_.clearMenu();
    int parenPos = selectedOption.indexOf('(');
    if (parenPos != -1)
        selectedOption = selectedOption.substring(0, parenPos).trim();
    // don't show format text (but leave the code in for now in case
    // we change our mind)
    // setFormatText(selectedOption);
    setFormatText("");
    String prefix = fileType.isPlainMarkdown() ? "Preview " : "Knit to ";
    for (int i = 0; i < Math.min(options.size(), values.size()); i++) {
        String ext = extensions.get(i);
        ImageResource img = ext != null ? fileTypeRegistry_.getIconForFilename("output." + ext) : fileTypeRegistry_.getIconForFilename("Makefile");
        final String valueName = values.get(i);
        ScheduledCommand cmd = new ScheduledCommand() {

            @Override
            public void execute() {
                handlerManager_.fireEvent(new RmdOutputFormatChangedEvent(valueName));
            }
        };
        String text = ext == ".nb.html" ? "Preview Notebook" : prefix + options.get(i);
        MenuItem item = ImageMenuItem.create(img, text, cmd, 2);
        rmdFormatButton_.addMenuItem(item, values.get(i));
    }
    if (session_.getSessionInfo().getKnitParamsAvailable()) {
        final AppCommand knitWithParams = commands_.knitWithParameters();
        rmdFormatButton_.addSeparator();
        ScheduledCommand cmd = new ScheduledCommand() {

            @Override
            public void execute() {
                knitWithParams.execute();
            }
        };
        MenuItem item = new MenuItem(knitWithParams.getMenuHTML(false), true, cmd);
        rmdFormatButton_.addMenuItem(item, knitWithParams.getMenuLabel(false));
    }
    if (session_.getSessionInfo().getKnitWorkingDirAvailable()) {
        MenuBar knitDirMenu = new MenuBar(true);
        DocPropMenuItem knitInDocDir = new DocShadowPropMenuItem("Document Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_DEFAULT);
        knitDirMenu.addItem(knitInDocDir);
        DocPropMenuItem knitInProjectDir = new DocShadowPropMenuItem("Project Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_PROJECT);
        knitDirMenu.addItem(knitInProjectDir);
        DocPropMenuItem knitInCurrentDir = new DocShadowPropMenuItem("Current Working Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_CURRENT);
        knitDirMenu.addItem(knitInCurrentDir);
        rmdFormatButton_.addSeparator();
        rmdFormatButton_.addMenuItem(knitDirMenu, "Knit Directory");
    }
    addClearKnitrCacheMenu(rmdFormatButton_);
    showRmdViewerMenuItems(true, canEditFormatOptions, fileType.isRmd(), RmdOutput.TYPE_STATIC);
    if (publishButton_ != null)
        publishButton_.setIsStatic(true);
    isShiny_ = false;
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) ImageResource(com.google.gwt.resources.client.ImageResource) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RmdOutputFormatChangedEvent(org.rstudio.studio.client.rmarkdown.events.RmdOutputFormatChangedEvent) ImageMenuItem(org.rstudio.studio.client.common.ImageMenuItem)

Example 30 with ScheduledCommand

use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.

the class AceEditorBackgroundLinkHighlighter method onDocumentChanged.

@Override
public void onDocumentChanged(DocumentChangedEvent event) {
    // clear markers within the delete range
    clearMarkers(event.getEvent().getRange());
    // prepare highlighter
    int row = event.getEvent().getRange().getStart().getRow();
    nextHighlightStart_ = Math.min(nextHighlightStart_, row);
    timer_.schedule(700);
    // update marker positions (deferred so that anchors update)
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            final SafeMap<Integer, List<MarkerRegistration>> newMarkers = new SafeMap<Integer, List<MarkerRegistration>>();
            MapUtil.forEach(activeMarkers_, new ForEachCommand<Integer, List<MarkerRegistration>>() {

                @Override
                public void execute(Integer oldRow, List<MarkerRegistration> markers) {
                    if (markers == null || markers.isEmpty())
                        return;
                    // all markers here should have same row
                    int newRow = markers.get(0).getRange().getStart().getRow();
                    newMarkers.put(newRow, markers);
                }
            });
            activeMarkers_.clear();
            activeMarkers_ = newMarkers;
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SafeMap(org.rstudio.core.client.container.SafeMap) ForEachCommand(org.rstudio.core.client.MapUtil.ForEachCommand) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)104 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)7 Element (com.google.gwt.dom.client.Element)6 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)6 JsArray (com.google.gwt.core.client.JsArray)5 Command (com.google.gwt.user.client.Command)5 ServerError (org.rstudio.studio.client.server.ServerError)5 JsArrayString (com.google.gwt.core.client.JsArrayString)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 Event (com.google.gwt.user.client.Event)3 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)3 Timer (com.google.gwt.user.client.Timer)3 WindowEx (org.rstudio.core.client.dom.WindowEx)3 SourcePosition (org.rstudio.studio.client.workbench.views.source.model.SourcePosition)3 ErrorDialog (com.google.gerrit.client.ErrorDialog)2 OnEditEnabler (com.google.gerrit.client.ui.OnEditEnabler)2