Search in sources :

Example 1 with TextEditBasedChangeGroup

use of org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup in project che by eclipse.

the class TextEditChangePreviewViewer method setInput.

//	public void createControl(Composite parent) {
//		fViewer = new ComparePreviewer(parent);
//	}
//
//	public Control getControl() {
//		return fViewer;
//	}
public ChangePreview setInput(ChangePreviewViewerInput input) {
    try {
        Change change = input.getChange();
        if (input instanceof TextEditBasedChangeInput) {
            TextEditBasedChangeInput extended = (TextEditBasedChangeInput) input;
            if (extended.group != null && extended.surroundingLines >= 0) {
                TextEditBasedChangeGroup group = extended.group;
                TextEditBasedChange editChange = group.getTextEditChange();
                //					setInput(editChange, editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(new TextEditBasedChangeGroup[]{group}, group.getRegion(), true, 2,
                //														  new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(new TextEditBasedChangeGroup[] { group }, group.getRegion(), true, 2, new NullProgressMonitor()));
                return preview;
            } else if (extended.groups != null && extended.groups.length > 0 && extended.range != null) {
                TextEditBasedChange editChange = extended.groups[0].getTextEditChange();
                TextEditBasedChangeGroup[] groups = extended.groups;
                //					if (extended.groupCategory != null) {
                //
                //					}
                //					setInput(editChange, editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()));
                return preview;
            }
        } else if (change instanceof TextEditBasedChange) {
            TextEditBasedChange editChange = (TextEditBasedChange) change;
            //				setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()),
            //						 editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
            ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
            preview.setFileName(getFileName(editChange));
            preview.setOldContent(editChange.getCurrentContent(new NullProgressMonitor()));
            preview.setNewContent(editChange.getPreviewContent(new NullProgressMonitor()));
            return preview;
        } else {
            //				fViewer.setInput(null);
            return null;
        }
    } catch (CoreException | AssertionFailedException e) {
        JavaPlugin.log(e);
        //			fViewer.setInput(null);
        return null;
    }
    //		}
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Example 2 with TextEditBasedChangeGroup

use of org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup in project che by eclipse.

the class TextEditGroupNode method feedInput.

public ChangePreview feedInput(IChangePreviewViewer viewer, List categories) throws CoreException {
    InternalTextEditChangeNode element = getTextEditChangeNode();
    if (element != null) {
        Change change = element.getChange();
        if (change instanceof TextEditBasedChange) {
            IRegion range = getTextRange(this);
            ChangePreviewViewerInput input = null;
            if (range != null) {
                input = TextEditChangePreviewViewer.createInput(change, new TextEditBasedChangeGroup[] { fChangeGroup }, range);
            } else {
                input = TextEditChangePreviewViewer.createInput(change, fChangeGroup, 2);
            }
            return viewer.setInput(input);
        }
    } else {
        return viewer.setInput(null);
    }
    return null;
}
Also used : TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) ChangePreviewViewerInput(org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) IRegion(org.eclipse.jface.text.IRegion) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Example 3 with TextEditBasedChangeGroup

use of org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup in project che by eclipse.

the class CompilationUnitChangeNode method createChildNodes.

@Override
protected ChildNode[] createChildNodes() {
    TextEditBasedChange change = getTextEditBasedChange();
    if (change instanceof MultiStateTextFileChange) {
        // no edit preview & edit disabling possible in the MultiStateTextFileChange (edits must be applied
        return new ChildNode[0];
    // in sequence)
    }
    ICompilationUnit cunit = (ICompilationUnit) change.getAdapter(ICompilationUnit.class);
    if (cunit != null) {
        List<ChildNode> children = new ArrayList<ChildNode>(5);
        Map<IJavaElement, JavaLanguageNode> map = new HashMap<IJavaElement, JavaLanguageNode>(20);
        TextEditBasedChangeGroup[] changes = getSortedChangeGroups(change);
        for (int i = 0; i < changes.length; i++) {
            TextEditBasedChangeGroup tec = changes[i];
            try {
                IJavaElement element = getModifiedJavaElement(tec, cunit);
                if (element.equals(cunit)) {
                    children.add(createTextEditGroupNode(this, tec));
                } else {
                    JavaLanguageNode pjce = getChangeElement(map, element, children, this);
                    pjce.addChild(createTextEditGroupNode(pjce, tec));
                }
            } catch (JavaModelException e) {
                children.add(createTextEditGroupNode(this, tec));
            }
        }
        return children.toArray(new ChildNode[children.size()]);
    } else {
        return EMPTY_CHILDREN;
    }
}
Also used : MultiStateTextFileChange(org.eclipse.ltk.core.refactoring.MultiStateTextFileChange) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange)

Example 4 with TextEditBasedChangeGroup

use of org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup in project che by eclipse.

the class InternalLanguageElementNode method collectTextEditBasedChangeGroups.

private List collectTextEditBasedChangeGroups(List categories) {
    List result = new ArrayList(10);
    PreviewNode[] children = getChildren();
    for (int i = 0; i < children.length; i++) {
        PreviewNode child = children[i];
        if (child instanceof TextEditGroupNode) {
            TextEditBasedChangeGroup changeGroup = ((TextEditGroupNode) child).getChangeGroup();
            if (categories == null || changeGroup.getGroupCategorySet().containsOneCategory(categories))
                result.add(changeGroup);
        } else if (child instanceof InternalLanguageElementNode) {
            result.addAll(((InternalLanguageElementNode) child).collectTextEditBasedChangeGroups(categories));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Example 5 with TextEditBasedChangeGroup

use of org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup in project che by eclipse.

the class TextEditChangeNode method getSortedChangeGroups.

private TextEditBasedChangeGroup[] getSortedChangeGroups(TextEditBasedChange change) {
    TextEditBasedChangeGroup[] groups = change.getChangeGroups();
    List result = new ArrayList(groups.length);
    for (int i = 0; i < groups.length; i++) {
        if (!groups[i].getTextEditGroup().isEmpty())
            result.add(groups[i]);
    }
    Comparator comparator = new OffsetComparator();
    Collections.sort(result, comparator);
    return (TextEditBasedChangeGroup[]) result.toArray(new TextEditBasedChangeGroup[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup) Comparator(java.util.Comparator)

Aggregations

TextEditBasedChangeGroup (org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)6 TextEditBasedChange (org.eclipse.ltk.core.refactoring.TextEditBasedChange)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Change (org.eclipse.ltk.core.refactoring.Change)2 MultiStateTextFileChange (org.eclipse.ltk.core.refactoring.MultiStateTextFileChange)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)1 AssertionFailedException (org.eclipse.core.runtime.AssertionFailedException)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IRegion (org.eclipse.jface.text.IRegion)1 TextEditGroupNode (org.eclipse.ltk.internal.ui.refactoring.TextEditGroupNode)1 ChangePreviewViewerInput (org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput)1