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 AbstractDebugger method deleteBreakpoint.
@Override
public void deleteBreakpoint(final VirtualFile file, final int lineNumber) {
if (!isConnected()) {
return;
}
LocationDto locationDto = dtoFactory.createDto(LocationDto.class);
locationDto.setLineNumber(lineNumber + 1);
String fqn = pathToFqn(file);
if (fqn == null) {
return;
}
locationDto.setTarget(fqn);
Promise<Void> promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto);
promise.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
for (DebuggerObserver observer : observers) {
Breakpoint breakpoint = new Breakpoint(Breakpoint.Type.BREAKPOINT, lineNumber, file.getLocation().toString(), file, false);
observer.onBreakpointDeleted(breakpoint);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(AbstractDebugger.class, arg.getMessage());
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class AbstractDebugger method disconnect.
@Override
public void disconnect() {
stopCheckingDebugEvents();
Promise<Void> disconnect;
if (isConnected()) {
disconnect = service.disconnect(debugSessionDto.getId());
} else {
disconnect = Promises.resolve(null);
}
invalidateDebugSession();
preserveDebuggerState();
disconnect.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
for (DebuggerObserver observer : observers) {
observer.onDebuggerDisconnected();
}
debuggerManager.setActiveDebugger(null);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
for (DebuggerObserver observer : observers) {
observer.onDebuggerDisconnected();
}
debuggerManager.setActiveDebugger(null);
}
});
}
Aggregations