Search in sources :

Example 1 with CreateRenameRefactoring

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring 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 2 with CreateRenameRefactoring

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring in project che by eclipse.

the class JavaRefactoringRename method createLinkedRenameSession.

private void createLinkedRenameSession() {
    final CreateRenameRefactoring refactoringSession = createRenameRefactoringDto(textEditor, true);
    Promise<RenameRefactoringSession> createRenamePromise = refactoringServiceClient.createRenameRefactoring(refactoringSession);
    createRenamePromise.then(new Operation<RenameRefactoringSession>() {

        @Override
        public void apply(RenameRefactoringSession session) throws OperationException {
            activateLinkedModeIntoEditor(session, textEditor.getDocument());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            isActiveLinkedEditor = false;
            showError();
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with CreateRenameRefactoring

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring in project che by eclipse.

the class JavaRefactoringRename method createRenameSession.

private void createRenameSession() {
    final CreateRenameRefactoring refactoringSession = createRenameRefactoringDto(textEditor, false);
    Promise<RenameRefactoringSession> createRenamePromise = refactoringServiceClient.createRenameRefactoring(refactoringSession);
    createRenamePromise.then(new Operation<RenameRefactoringSession>() {

        @Override
        public void apply(RenameRefactoringSession session) throws OperationException {
            renamePresenter.show(session);
            if (mode != null) {
                mode.exitLinkedMode(false);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            showError();
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with CreateRenameRefactoring

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring in project che by eclipse.

the class RenamePresenter method createRenameRefactoringDto.

private CreateRenameRefactoring createRenameRefactoringDto(RefactorInfo refactorInfo) {
    CreateRenameRefactoring dto = dtoFactory.createDto(CreateRenameRefactoring.class);
    dto.setRefactorLightweight(false);
    if (refactorInfo == null) {
        final VirtualFile file = editorAgent.getActiveEditor().getEditorInput().getFile();
        dto.setType(JAVA_ELEMENT);
        dto.setPath(JavaUtil.resolveFQN(file));
        dto.setOffset(((TextEditor) editorAgent.getActiveEditor()).getCursorOffset());
        if (file instanceof Resource) {
            final Project project = ((Resource) file).getRelatedProject().get();
            dto.setProjectPath(project.getLocation().toString());
        }
    } else {
        final Resource[] resources = refactorInfo.getResources();
        checkState(resources != null && resources.length == 1);
        final Resource resource = resources[0];
        if (resource.getResourceType() == FILE) {
            dto.setPath(JavaUtil.resolveFQN(resource));
            dto.setType(COMPILATION_UNIT);
        } else if (resource instanceof Container) {
            dto.setPath(resource.getLocation().toString());
            dto.setType(PACKAGE);
        }
        final Project project = resource.getRelatedProject().get();
        dto.setProjectPath(project.getLocation().toString());
    }
    return dto;
}
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) Resource(org.eclipse.che.ide.api.resources.Resource) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring)

Example 5 with CreateRenameRefactoring

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring in project che by eclipse.

the class RenamePresenter method show.

/**
     * Show Rename window with the special information.
     *
     * @param refactorInfo
     *         information about the rename operation
     */
public void show(RefactorInfo refactorInfo) {
    this.refactorInfo = refactorInfo;
    final CreateRenameRefactoring createRenameRefactoring = createRenameRefactoringDto(refactorInfo);
    Promise<RenameRefactoringSession> createRenamePromise = refactorService.createRenameRefactoring(createRenameRefactoring);
    createRenamePromise.then(new Operation<RenameRefactoringSession>() {

        @Override
        public void apply(RenameRefactoringSession session) throws OperationException {
            show(session);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

CreateRenameRefactoring (org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring)5 Operation (org.eclipse.che.api.promises.client.Operation)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)3 Project (org.eclipse.che.ide.api.resources.Project)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)2 NotNull (javax.validation.constraints.NotNull)1 Container (org.eclipse.che.ide.api.resources.Container)1