Search in sources :

Example 6 with RefactoringResult

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

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

the class JavaRefactoringRename method performRename.

private void performRename(RenameRefactoringSession session) {
    final LinkedRenameRefactoringApply dto = createLinkedRenameRefactoringApplyDto(newName, session.getSessionId());
    Promise<RefactoringResult> applyModelPromise = refactoringServiceClient.applyLinkedModeRename(dto);
    applyModelPromise.then(new Operation<RefactoringResult>() {

        @Override
        public void apply(RefactoringResult result) throws OperationException {
            switch(result.getSeverity()) {
                case OK:
                case INFO:
                    final VirtualFile file = textEditor.getDocument().getFile();
                    if (file instanceof Resource) {
                        final Optional<Project> project = ((Resource) file).getRelatedProject();
                        refactoringServiceClient.reindexProject(project.get().getLocation().toString());
                    }
                    refactoringUpdater.updateAfterRefactoring(result.getChanges());
                    break;
                case WARNING:
                case ERROR:
                    enableAutoSave();
                    undoChanges();
                    showWarningDialog();
                    break;
                case FATAL:
                    undoChanges();
                    notificationManager.notify(locale.failedToRename(), result.getEntries().get(0).getMessage(), FAIL, FLOAT_MODE);
                    break;
                default:
                    break;
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            enableAutoSave();
            undoChanges();
            notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) Resource(org.eclipse.che.ide.api.resources.Resource) LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)7 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)3 ArrayList (java.util.ArrayList)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)2 MoveRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession)2 RefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RefactoringSession)2 RenameLinkedModeRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession)2 ReorgRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.ReorgRefactoringSession)2 Change (org.eclipse.ltk.core.refactoring.Change)2 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)2 PerformChangeOperation (org.eclipse.ltk.core.refactoring.PerformChangeOperation)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)1