Search in sources :

Example 6 with ChangeCreationResult

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

the class MovePresenter method onAcceptButtonClicked.

/** {@inheritDoc} */
@Override
public void onAcceptButtonClicked() {
    final RefactoringSession session = dtoFactory.createDto(RefactoringSession.class);
    session.setSessionId(refactoringSessionId);
    prepareMovingChanges(session).then(new Operation<ChangeCreationResult>() {

        @Override
        public void apply(ChangeCreationResult arg) throws OperationException {
            if (arg.isCanShowPreviewPage()) {
                eventBus.fireEvent(newFileTrackingSuspendEvent());
                refactorService.applyRefactoring(session).then(new Operation<RefactoringResult>() {

                    @Override
                    public void apply(RefactoringResult arg) throws OperationException {
                        if (arg.getSeverity() == OK) {
                            view.hide();
                            refactoringUpdater.updateAfterRefactoring(arg.getChanges());
                            final Resource[] resources = refactorInfo.getResources();
                            if (resources != null && resources.length == 1) {
                                refactorService.reindexProject(resources[0].getRelatedProject().get().getLocation().toString());
                            }
                        } else {
                            view.showErrorMessage(arg);
                        }
                        for (ChangeInfo change : arg.getChanges()) {
                            final String path = change.getPath();
                            final String oldPath = change.getOldPath();
                            eventBus.fireEvent(newFileTrackingMoveEvent(path, oldPath));
                        }
                        eventBus.fireEvent(newFileTrackingResumeEvent());
                    }
                });
            } else {
                view.showErrorMessage(arg.getStatus());
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(locale.applyMoveError(), error.getMessage(), Status.FAIL, FLOAT_MODE);
        }
    });
}
Also used : ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) RefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 7 with ChangeCreationResult

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

the class RenamePresenter method applyChanges.

private void applyChanges() {
    final RefactoringSession session = dtoFactory.createDto(RefactoringSession.class);
    session.setSessionId(renameRefactoringSession.getSessionId());
    prepareRenameChanges(session).then(new Operation<ChangeCreationResult>() {

        @Override
        public void apply(ChangeCreationResult arg) throws OperationException {
            int severityCode = arg.getStatus().getSeverity();
            switch(severityCode) {
                case WARNING:
                case ERROR:
                    showWarningDialog(session, arg);
                    break;
                case FATAL:
                    if (!arg.isCanShowPreviewPage()) {
                        view.showErrorMessage(arg.getStatus());
                    }
                    break;
                default:
                    applyRefactoring(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) RefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)7 Operation (org.eclipse.che.api.promises.client.Operation)4 OperationException (org.eclipse.che.api.promises.client.OperationException)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 RefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession)4 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IType (org.eclipse.jdt.core.IType)2 Test (org.junit.Test)2 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)1 MoveSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)1 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)1 RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)1 RenameSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings)1 ReorgDestination (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination)1 DtoServerImpls (org.eclipse.che.plugin.java.server.dto.DtoServerImpls)1 RefactoringException (org.eclipse.che.plugin.java.server.refactoring.RefactoringException)1 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)1 MoveCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)1 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)1