use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class PropertyEditorPresenter method editProperty.
private void editProperty(Project project) {
final String propertyName = view.getSelectedProperty();
final Depth depth = view.getDepth();
final String propertyValue = view.getPropertyValue();
final boolean force = view.isForceSelected();
final Resource[] resources = appContext.getResources();
checkState(!Arrays.isNullOrEmpty(resources));
checkState(resources.length == 1);
final StatusNotification notification = new StatusNotification(constants.propertyModifyStart(), PROGRESS, FLOAT_MODE);
notificationManager.notify(notification);
service.propertySet(project.getLocation(), propertyName, propertyValue, depth, force, toRelative(project, resources[0])).then(new Operation<CLIOutputResponse>() {
@Override
public void apply(CLIOutputResponse response) throws OperationException {
printResponse(response.getCommand(), response.getOutput(), response.getErrOutput(), constants.commandProperty());
notification.setTitle(constants.propertyModifyFinished());
notification.setStatus(SUCCESS);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notification.setTitle(constants.propertyModifyFailed());
notification.setStatus(FAIL);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class DeleteResourceManager method onConfirm.
private ConfirmCallback onConfirm(final Resource[] resources, final AsyncCallback<Void> callback) {
return new ConfirmCallback() {
@Override
public void accepted() {
if (resources == null) {
//sometimes we may occur NPE here while reading length
callback.onFailure(new IllegalStateException());
return;
}
Promise<?>[] deleteAll = new Promise<?>[resources.length];
for (int i = 0; i < resources.length; i++) {
final Resource resource = resources[i];
deleteAll[i] = resource.delete().catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify("Failed to delete '" + resource.getName() + "'", error.getMessage(), FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
}
});
}
promiseProvider.all(deleteAll).then(new Operation<JsArrayMixed>() {
@Override
public void apply(JsArrayMixed arg) throws OperationException {
callback.onSuccess(null);
}
});
}
};
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class EvaluateExpressionPresenter method onEvaluateClicked.
/** {@inheritDoc} */
@Override
public void onEvaluateClicked() {
Debugger debugger = debuggerManager.getActiveDebugger();
if (debugger != null) {
view.setEnableEvaluateButton(false);
debugger.evaluate(view.getExpression()).then(new Operation<String>() {
@Override
public void apply(String result) throws OperationException {
view.setResult(result);
view.setEnableEvaluateButton(true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
view.setResult(constant.evaluateExpressionFailed(error.getMessage()));
view.setEnableEvaluateButton(true);
}
});
}
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class MovePresenter method show.
/**
* Show Move panel with the special information.
*
* @param refactorInfo
* information about the move operation
*/
public void show(final RefactorInfo refactorInfo) {
this.refactorInfo = refactorInfo;
view.setEnablePreviewButton(false);
view.setEnableAcceptButton(false);
view.clearErrorLabel();
CreateMoveRefactoring moveRefactoring = createMoveDto();
Promise<String> sessionIdPromise = refactorService.createMoveRefactoring(moveRefactoring);
sessionIdPromise.then(new Operation<String>() {
@Override
public void apply(String sessionId) throws OperationException {
MovePresenter.this.refactoringSessionId = sessionId;
showProjectsAndPackages();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), Status.FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class MovePresenter method onPreviewButtonClicked.
/** {@inheritDoc} */
@Override
public void onPreviewButtonClicked() {
RefactoringSession session = dtoFactory.createDto(RefactoringSession.class);
session.setSessionId(refactoringSessionId);
prepareMovingChanges(session).then(new Operation<ChangeCreationResult>() {
@Override
public void apply(ChangeCreationResult arg) throws OperationException {
if (arg.isCanShowPreviewPage()) {
previewPresenter.show(refactoringSessionId, refactorInfo);
view.hide();
} else {
view.showStatusMessage(arg.getStatus());
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(locale.showPreviewError(), error.getMessage(), Status.FAIL, FLOAT_MODE);
}
});
}
Aggregations