use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult 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);
}
});
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult in project che by eclipse.
the class RefactoringSession method createChange.
public ChangeCreationResult createChange() throws RefactoringException {
Change change = createChange(new CreateChangeOperation(new CheckConditionsOperation(refactoring, CheckConditionsOperation.FINAL_CONDITIONS), RefactoringStatus.FATAL), true);
// Status has been updated since we have passed true
RefactoringStatus status = conditionCheckingStatus;
// Creating the change has been canceled
if (change == null && status == null) {
internalSetChange(change);
throw new RefactoringException("Creating the change has been canceled");
}
// Set change if we don't have fatal errors.
if (!status.hasFatalError()) {
internalSetChange(change);
}
ChangeCreationResult result = DtoFactory.newDto(ChangeCreationResult.class);
result.setStatus(DtoConverter.toRefactoringStatusDto(status));
result.setCanShowPreviewPage(status.isOK());
return result;
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult in project che by eclipse.
the class MoveRefactoringSessionTest method testCtrateMoveChanges.
@Test
public void testCtrateMoveChanges() throws Exception {
IType type = fProject.findType("p.A");
ICompilationUnit unit = type.getCompilationUnit();
String sessionId = manager.createMoveRefactoringSession(new IJavaElement[] { unit });
ReorgDestination destination = new DtoServerImpls.ReorgDestinationImpl();
destination.setSessionId(sessionId);
destination.setProjectPath(RefactoringTestSetup.getProject().getPath().toOSString());
destination.setDestination(p1.getPath().toOSString());
destination.setType(ReorgDestination.DestinationType.PACKAGE);
manager.setRefactoringDestination(destination);
MoveSettings settings = new DtoServerImpls.MoveSettingsImpl();
settings.setUpdateReferences(true);
settings.setSessionId(sessionId);
manager.setMoveSettings(settings);
ChangeCreationResult change = manager.createChange(sessionId);
assertThat(change).isNotNull();
assertThat(change.isCanShowPreviewPage()).isTrue();
assertThat(change.getStatus().getSeverity()).isEqualTo(RefactoringStatus.OK);
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult 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);
}
});
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult in project che by eclipse.
the class RenameRefactoringTest method testDoRename.
@Test
public void testDoRename() throws Exception {
StringBuilder b = new StringBuilder();
b.append("package p;\n");
b.append("public class A{}\n");
ICompilationUnit unit = getPackageP().createCompilationUnit("A.java", b.toString(), false, null);
IType type = unit.getAllTypes()[0];
RenameRefactoringSession refactoring = manager.createRenameRefactoring(type, unit, b.indexOf("A"), false);
DtoServerImpls.ValidateNewNameImpl validateNewName = new DtoServerImpls.ValidateNewNameImpl();
validateNewName.setSessionId(refactoring.getSessionId());
validateNewName.setNewName("MyClass");
manager.renameValidateNewName(validateNewName);
RenameSettings settings = new DtoServerImpls.RenameSettingsImpl();
settings.setSessionId(refactoring.getSessionId());
settings.setDeprecateDelegates(true);
settings.setUpdateReferences(true);
manager.setRenameSettings(settings);
ChangeCreationResult change = manager.createChange(refactoring.getSessionId());
assertThat(change).isNotNull();
RefactoringStatus applyRefactoring = manager.applyRefactoring(refactoring.getSessionId());
assertThat(applyRefactoring).isNotNull();
assertThat(applyRefactoring.getSeverity()).isEqualTo(RefactoringStatus.OK);
assertThat(unit.exists()).isFalse();
ICompilationUnit newUnit = getPackageP().getCompilationUnit("MyClass.java");
assertThat(newUnit.exists()).isTrue();
}
Aggregations