use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class OpenDeclarationFinder method openDeclaration.
public void openDeclaration() {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor == null) {
return;
}
if (!(activeEditor instanceof TextEditor)) {
Log.error(getClass(), "Open Declaration support only TextEditor as editor");
return;
}
TextEditor editor = ((TextEditor) activeEditor);
int offset = editor.getCursorOffset();
final VirtualFile file = editor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent()) {
return;
}
final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
navigationService.findDeclaration(project.get().getLocation(), fqn, offset).then(new Operation<OpenDeclarationDescriptor>() {
@Override
public void apply(OpenDeclarationDescriptor result) throws OperationException {
if (result != null) {
handleDescriptor(project.get().getLocation(), result);
}
}
});
} else if (file instanceof JarFileNode) {
navigationService.findDeclaration(((JarFileNode) file).getProjectLocation(), file.getLocation().toString().replace('/', '.'), offset).then(new Operation<OpenDeclarationDescriptor>() {
@Override
public void apply(OpenDeclarationDescriptor result) throws OperationException {
if (result != null) {
handleDescriptor(((JarFileNode) file).getProject(), result);
}
}
});
}
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class OpenDeclarationFinder method handleDescriptor.
private void handleDescriptor(final Path projectPath, final OpenDeclarationDescriptor descriptor) {
final EditorPartPresenter openedEditor = editorAgent.getOpenedEditor(Path.valueOf(descriptor.getPath()));
if (openedEditor != null) {
editorAgent.openEditor(openedEditor.getEditorInput().getFile(), new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursorAndActivateEditor(editor, descriptor.getOffset());
}
@Override
public void onEditorActivated(EditorPartPresenter editor) {
setCursorAndActivateEditor(editor, descriptor.getOffset());
}
});
return;
}
if (descriptor.isBinary()) {
navigationService.getEntry(projectPath, descriptor.getLibId(), descriptor.getPath()).then(new Operation<JarEntry>() {
@Override
public void apply(final JarEntry entry) throws OperationException {
navigationService.getContent(projectPath, descriptor.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final VirtualFile file = javaNodeFactory.newJarFileNode(entry, descriptor.getLibId(), projectPath, null);
editorAgent.openEditor(file, new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(final EditorPartPresenter editor) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
if (editor instanceof TextEditor) {
((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
editor.activate();
}
}
});
}
});
}
});
}
});
} else {
appContext.getWorkspaceRoot().getFile(descriptor.getPath()).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(final EditorPartPresenter editor) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
if (editor instanceof TextEditor) {
((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
editor.activate();
}
}
});
}
});
}
}
});
}
}
use of org.eclipse.che.api.promises.client.OperationException 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.OperationException 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.OperationException 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