use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class AbstractNewResourceAction method createFile.
final void createFile(String nameWithoutExtension) {
final String name = getExtension().isEmpty() ? nameWithoutExtension : nameWithoutExtension + '.' + getExtension();
Resource resource = appContext.getResource();
if (!(resource instanceof Container)) {
final Container parent = resource.getParent();
checkState(parent != null, "Parent should be a container");
resource = parent;
}
((Container) resource).newFile(name, getDefaultContent()).then(new Operation<File>() {
@Override
public void apply(File newFile) throws OperationException {
eventBus.fireEvent(FileEvent.createOpenFileEvent(newFile));
eventBus.fireEvent(new RevealResourceEvent(newFile));
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify("Failed to create resource", error.getMessage(), FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class DeleteRepositoryPresenter method deleteRepository.
/** Delete Git repository. */
public void deleteRepository(final Project project) {
final GitOutputConsole console = gitOutputConsoleFactory.create(DELETE_REPO_COMMAND_NAME);
service.deleteRepository(appContext.getDevMachine(), project.getLocation()).then(new Operation<Void>() {
@Override
public void apply(Void ignored) throws OperationException {
console.print(constant.deleteGitRepositorySuccess());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(constant.deleteGitRepositorySuccess());
project.synchronize();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
console.printError(error.getMessage());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(constant.failedToDeleteRepository(), FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class FetchPresenter 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 {
final String errorMessage = error.getMessage() != null ? error.getMessage() : constant.branchesListFailed();
GitOutputConsole console = gitOutputConsoleFactory.create(FETCH_COMMAND_NAME);
console.printError(errorMessage);
processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(constant.branchesListFailed(), FAIL, FLOAT_MODE);
view.setEnableFetchButton(false);
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class MergePresenter method showDialog.
/** Show dialog. */
public void showDialog(Project project) {
this.project = project;
final GitOutputConsole console = gitOutputConsoleFactory.create(MERGE_COMMAND_NAME);
selectedReference = null;
view.setEnableMergeButton(false);
service.branchList(appContext.getDevMachine(), project.getLocation(), LIST_LOCAL).then(new Operation<List<Branch>>() {
@Override
public void apply(List<Branch> branches) throws OperationException {
List<Reference> references = new ArrayList<>();
for (Branch branch : branches) {
if (!branch.isActive()) {
Reference reference = new Reference(branch.getName(), branch.getDisplayName(), LOCAL_BRANCH);
references.add(reference);
}
}
view.setLocalBranches(references);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
console.printError(error.getMessage());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(constant.branchesListFailed(), FAIL, FLOAT_MODE);
}
});
service.branchList(appContext.getDevMachine(), project.getLocation(), LIST_REMOTE).then(new Operation<List<Branch>>() {
@Override
public void apply(List<Branch> branches) throws OperationException {
List<Reference> references = new ArrayList<>();
for (Branch branch : branches) {
if (!branch.isActive()) {
Reference reference = new Reference(branch.getName(), branch.getDisplayName(), REMOTE_BRANCH);
references.add(reference);
}
}
view.setRemoteBranches(references);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
console.printError(error.getMessage());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(constant.branchesListFailed(), FAIL, FLOAT_MODE);
}
});
view.showDialog();
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class PullPresenter method onPullClicked.
/** {@inheritDoc} */
@Override
public void onPullClicked() {
view.close();
final StatusNotification notification = notificationManager.notify(constant.pullProcess(), PROGRESS, FLOAT_MODE);
service.pull(appContext.getDevMachine(), project.getLocation(), getRefs(), view.getRepositoryName()).then(new Operation<PullResponse>() {
@Override
public void apply(PullResponse response) throws OperationException {
GitOutputConsole console = gitOutputConsoleFactory.create(PULL_COMMAND_NAME);
console.print(response.getCommandOutput(), GREEN_COLOR);
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notification.setStatus(SUCCESS);
if (response.getCommandOutput().contains("Already up-to-date")) {
notification.setTitle(constant.pullUpToDate());
} else {
project.synchronize();
notification.setTitle(constant.pullSuccess(view.getRepositoryUrl()));
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notification.setStatus(FAIL);
if (getErrorCode(error.getCause()) == ErrorCodes.MERGE_CONFLICT) {
project.synchronize();
}
handleError(error.getCause(), PULL_COMMAND_NAME);
}
});
}
Aggregations