Search in sources :

Example 1 with RefactoringSession

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

the class RenamePresenter method showPreview.

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

        @Override
        public void apply(ChangeCreationResult arg) throws OperationException {
            if (arg.isCanShowPreviewPage() || arg.getStatus().getSeverity() <= 3) {
                previewPresenter.show(renameRefactoringSession.getSessionId(), refactorInfo);
                previewPresenter.setTitle(locale.renameItemTitle());
                view.hide();
            } else {
                view.showErrorMessage(arg.getStatus());
            }
        }
    }).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)

Example 2 with RefactoringSession

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

the class MovePresenter method onPreviewButtonClicked.

/** {@inheritDoc} */
@Override
public void onPreviewButtonClicked() {
    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()) {
                previewPresenter.show(refactoringSessionId, refactorInfo);
                view.hide();
            } else {
                view.showStatusMessage(arg.getStatus());
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(locale.showPreviewError(), error.getMessage(), Status.FAIL, FLOAT_MODE);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) 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 3 with RefactoringSession

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

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

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 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)4 RefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession)4 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)2 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)1 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)1