Search in sources :

Example 1 with FindUsagesRequest

use of org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesRequest 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);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) FindUsagesResponse(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse) ServerException(org.eclipse.che.ide.commons.exception.ServerException) FindUsagesRequest(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesRequest) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 ServerException (org.eclipse.che.ide.commons.exception.ServerException)1 FindUsagesRequest (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesRequest)1 FindUsagesResponse (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse)1 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)1