use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class FetchPresenter method onFetchClicked.
/** {@inheritDoc} */
@Override
public void onFetchClicked() {
final String remoteUrl = view.getRepositoryUrl();
final StatusNotification notification = notificationManager.notify(constant.fetchProcess(), PROGRESS, FLOAT_MODE);
final GitOutputConsole console = gitOutputConsoleFactory.create(FETCH_COMMAND_NAME);
service.fetch(appContext.getDevMachine(), project.getLocation(), view.getRepositoryName(), getRefs(), view.isRemoveDeletedRefs()).then(new Operation<Void>() {
@Override
public void apply(Void ignored) throws OperationException {
console.print(constant.fetchSuccess(remoteUrl));
processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notification.setStatus(SUCCESS);
notification.setTitle(constant.fetchSuccess(remoteUrl));
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
handleError(error.getCause(), remoteUrl, 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 CompareWithLatestAction method actionPerformed.
/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
final Project project = appContext.getRootProject();
final Resource resource = appContext.getResource();
checkState(project != null, "Null project occurred");
checkState(project.getLocation().isPrefixOf(resource.getLocation()), "Given selected item is not descendant of given project");
final String selectedItemPath = resource.getLocation().removeFirstSegments(project.getLocation().segmentCount()).removeTrailingSeparator().toString();
service.diff(appContext.getDevMachine(), project.getLocation(), selectedItemPath.isEmpty() ? null : singletonList(selectedItemPath), NAME_STATUS, false, 0, REVISION, false).then(new Operation<String>() {
@Override
public void apply(String diff) throws OperationException {
if (diff.isEmpty()) {
dialogFactory.createMessageDialog(locale.compareMessageIdenticalContentTitle(), locale.compareMessageIdenticalContentText(), null).show();
} else {
final String[] changedFiles = diff.split("\n");
if (changedFiles.length == 1) {
project.getFile(changedFiles[0].substring(2)).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
comparePresenter.showCompareWithLatest(file.get(), defineStatus(changedFiles[0].substring(0, 1)), REVISION);
}
}
});
} else {
Map<String, Status> items = new HashMap<>();
for (String item : changedFiles) {
items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)));
}
changedListPresenter.show(items, REVISION, null, project);
}
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class InitRepositoryPresenter method initRepository.
public void initRepository(final Project project) {
final GitOutputConsole console = gitOutputConsoleFactory.create(INIT_COMMAND_NAME);
service.init(appContext.getDevMachine(), project.getLocation(), false).then(new Operation<Void>() {
@Override
public void apply(Void ignored) throws OperationException {
console.print(constant.initSuccess());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(constant.initSuccess());
project.synchronize();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
handleError(error.getCause(), console);
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class MergePresenter method onMergeClicked.
/** {@inheritDoc} */
@Override
public void onMergeClicked() {
view.close();
final GitOutputConsole console = gitOutputConsoleFactory.create(MERGE_COMMAND_NAME);
service.merge(appContext.getDevMachine(), project.getLocation(), selectedReference.getDisplayName()).then(new Operation<MergeResult>() {
@Override
public void apply(MergeResult result) throws OperationException {
console.print(formMergeMessage(result));
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(formMergeMessage(result));
project.synchronize();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
if (error.getCause() instanceof ServerException && ((ServerException) error.getCause()).getErrorCode() == ErrorCodes.NO_COMMITTER_NAME_OR_EMAIL_DEFINED) {
dialogFactory.createMessageDialog(constant.mergeTitle(), constant.committerIdentityInfoEmpty(), new ConfirmCallback() {
@Override
public void accepted() {
//do nothing
}
}).show();
return;
}
console.printError(error.getMessage());
consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
notificationManager.notify(constant.mergeFailed(), FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class ComparePresenter method showCompareWithLatest.
/**
* Show compare window.
*
* @param file
* file name with its full path
* @param status
* status of the file
* @param revision
* hash of revision or branch
*/
public void showCompareWithLatest(final File file, final Status status, final String revision) {
this.comparedFile = file;
this.revision = revision;
this.compareWithLatest = true;
if (status.equals(ADDED)) {
showCompare("");
return;
}
final Optional<Project> project = file.getRelatedProject();
if (!project.isPresent()) {
return;
}
final Path relPath = file.getLocation().removeFirstSegments(project.get().getLocation().segmentCount());
if (status.equals(DELETED)) {
service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse content) throws OperationException {
view.setTitle(file.getLocation().toString());
view.setColumnTitles(locale.compareYourVersionTitle(), revision + locale.compareReadOnlyTitle());
view.show(content.getContent(), "", file.getLocation().toString(), false);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else {
service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse content) throws OperationException {
showCompare(content.getContent());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
}
}
Aggregations