use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class AddToIndexPresenter method onAddClicked.
/** {@inheritDoc} */
@Override
public void onAddClicked() {
DevMachine devMachine = appContext.getDevMachine();
Resource[] resources = appContext.getResources();
Path projectLocation = appContext.getRootProject().getLocation();
Path[] paths = new Path[resources.length];
for (int i = 0; i < resources.length; i++) {
Path path = resources[i].getLocation().removeFirstSegments(projectLocation.segmentCount());
paths[i] = path.segmentCount() == 0 ? Path.EMPTY : path;
}
final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName());
consolesPanelPresenter.addCommandOutput(devMachine.getId(), console);
service.add(devMachine, projectLocation, view.isUpdated(), paths).then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
console.print(constant.addSuccess());
notificationManager.notify(constant.addSuccess());
view.close();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
console.printError(constant.addFailed());
notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE);
view.close();
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class BranchPresenter method onCheckoutClicked.
/** {@inheritDoc} */
@Override
public void onCheckoutClicked() {
final CheckoutRequest checkoutRequest = dtoFactory.createDto(CheckoutRequest.class);
if (selectedBranch.isRemote()) {
checkoutRequest.setTrackBranch(selectedBranch.getDisplayName());
} else {
checkoutRequest.setName(selectedBranch.getDisplayName());
}
service.checkout(appContext.getDevMachine(), project.getLocation(), checkoutRequest).then(new Operation<Void>() {
@Override
public void apply(Void ignored) throws OperationException {
getBranches();
project.synchronize();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
handleError(error.getCause(), BRANCH_CHECKOUT_COMMAND_NAME);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class CommitPresenter method setAmendCommitMessage.
/** {@inheritDoc} */
@Override
public void setAmendCommitMessage() {
service.log(appContext.getDevMachine(), project.getLocation(), null, false).then(new Operation<LogResponse>() {
@Override
public void apply(LogResponse log) throws OperationException {
final List<Revision> commits = log.getCommits();
String message = "";
if (commits != null && (!commits.isEmpty())) {
final Revision tip = commits.get(0);
if (tip != null) {
message = tip.getMessage();
}
}
CommitPresenter.this.view.setMessage(message);
CommitPresenter.this.view.setEnableCommitButton(!message.isEmpty());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
if (getErrorCode(error.getCause()) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) {
dialogFactory.createMessageDialog(constant.commitTitle(), constant.initCommitWasNotPerformed(), null).show();
} else {
CommitPresenter.this.view.setMessage("");
notificationManager.notify(constant.logFailed(), FAIL, NOT_EMERGE_MODE);
}
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class ComparePresenter method showCompareBetweenRevisions.
/**
*
* @param file
* path of the file
* @param status
* status of the file
* @param revisionA
* hash of the first revision or branch.
* If it is set to {@code null}, compare with empty repository state will be performed
* @param revisionB
* hash of the second revision or branch.
* If it is set to {@code null}, compare with latest repository state will be performed
*/
public void showCompareBetweenRevisions(final Path file, final Status status, @Nullable final String revisionA, @Nullable final String revisionB) {
this.compareWithLatest = false;
final DevMachine devMachine = appContext.getDevMachine();
final Path projectLocation = appContext.getRootProject().getLocation();
view.setTitle(file.toString());
if (status == Status.ADDED) {
service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA == null ? "" : revisionA + locale.compareReadOnlyTitle());
view.show("", response.getContent(), file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else if (status == Status.DELETED) {
service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
view.show(response.getContent(), "", file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else {
service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(final ShowFileContentResponse contentAResponse) throws OperationException {
service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse contentBResponse) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
view.show(contentAResponse.getContent(), contentBResponse.getContent(), file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
}
});
}
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class PullPresenter method updateBranches.
/**
* Update the list of branches.
*
* @param remoteMode
* is a remote mode
*/
private void updateBranches(@NotNull final BranchListMode remoteMode) {
service.branchList(appContext.getDevMachine(), project.getLocation(), remoteMode).then(new Operation<List<Branch>>() {
@Override
public void apply(List<Branch> branches) throws OperationException {
if (LIST_REMOTE.equals(remoteMode)) {
view.setRemoteBranches(branchSearcher.getRemoteBranchesToDisplay(view.getRepositoryName(), branches));
updateBranches(LIST_LOCAL);
} else {
view.setLocalBranches(branchSearcher.getLocalBranchesToDisplay(branches));
for (Branch branch : branches) {
if (branch.isActive()) {
view.selectRemoteBranch(branch.getDisplayName());
break;
}
}
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
handleError(error.getCause(), BRANCH_LIST_COMMAND_NAME);
view.setEnablePullButton(false);
}
});
}
Aggregations