Search in sources :

Example 1 with ValidateNewName

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

the class RenameRefactoringTest method testRenamePackage.

@Test
public void testRenamePackage() throws Exception {
    final IPackageFragment packageFragment = getRoot().createPackageFragment("p.a.b.c", true, null);
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(packageFragment, null, -1, false);
    assertThat(refactoring).isNotNull();
    assertThat(refactoring.getSessionId()).isNotNull().isNotEmpty();
    final ValidateNewName validateNewName = new DtoServerImpls.ValidateNewNameImpl().withNewName("p.x.s.z");
    validateNewName.setSessionId(refactoring.getSessionId());
    final RefactoringStatus status = manager.renameValidateNewName(validateNewName);
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.OK);
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ValidateNewName(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) Test(org.junit.Test)

Example 2 with ValidateNewName

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

the class RenamePresenter method validateName.

/** {@inheritDoc} */
@Override
public void validateName() {
    ValidateNewName validateNewName = dtoFactory.createDto(ValidateNewName.class);
    validateNewName.setSessionId(renameRefactoringSession.getSessionId());
    validateNewName.setNewName(view.getNewName());
    refactorService.validateNewName(validateNewName).then(new Operation<RefactoringStatus>() {

        @Override
        public void apply(RefactoringStatus arg) throws OperationException {
            switch(arg.getSeverity()) {
                case OK:
                    view.setEnableAcceptButton(true);
                    view.setEnablePreviewButton(true);
                    view.clearErrorLabel();
                    break;
                case INFO:
                    view.setEnableAcceptButton(true);
                    view.setEnablePreviewButton(true);
                    view.showStatusMessage(arg);
                    break;
                default:
                    view.setEnableAcceptButton(false);
                    view.setEnablePreviewButton(false);
                    view.showErrorMessage(arg);
                    break;
            }
        }
    }).catchError(new Operation<PromiseError>() {

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

Aggregations

RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)2 ValidateNewName (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName)2 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 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)1 DtoServerImpls (org.eclipse.che.plugin.java.server.dto.DtoServerImpls)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 Test (org.junit.Test)1