Search in sources :

Example 11 with Resource

use of org.eclipse.che.ide.api.resources.Resource 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)

Example 12 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class JavaRefactoringRename method createRenameRefactoringDto.

@NotNull
private CreateRenameRefactoring createRenameRefactoringDto(TextEditor editor, boolean isActiveLinkedMode) {
    CreateRenameRefactoring dto = dtoFactory.createDto(CreateRenameRefactoring.class);
    dto.setOffset(editor.getCursorOffset());
    dto.setRefactorLightweight(isActiveLinkedMode);
    final VirtualFile file = editor.getEditorInput().getFile();
    dto.setPath(JavaUtil.resolveFQN(file));
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        dto.setProjectPath(project.get().getLocation().toString());
    }
    dto.setType(JAVA_ELEMENT);
    return dto;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring) NotNull(javax.validation.constraints.NotNull)

Example 13 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class RenameRefactoringAction method updateInPerspective.

@Override
public void updateInPerspective(ActionEvent event) {
    event.getPresentation().setVisible(true);
    if (editorInFocus) {
        final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
        if (editorPart == null || !(editorPart instanceof TextEditor)) {
            event.getPresentation().setEnabled(false);
            return;
        }
        final VirtualFile file = editorPart.getEditorInput().getFile();
        if (file instanceof File) {
            final Optional<Project> project = ((File) file).getRelatedProject();
            if (!project.isPresent()) {
                event.getPresentation().setEnabled(false);
                return;
            }
            event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && isJavaFile(file));
        } else {
            event.getPresentation().setEnabled(isJavaFile(file));
        }
    } else {
        final Resource[] resources = appContext.getResources();
        if (resources == null || resources.length > 1) {
            event.getPresentation().setEnabled(false);
            return;
        }
        final Resource resource = resources[0];
        final Optional<Project> project = resource.getRelatedProject();
        if (!project.isPresent()) {
            event.getPresentation().setEnabled(false);
            return;
        }
        final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
        if (resource.getResourceType() == FILE) {
            event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent() && isJavaFile((File) resource));
        } else if (resource instanceof Container) {
            event.getPresentation().setEnabled(JavaUtil.isJavaProject(project.get()) && srcFolder.isPresent());
        }
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Resource(org.eclipse.che.ide.api.resources.Resource) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 14 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class RenameRefactoringAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    if (editorInFocus) {
        final EditorPartPresenter editorPart = editorAgent.getActiveEditor();
        if (editorPart == null || !(editorPart instanceof TextEditor)) {
            return;
        }
        javaRefactoringRename.refactor((TextEditor) editorPart);
    } else {
        final Resource[] resources = appContext.getResources();
        if (resources == null || resources.length > 1) {
            return;
        }
        final Resource resource = resources[0];
        final Optional<Project> project = resource.getRelatedProject();
        if (!JavaUtil.isJavaProject(project.get())) {
            return;
        }
        final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent() || resource.getLocation().equals(srcFolder.get().getLocation())) {
            return;
        }
        RefactoredItemType renamedItemType = null;
        if (resource.getResourceType() == FILE && isJavaFile((File) resource)) {
            renamedItemType = COMPILATION_UNIT;
        } else if (resource instanceof Container) {
            renamedItemType = PACKAGE;
        }
        if (renamedItemType == null) {
            return;
        }
        renamePresenter.show(RefactorInfo.of(renamedItemType, resources));
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Resource(org.eclipse.che.ide.api.resources.Resource) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) RefactoredItemType(org.eclipse.che.ide.ext.java.client.refactoring.move.RefactoredItemType) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 15 with Resource

use of org.eclipse.che.ide.api.resources.Resource 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());
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) 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) List(java.util.List) MethodParameters(org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Resource (org.eclipse.che.ide.api.resources.Resource)146 Project (org.eclipse.che.ide.api.resources.Project)73 OperationException (org.eclipse.che.api.promises.client.OperationException)48 Operation (org.eclipse.che.api.promises.client.Operation)46 PromiseError (org.eclipse.che.api.promises.client.PromiseError)40 Container (org.eclipse.che.ide.api.resources.Container)32 Path (org.eclipse.che.ide.resource.Path)30 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)22 Optional (com.google.common.base.Optional)15 File (org.eclipse.che.ide.api.resources.File)14 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)14 List (java.util.List)13 Promise (org.eclipse.che.api.promises.client.Promise)13 FunctionException (org.eclipse.che.api.promises.client.FunctionException)12 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)12 ArrayList (java.util.ArrayList)11 Function (org.eclipse.che.api.promises.client.Function)9 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)9 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)9 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)8