Search in sources :

Example 1 with Token

use of org.rstudio.core.client.Invalidation.Token in project rstudio by rstudio.

the class ImportFileSettingsDialog method loadData.

private void loadData() {
    final Token invalidationToken = updateRequest_.getInvalidationToken();
    progress_.onProgress("Detecting data format");
    server_.getDataPreview(dataFile_.getPath(), new ServerRequestCallback<DataPreviewResult>() {

        @Override
        public void onResponseReceived(DataPreviewResult response) {
            input_.setHTML(toInputHtml(response));
            if (invalidationToken.isInvalid())
                return;
            progress_.onProgress(null);
            populateOutput(response);
            if (response.hasHeader())
                headingYes_.setValue(true);
            else
                headingNo_.setValue(true);
            selectByValue(separator_, response.getSeparator());
            selectByValue(decimal_, response.getDecimal());
            selectByValue(quote_, response.getQuote());
            selectByValue(comment_, response.getComment());
            defaultStringsAsFactors_ = response.getDefaultStringsAsFactors();
            stringsAsFactors_.setValue(defaultStringsAsFactors_);
        }

        @Override
        public void onError(ServerError error) {
            if (invalidationToken.isInvalid())
                return;
            progress_.onProgress(null);
            globalDisplay_.showErrorMessage("Error", error.getUserMessage());
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) DataPreviewResult(org.rstudio.studio.client.workbench.views.environment.model.DataPreviewResult) Token(org.rstudio.core.client.Invalidation.Token)

Example 2 with Token

use of org.rstudio.core.client.Invalidation.Token in project rstudio by rstudio.

the class SVNReviewPresenter method updateDiff.

private void updateDiff() {
    view_.hideSizeWarning();
    final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems();
    if (paths.size() != 1) {
        clearDiff();
        return;
    }
    final StatusAndPath item = paths.get(0);
    if (!item.getPath().equals(currentFilename_)) {
        clearDiff();
        currentFilename_ = item.getPath();
    }
    // bail if this is an undiffable status
    if (undiffableStatuses_.contains(item.getStatus()))
        return;
    diffInvalidation_.invalidate();
    final Token token = diffInvalidation_.getInvalidationToken();
    server_.svnDiffFile(item.getPath(), view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") {

        @Override
        public void onResponseReceived(DiffResult diffResult) {
            if (token.isInvalid())
                return;
            String response = diffResult.getDecodedValue();
            // Use lastResponse_ to prevent unnecessary flicker
            if (response.equals(currentResponse_))
                return;
            currentResponse_ = response;
            currentEncoding_ = diffResult.getSourceEncoding();
            SVNDiffParser parser = new SVNDiffParser(response);
            parser.nextFilePair();
            ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>();
            activeChunks_.clear();
            for (DiffChunk chunk; null != (chunk = parser.nextChunk()); ) {
                if (!chunk.shouldIgnore()) {
                    activeChunks_.add(chunk);
                    allLines.add(new ChunkOrLine(chunk));
                }
                for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line));
            }
            view_.getLineTableDisplay().setShowActions(!"?".equals(item.getStatus()));
            view_.setData(allLines);
        }

        @Override
        public void onError(ServerError error) {
            JSONNumber size = error.getClientInfo().isNumber();
            if (size != null)
                view_.showSizeWarning((long) size.doubleValue());
            else
                super.onError(error);
        }
    });
}
Also used : SVNDiffParser(org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser) StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) Token(org.rstudio.core.client.Invalidation.Token) JSONNumber(com.google.gwt.json.client.JSONNumber) DiffResult(org.rstudio.studio.client.common.vcs.DiffResult)

Example 3 with Token

use of org.rstudio.core.client.Invalidation.Token in project rstudio by rstudio.

the class HistoryPresenter method showCommitDetail.

private void showCommitDetail(boolean noSizeWarning) {
    final CommitInfo commitInfo = view_.getCommitList().getSelectedCommit();
    if (!noSizeWarning && commitInfo != null && commitInfo.getId().equals(commitShowing_)) {
        return;
    }
    commitShowing_ = null;
    view_.hideSizeWarning();
    view_.getCommitDetail().setSelectedCommit(commitInfo);
    view_.getCommitDetail().showDetailProgress();
    invalidation_.invalidate();
    if (commitInfo == null)
        return;
    final Token token = invalidation_.getInvalidationToken();
    strategy_.showCommit(commitInfo.getId(), noSizeWarning, new SimpleRequestCallback<String>() {

        @Override
        public void onResponseReceived(String response) {
            super.onResponseReceived(response);
            if (token.isInvalid())
                return;
            DiffParser parser = strategy_.createParserForCommit(response);
            view_.getCommitDetail().setDetails(parser, !strategy_.isShowFileSupported());
            commitShowing_ = commitInfo.getId();
        }

        @Override
        public void onError(ServerError error) {
            commitShowing_ = null;
            JSONNumber size = error.getClientInfo().isNumber();
            if (size != null)
                view_.showSizeWarning((long) size.doubleValue());
            else if (strategy_.getShowHistoryErrors())
                super.onError(error);
            else
                Debug.logError(error);
        }
    });
}
Also used : DiffParser(org.rstudio.studio.client.workbench.views.vcs.common.diff.DiffParser) ServerError(org.rstudio.studio.client.server.ServerError) Token(org.rstudio.core.client.Invalidation.Token) JSONNumber(com.google.gwt.json.client.JSONNumber)

Example 4 with Token

use of org.rstudio.core.client.Invalidation.Token in project rstudio by rstudio.

the class GitReviewPresenter method updateDiff.

private void updateDiff(boolean allowModeSwitch) {
    view_.hideSizeWarning();
    final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems();
    if (paths.size() != 1) {
        clearDiff();
        return;
    }
    final StatusAndPath item = paths.get(0);
    if (allowModeSwitch) {
        if (!softModeSwitch_) {
            boolean staged = item.getStatus().charAt(0) != ' ' && item.getStatus().charAt(1) == ' ';
            HasValue<Boolean> checkbox = staged ? view_.getStagedCheckBox() : view_.getUnstagedCheckBox();
            if (!checkbox.getValue()) {
                clearDiff();
                checkbox.setValue(true, true);
            }
        } else {
            if (view_.getStagedCheckBox().getValue() && (item.getStatus().charAt(0) == ' ' || item.getStatus().charAt(0) == '?')) {
                clearDiff();
                view_.getUnstagedCheckBox().setValue(true, true);
            } else if (view_.getUnstagedCheckBox().getValue() && item.getStatus().charAt(1) == ' ') {
                clearDiff();
                view_.getStagedCheckBox().setValue(true, true);
            }
        }
    }
    softModeSwitch_ = false;
    if (!item.getPath().equals(currentFilename_)) {
        clearDiff();
        currentFilename_ = item.getPath();
    }
    diffInvalidation_.invalidate();
    final Token token = diffInvalidation_.getInvalidationToken();
    final PatchMode patchMode = view_.getStagedCheckBox().getValue() ? PatchMode.Stage : PatchMode.Working;
    server_.gitDiffFile(item.getPath(), patchMode, view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") {

        @Override
        public void onResponseReceived(DiffResult diffResult) {
            if (token.isInvalid())
                return;
            // Use lastResponse_ to prevent unnecessary flicker
            String response = diffResult.getDecodedValue();
            if (response.equals(currentResponse_))
                return;
            currentResponse_ = response;
            currentSourceEncoding_ = diffResult.getSourceEncoding();
            UnifiedParser parser = new UnifiedParser(response);
            parser.nextFilePair();
            ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>();
            activeChunks_.clear();
            for (DiffChunk chunk; null != (chunk = parser.nextChunk()); ) {
                activeChunks_.add(chunk);
                allLines.add(new ChunkOrLine(chunk));
                for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line));
            }
            view_.setShowActions(!"??".equals(item.getStatus()) && !"UU".equals(item.getStatus()));
            view_.setData(allLines, patchMode);
        }

        @Override
        public void onError(ServerError error) {
            JSONNumber size = error.getClientInfo().isNumber();
            if (size != null)
                view_.showSizeWarning((long) size.doubleValue());
            else {
                if (error.getCode() != ServerError.TRANSMISSION)
                    super.onError(error);
            }
        }
    });
}
Also used : StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) Token(org.rstudio.core.client.Invalidation.Token) JSONNumber(com.google.gwt.json.client.JSONNumber) DiffResult(org.rstudio.studio.client.common.vcs.DiffResult) PatchMode(org.rstudio.studio.client.common.vcs.GitServerOperations.PatchMode)

Example 5 with Token

use of org.rstudio.core.client.Invalidation.Token in project rstudio by rstudio.

the class ImportFileSettingsDialog method updateOutput.

private void updateOutput() {
    if (separator_.getSelectedIndex() < 0 || quote_.getSelectedIndex() < 0 || decimal_.getSelectedIndex() < 0) {
        return;
    }
    updateRequest_.invalidate();
    final Token invalidationToken = updateRequest_.getInvalidationToken();
    progress_.onProgress("Updating preview");
    server_.getOutputPreview(dataFile_.getPath(), encoding_.getValue(encoding_.getSelectedIndex()), headingYes_.getValue().booleanValue(), separator_.getValue(separator_.getSelectedIndex()), decimal_.getValue(decimal_.getSelectedIndex()), quote_.getValue(quote_.getSelectedIndex()), comment_.getValue(comment_.getSelectedIndex()), new ServerRequestCallback<DataPreviewResult>() {

        @Override
        public void onResponseReceived(DataPreviewResult response) {
            if (invalidationToken.isInvalid())
                return;
            progress_.onProgress(null);
            populateOutput(response);
        }

        @Override
        public void onError(ServerError error) {
            if (invalidationToken.isInvalid())
                return;
            progress_.onProgress(null);
            globalDisplay_.showErrorMessage("Error", error.getUserMessage());
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) DataPreviewResult(org.rstudio.studio.client.workbench.views.environment.model.DataPreviewResult) Token(org.rstudio.core.client.Invalidation.Token)

Aggregations

Token (org.rstudio.core.client.Invalidation.Token)6 ServerError (org.rstudio.studio.client.server.ServerError)5 JSONNumber (com.google.gwt.json.client.JSONNumber)3 ArrayList (java.util.ArrayList)3 DiffResult (org.rstudio.studio.client.common.vcs.DiffResult)2 StatusAndPath (org.rstudio.studio.client.common.vcs.StatusAndPath)2 DataPreviewResult (org.rstudio.studio.client.workbench.views.environment.model.DataPreviewResult)2 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Point (org.rstudio.core.client.Point)1 PatchMode (org.rstudio.studio.client.common.vcs.GitServerOperations.PatchMode)1 DiffParser (org.rstudio.studio.client.workbench.views.vcs.common.diff.DiffParser)1 ViewFileRevisionEvent (org.rstudio.studio.client.workbench.views.vcs.common.events.ViewFileRevisionEvent)1 SVNDiffParser (org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser)1