use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class PushToRemotePresenter method onPushClicked.
/** {@inheritDoc} */
@Override
public void onPushClicked() {
final StatusNotification notification = notificationManager.notify(constant.pushProcess(), PROGRESS, FLOAT_MODE);
final String repository = view.getRepository();
final GitOutputConsole console = gitOutputConsoleFactory.create(PUSH_COMMAND_NAME);
service.push(appContext.getDevMachine(), project.getLocation(), getRefs(), repository, false).then(new Operation<PushResponse>() {
@Override
public void apply(PushResponse response) throws OperationException {
console.print(response.getCommandOutput());
processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notification.setStatus(SUCCESS);
if (response.getCommandOutput().contains("Everything up-to-date")) {
notification.setTitle(constant.pushUpToDate());
} else {
notification.setTitle(constant.pushSuccess(repository));
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
handleError(error.getCause(), notification, console);
processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
}
});
view.close();
}
use of org.eclipse.che.api.promises.client.Operation 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.Operation in project che by eclipse.
the class OrionEditorPresenter method onResourceCreated.
private void onResourceCreated(ResourceDelta delta) {
if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
return;
}
final Resource resource = delta.getResource();
final Path movedFrom = delta.getFromPath();
//file moved directly
if (document.getFile().getLocation().equals(movedFrom)) {
deletedFilesController.add(movedFrom.toString());
document.setFile((File) resource);
input.setFile((File) resource);
updateContent();
} else if (movedFrom.isPrefixOf(document.getFile().getLocation())) {
//directory where file moved
final Path relPath = document.getFile().getLocation().removeFirstSegments(movedFrom.segmentCount());
final Path newPath = delta.getToPath().append(relPath);
appContext.getWorkspaceRoot().getFile(newPath).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
final Path location = document.getFile().getLocation();
deletedFilesController.add(location.toString());
generalEventBus.fireEvent(newFileTrackingStartEvent(file.get().getLocation().toString()));
document.setFile(file.get());
input.setFile(file.get());
updateTabReference(file.get(), location);
updateContent();
}
}
});
}
}
use of org.eclipse.che.api.promises.client.Operation 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.Operation in project che by eclipse.
the class FindDefinitionAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
TextEditor textEditor = ((TextEditor) activeEditor);
TextDocumentPositionParamsDTO paramsDTO = dtoBuildHelper.createTDPP(textEditor.getDocument(), textEditor.getCursorPosition());
final Promise<List<LocationDTO>> promise = client.definition(paramsDTO);
promise.then(new Operation<List<LocationDTO>>() {
@Override
public void apply(List<LocationDTO> arg) throws OperationException {
if (arg.size() == 1) {
presenter.onLocationSelected(arg.get(0));
} else {
presenter.openLocation(promise);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
presenter.showError(arg);
}
});
}
Aggregations