use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class PushToRemotePresenter method getUpstreamBranch.
/**
* Get upstream branch for selected local branch. Can invoke {@code onSuccess(null)} if upstream branch isn't set
*/
private void getUpstreamBranch(final AsyncCallback<Branch> result) {
final String configBranchRemote = "branch." + view.getLocalBranch() + ".remote";
final String configUpstreamBranch = "branch." + view.getLocalBranch() + ".merge";
service.config(appContext.getDevMachine(), project.getLocation(), Arrays.asList(configUpstreamBranch, configBranchRemote)).then(new Operation<Map<String, String>>() {
@Override
public void apply(Map<String, String> configs) throws OperationException {
if (configs.containsKey(configBranchRemote) && configs.containsKey(configUpstreamBranch)) {
String displayName = configs.get(configBranchRemote) + "/" + configs.get(configUpstreamBranch);
Branch upstream = dtoFactory.createDto(Branch.class).withActive(false).withRemote(true).withDisplayName(displayName).withName("refs/remotes/" + displayName);
result.onSuccess(upstream);
} else {
result.onSuccess(null);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
result.onFailure(error.getCause());
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class HistoryPresenterTest method shouldShowDialogOnInitCommitError.
@Test
public void shouldShowDialogOnInitCommitError() throws Exception {
PromiseError error = mock(PromiseError.class);
ServerException exception = mock(ServerException.class);
when(exception.getErrorCode()).thenReturn(ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED);
when(error.getCause()).thenReturn(exception);
when(constant.initCommitWasNotPerformed()).thenReturn("error message");
MessageDialog dialog = mock(MessageDialog.class);
when(dialogFactory.createMessageDialog(eq("title"), eq("error message"), any(ConfirmCallback.class))).thenReturn(dialog);
presenter.show();
verify(logPromise).catchError(promiseErrorCaptor.capture());
promiseErrorCaptor.getValue().apply(error);
verify(dialog).show();
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class CreateWorkspacePresenterTest method errorShouldBeCaughtWhenCreatesWorkSpace.
@Test
public void errorShouldBeCaughtWhenCreatesWorkSpace() throws Exception {
final PromiseError promiseError = mock(PromiseError.class);
clickOnCreateButton();
verify(userWsPromise).catchError(errorOperation.capture());
errorOperation.getValue().apply(promiseError);
//noinspection ThrowableResultOfMethodCallIgnored
verify(promiseError).getCause();
verify(componentCallback).onFailure(Matchers.<Exception>anyObject());
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class LanguageServerCodeAssistProcessor method computeCompletionProposals.
@Override
public void computeCompletionProposals(TextEditor editor, final int offset, final boolean triggered, final CodeAssistCallback callback) {
this.lastErrorMessage = null;
TextDocumentPositionParamsDTO documentPosition = dtoBuildHelper.createTDPP(editor.getDocument(), offset);
final TextDocumentIdentifierDTO documentId = documentPosition.getTextDocument();
String currentLine = editor.getDocument().getLineContent(documentPosition.getPosition().getLine());
final String currentWord = getCurrentWord(currentLine, documentPosition.getPosition().getCharacter());
if (!triggered && latestCompletionResult.isGoodFor(documentId, offset, currentWord)) {
// no need to send new completion request
computeProposals(currentWord, offset - latestCompletionResult.getOffset(), callback);
} else {
documentServiceClient.completion(documentPosition).then(new Operation<CompletionListDTO>() {
@Override
public void apply(CompletionListDTO list) throws OperationException {
latestCompletionResult.update(documentId, offset, currentWord, list);
computeProposals(currentWord, 0, callback);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
lastErrorMessage = error.getMessage();
}
});
}
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class LanguageServerSignatureHelp method signatureHelp.
@Override
public Promise<Optional<SignatureHelp>> signatureHelp(Document document, int offset) {
TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, offset);
Promise<SignatureHelpDTO> promise = client.signatureHelp(paramsDTO);
return promise.then(new Function<SignatureHelpDTO, Optional<SignatureHelp>>() {
@Override
public Optional<SignatureHelp> apply(SignatureHelpDTO arg) throws FunctionException {
if (arg == null) {
return Optional.absent();
}
return Optional.<SignatureHelp>of(new SignatureHelpImpl(arg));
}
}).catchError(new Function<PromiseError, Optional<SignatureHelp>>() {
@Override
public Optional<SignatureHelp> apply(PromiseError arg) throws FunctionException {
notificationManager.notify(arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.EMERGE_MODE);
return Optional.absent();
}
});
}
Aggregations