use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview in project che by eclipse.
the class PreviewViewImpl method setTreeOfChanges.
/** {@inheritDoc} */
@Override
public void setTreeOfChanges(final RefactoringPreview changes) {
showDiffPanel(false);
final SelectionModel<RefactoringPreview> selectionModel = new SingleSelectionModel<>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
RefactoringPreview selectedNode = (RefactoringPreview) ((SingleSelectionModel) selectionModel).getSelectedObject();
delegate.onSelectionChanged(selectedNode);
}
});
Tree tree = new Tree();
tree.getElement().setId("tree-of-changes");
for (RefactoringPreview parentChange : changes.getChildrens()) {
TreeItem treeItem = new TreeItem();
containerChanges.put(treeItem, parentChange);
createTreeElement(treeItem, parentChange.getText(), parentChange.getChildrens());
tree.addItem(treeItem);
}
tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
@Override
public void onSelection(SelectionEvent<TreeItem> event) {
if (selectedElement != null) {
selectedElement.getStyle().setProperty("background", "transparent");
}
selectedElement = event.getSelectedItem().getWidget().getElement();
selectedElement.getStyle().setProperty("background", getEditorSelectionColor());
}
});
treePanel.add(tree);
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview in project che by eclipse.
the class DtoConverter method toRefactoringPreview.
/**
* Converts {@link PreviewNode} to {@link RefactoringPreview}.
*/
public static RefactoringPreview toRefactoringPreview(PreviewNode node) {
RefactoringPreview dto = DtoFactory.newDto(RefactoringPreview.class);
dto.setId(node.getId());
dto.setText(node.getText());
dto.setImage(node.getImageDescriptor().getImage());
dto.setEnabled(true);
PreviewNode[] children = node.getChildren();
if (children != null && children.length > 0) {
List<RefactoringPreview> list = new ArrayList<>(children.length);
for (PreviewNode child : children) {
list.add(toRefactoringPreview(child));
}
dto.setChildrens(list);
}
return dto;
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview in project che by eclipse.
the class MoveRefactoringSessionTest method testPreviewChanges.
@Test
public void testPreviewChanges() 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);
manager.createChange(sessionId);
RefactoringPreview change = manager.getRefactoringPreview(sessionId);
RefactoringChange change1 = new DtoServerImpls.ChangeEnabledStateImpl();
change1.setSessionId(sessionId);
change1.setChangeId(change.getChildrens().get(0).getId());
ChangePreview preview = manager.getChangePreview(change1);
assertThat(preview).isNotNull();
assertThat(preview.getFileName()).isNotNull().isNotEmpty();
assertThat(preview.getOldContent()).isNotNull().isNotEmpty();
assertThat(preview.getNewContent()).isNotNull().isNotEmpty();
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview in project che by eclipse.
the class RenameRefactoringTest method testRenamePreviewChanges.
@Test
public void testRenamePreviewChanges() throws Exception {
StringBuilder b = new StringBuilder();
b.append("package p;\n");
b.append("public class A{\n private A a; \n}\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");
RefactoringStatus status = manager.renameValidateNewName(validateNewName);
manager.createChange(refactoring.getSessionId());
RefactoringPreview preview = manager.getRefactoringPreview(refactoring.getSessionId());
RefactoringChange change1 = new DtoServerImpls.ChangeEnabledStateImpl();
change1.setSessionId(refactoring.getSessionId());
change1.setChangeId(preview.getChildrens().get(0).getId());
ChangePreview changePreview = manager.getChangePreview(change1);
assertThat(changePreview).isNotNull();
assertThat(changePreview.getFileName()).isNotNull().isNotEmpty();
assertThat(changePreview.getOldContent()).isNotNull().isNotEmpty();
assertThat(changePreview.getNewContent()).isNotNull().isNotEmpty();
assertThat(changePreview.getNewContent()).isNotEqualTo(changePreview.getOldContent());
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview in project che by eclipse.
the class MoveRefactoringSessionTest method testGetMoveChanges.
@Test
public void testGetMoveChanges() 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);
manager.createChange(sessionId);
RefactoringPreview change = manager.getRefactoringPreview(sessionId);
assertThat(change).isNotNull();
assertThat(change.getText()).isEqualTo("Move");
assertThat(change.getChildrens()).isNotNull().hasSize(2);
}
Aggregations