use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class BreakpointManagerImpl method restoreBreakpoints.
private void restoreBreakpoints() {
Storage localStorage = Storage.getLocalStorageIfSupported();
if (localStorage == null) {
return;
}
String data = localStorage.getItem(LOCAL_STORAGE_BREAKPOINTS_KEY);
if (data == null || data.isEmpty()) {
return;
}
List<StorableBreakpointDto> allDtoBreakpoints = dtoFactory.createListDtoFromJson(data, StorableBreakpointDto.class);
Promise<Void> bpPromise = promises.resolve(null);
for (final StorableBreakpointDto dto : allDtoBreakpoints) {
bpPromise.thenPromise(new Function<Void, Promise<Void>>() {
@Override
public Promise<Void> apply(Void ignored) throws FunctionException {
return appContext.getWorkspaceRoot().getFile(dto.getPath()).then(new Function<Optional<File>, Void>() {
@Override
public Void apply(Optional<File> file) throws FunctionException {
if (!file.isPresent()) {
return null;
}
if (dto.getType() == Type.CURRENT) {
doSetCurrentBreakpoint(file.get(), dto.getLineNumber());
} else {
addBreakpoint(new Breakpoint(dto.getType(), dto.getLineNumber(), dto.getPath(), file.get(), dto.isActive()));
}
return null;
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(getClass(), "Failed to restore breakpoint. ", arg.getCause());
}
});
}
});
}
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class CreateWorkspacePresenter method createWorkspace.
private void createWorkspace() {
WorkspaceConfigDto workspaceConfig = getWorkspaceConfig();
workspaceClient.create(workspaceConfig, null).then(new Operation<WorkspaceDto>() {
@Override
public void apply(WorkspaceDto workspace) throws OperationException {
DefaultWorkspaceComponent component = wsComponentProvider.get();
component.startWorkspace(workspace, callback);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
callback.onFailure(new Exception(arg.getCause()));
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class RenamePresenter method showPreview.
private void showPreview() {
RefactoringSession session = dtoFactory.createDto(RefactoringSession.class);
session.setSessionId(renameRefactoringSession.getSessionId());
prepareRenameChanges(session).then(new Operation<ChangeCreationResult>() {
@Override
public void apply(ChangeCreationResult arg) throws OperationException {
if (arg.isCanShowPreviewPage() || arg.getStatus().getSeverity() <= 3) {
previewPresenter.show(renameRefactoringSession.getSessionId(), refactorInfo);
previewPresenter.setTitle(locale.renameItemTitle());
view.hide();
} else {
view.showErrorMessage(arg.getStatus());
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class FindUsagesPresenter method findUsages.
public void findUsages(TextEditor activeEditor) {
final VirtualFile virtualFile = activeEditor.getEditorInput().getFile();
if (virtualFile instanceof Resource) {
final Project project = ((Resource) virtualFile).getRelatedProject().get();
if (project == null) {
return;
}
final Optional<Resource> srcFolder = ((Resource) virtualFile).getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent()) {
return;
}
final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) virtualFile);
String projectPath = project.getLocation().toString();
FindUsagesRequest request = dtoFactory.createDto(FindUsagesRequest.class);
request.setFQN(fqn);
request.setProjectPath(projectPath);
request.setOffset(activeEditor.getCursorOffset());
Promise<FindUsagesResponse> promise = searchService.findUsages(request);
promise.then(new Operation<FindUsagesResponse>() {
@Override
public void apply(FindUsagesResponse arg) throws OperationException {
handleResponse(arg);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Throwable cause = arg.getCause();
if (cause instanceof ServerException) {
handleError(((ServerException) cause).getHTTPStatus(), cause.getMessage());
return;
}
//in case websocket request
if (cause instanceof org.eclipse.che.ide.websocket.rest.exceptions.ServerException) {
handleError(((org.eclipse.che.ide.websocket.rest.exceptions.ServerException) cause).getHTTPStatus(), cause.getMessage());
return;
}
Log.error(getClass(), arg);
manager.notify(localizationConstant.failedToProcessFindUsage(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class ParametersHintsPresenter method show.
/**
* The method gets method parameters via {@link JavaNavigationService} and then call special method on view to display them.
*
* @param activeEditor
* active editor which contains method or constructor for which parameters will be displayed
*/
public void show(final TextEditor activeEditor) {
final int offset = activeEditor.getCursorOffset();
if (!isCursorInRightPlace(activeEditor, offset)) {
return;
}
VirtualFile file = activeEditor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
final int lineStartOffset = getLineStartOffset(activeEditor, offset);
navigationService.getMethodParametersHints(project.get().getLocation(), JavaUtil.resolveFQN(file), offset, lineStartOffset).then(new Operation<List<MethodParameters>>() {
@Override
public void apply(List<MethodParameters> parameters) throws OperationException {
if (parameters.isEmpty()) {
return;
}
PositionConverter.PixelCoordinates coordinates = activeEditor.getPositionConverter().offsetToPixel(offset);
view.show(parameters, coordinates.getX(), coordinates.getY());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
Log.error(getClass(), error.getMessage());
}
});
}
}
Aggregations