Search in sources :

Example 1 with RefactoringPreview

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);
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) TreeItem(com.google.gwt.user.client.ui.TreeItem) Tree(com.google.gwt.user.client.ui.Tree) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 2 with RefactoringPreview

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;
}
Also used : ArrayList(java.util.ArrayList) PreviewNode(org.eclipse.ltk.internal.ui.refactoring.PreviewNode) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)

Example 3 with RefactoringPreview

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();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringChange(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) ReorgDestination(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination) MoveSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 4 with RefactoringPreview

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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringChange(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 5 with RefactoringPreview

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);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ReorgDestination(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination) MoveSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Aggregations

RefactoringPreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 IType (org.eclipse.jdt.core.IType)3 Test (org.junit.Test)3 TreeItem (com.google.gwt.user.client.ui.TreeItem)2 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)2 MoveSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)2 RefactoringChange (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange)2 ReorgDestination (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Label (com.google.gwt.user.client.ui.Label)1 Tree (com.google.gwt.user.client.ui.Tree)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 SingleSelectionModel (com.google.gwt.view.client.SingleSelectionModel)1 ArrayList (java.util.ArrayList)1 RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)1 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)1